|
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()
|