hejianhao
2025-04-16 dab2d210ca06c1faa514c6388fbd5de1ab355360
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
 
class validate {
  constructor() {
    this._ = {
      '100': '必须为',
      '300': '请输入',
      '301': '请选择',
      '302': '请上传',
      '400': '账号',
      '401': '密码',
      'name': '名称',
      'addr': '地址',
      'time': '时间',
      'act': '活动',
      'min': '最小',
      'max': '最大',
      'ren': '参与人数',
      'login': '2-20个字符',
      'pwd': '6-12个字符,且必须包含英文和数字'
    }
    this.e1 = /^[A-Za-z0-9]+$/
    this.e2 = /^(?![^a-zA-Z]+$)(?!\D+$)/
    this.pMax = 12
  }
  // 登录
  login(os) {
    if (!os.account) {
      return this.error(300, 400)
    }
    if (!os.password) {
      return this.error(300, 401)
    }
    let len = os.account.length
    let len2 = os.password.length
    if (len < 2 || len > 20) {
      return this.error(400, 100, 'login')
    }
    if (len2 < 6 || len2 > this.pMax) {
      return this.error(401, 100, 'pwd')
    }
    if (!this.e1.test(os.password)) {
      return this.error(401, 100, 'pwd')
    }
    if (!this.e2.test(os.password)) {
      return this.error(401, 100, 'pwd')
    }
    return this.success(os)
  }
  // 重置密码
  pwd(os) {
    if (!os.oldPassword) {
      return this.error(300, '原', 401)
    }
    if (!os.newPassword) {
      return this.error(300, '新', 401)
    }
    let len2 = os.newPassword.length
    if (len2 < 6 || len2 > this.pMax) {
      return this.error('新', 401, 100, 'pwd')
    }
    if (!this.e1.test(os.newPassword)) {
      return this.error('新', 401, 100, 'pwd')
    }
    if (!this.e2.test(os.newPassword)) {
      return this.error('新', 401, 100, 'pwd')
    }
    return this.success(os)
  }
  // 党员活动-添加
  activeAdd(os) {
    if (!os.name) {
      return this.error(300, 'act', 'name')
    }
    if (!os.address) {
      return this.error(300, 'act', 'addr')
    }
    if (!os.participationLowestNum && +os.participationLowestNum !== 0) {
      return this.error(300, 'min', 'ren')
    }
    // if (!os.participationNum) {
    //   return this.error(300, 'max', 'ren')
    // }
    if (!os.enrollTimeEnd) {
      return this.error(301, '截止报名', 'time')
    }
    if (!os.activityTimeBegin || !os.activityTimeEnd) {
      return this.error(301, 'act', 'time')
    }
    if (!os.cover) {
      return this.error(302, '封面')
    }
    if (!os.richText) {
      return this.error(300, '内容')
    }
    // if (os.participationLowestNum > os.participationNum) {
    //   return this.error('min', 'ren', '不能大于', 'max', 'ren')
    // }
    return this.success(os)
  }
  // 社区活动-添加
  activityAdd(os, flag) {
    if (!os.activityName) {
      return this.error(300, 'act', 'name')
    }
    let la = os.activityName.length
    if (la < 2 || la > 20) {
      return this.error(300, '2-20字符的活动名称')
    }
    // if (!os.sponsorName) {
    //   return this.error(301, 'act', '负责人')
    // }
    // if (!os.volunteerMin && +os.volunteerMin !== 0) {
    //   return this.error(300, '志愿者', 'min', 'ren')
    // }
    // if (!os.volunteerMax) {
    //   return this.error(300, '志愿者', 'max', 'ren')
    // }
    console.log(os)
    if (!os.signUpEnd) {
      return this.error(301, '报名截止', 'time')
    }
    if (!flag) {
      if (!os.participantMin && +os.participantMin !== 0) {
        return this.error(300, 'min', 'ren')
      }
      if (!os.participantMax) {
        return this.error(300, 'max', 'ren')
      }
    }
    if (!os.activityAddr) {
      return this.error(300, 'act', 'addr')
    }
    // if (!os.signUpBegin || !os.signUpEnd) {
    //   return this.error(301, '报名', 'time')
    // }
 
    if (!os.beginAt || !os.endAt) {
      return this.error(301, 'act', 'time')
    }
    // if (new Date(os.beginAt).getTime() <= new Date(os.signUpEnd).getTime()) {
    //   return this.error('活动时间不能早于报名时间')
    // }
    let timeout = Date.now()
    // if (new Date(os.beginAt).getTime() < timeout || new Date(os.signUpBegin).getTime() < timeout) {
    //   return this.error('活动时间、报名时间都不能小于当前时间')
    // }
    timeout = null
    if (!os.cover) {
      return this.error(302, '封面')
    }
    if (os.hasPrize) {
      if (!os.comActActPrizeVOList || !os.comActActPrizeVOList.length) {
        return this.error('请添加至少一项活动奖品')
      }
      if (!os.rewardDesc) {
        return this.error(300, '奖励说明')
      }
    }
    if (!os.content) {
      return this.error(300, '内容')
    }
    // if (os.volunteerMin > os.volunteerMax) {
    //   return this.error('志愿者', 'min', 'ren', '不能大于', '志愿者', 'max', 'ren')
    // }
    // if (os.participantMin > os.participantMax) {
    //   return this.error('min', 'ren', '不能大于', 'max', 'ren')
    // }
    return this.success(os)
  }
  // 新增用户
  sysUser(os, flag) {
    let val = false
    // if (flag) {
    //   if (os.password === '') {
    //     os.password = 'a123456'
    //     val = true
    //   }
    // }
    if (!os.account) {
      return this.error(300, 400)
    }
    // if (!os.password) {
    //   return this.error(300, 401)
    // }
    if (!os.name) {
      return this.error(300, '用户名')
    }
    if (!os.phone) {
      return this.error(300, '手机号')
    }
    if (!os.roleId) {
      return this.error(301, '角色名称')
    }
    let len = os.account.length
    // let len2 = os.password.length
    if (len < 2 || len > 20) {
      return this.error(400, 100, 'login')
    }
    // if (len2 < 6 || len2 > this.pMax) {
    //   return this.error(401, 100, 'pwd')
    // }
    // if (!this.e1.test(os.password)) {
    //   return this.error(401, 100, 'pwd')
    // }
    // if (!this.e2.test(os.password)) {
    //   return this.error(401, 100, 'pwd')
    // }
    if (!/^[1][3,4,5,7,8,9][0-9]{9}$/.test(os.phone)) {
      return this.error(301, '正确的手机号')
    }
    // if (flag && val) {
    //   os.password = ''
    // }
    return this.success(os)
  }
  // 批量建房
  door(os, type) {
    // console.log(type)
    let tp = ['all', 'building']
    if (tp.indexOf(type) >= 0) {
      if (os.buildingBegin === '' || os.buildingEnd === '') {
        return this.error(300, '楼栋区间')
      }
    }
    tp.push('unit')
    if (tp.indexOf(type) >= 0) {
      if (os.unitBegin === '' || os.unitEnd === '') {
        return this.error(300, '单元区间')
      }
    }
    tp.push('floor')
    if (tp.indexOf(type) >= 0) {
      if (os.floorBegin === '' || os.floorEnd === '') {
        return this.error(300, '楼层区间')
      }
    }
    if (os.doorBegin === '' || os.doorEnd === '') {
      return this.error(300, '门户区间')
    }
    if (type === 'all') {
      if (os.ruleFloor === '' || os.ruleDoor === '') {
        return this.error(300, '门牌号规则')
      }
    }
    return this.success(os)
  }
  addBuild(os) {
    if (os.name === '') {
      return this.error(300, '建筑名称')
    }
    if (os.typeId === '') {
      return this.error(301, '建筑类型')
    }
    if (os.square === '') {
      return this.error(300, '建筑面积')
    }
    if (isNaN(os.square)) {
      return this.error('请正确建筑面积')
    }
    if (os.address === '') {
      return this.error(300, '建筑地址')
    }
    if (os.state === '') {
      return this.error(301, '建筑状态')
    }
    if (os.layerType === '') {
      return this.error(301, '楼层类型')
    }
    return this.success(os)
  }
  success(o) {
    return { code: 1, err: '', data: JSON.parse(JSON.stringify(o)) }
  }
  error(...arg) {
    let t = this
    let v = []
    if (arg.length) {
      for (let i = 0; i < arg.length; i++) {
        v.push(t._[arg[i + '']] || (arg[i] || ''))
      }
    }
    return { code: 0, err: v.join('') }
  }
}
 
export default new validate()