diff --git a/src/views/modules/book/book-add-or-update.vue b/src/views/modules/book/book-add-or-update.vue index 56b288c..01a340c 100644 --- a/src/views/modules/book/book-add-or-update.vue +++ b/src/views/modules/book/book-add-or-update.vue @@ -77,7 +77,7 @@ 国学经典 - + diff --git a/src/views/modules/user/user-add-or-update.vue b/src/views/modules/user/user-add-or-update.vue index 04b5b62..2378df5 100644 --- a/src/views/modules/user/user-add-or-update.vue +++ b/src/views/modules/user/user-add-or-update.vue @@ -3,12 +3,15 @@ @close="handlereset"> - - - + + + + + + @@ -134,6 +137,7 @@ id: 0, name: '', age: '', + email: '', sex: 2, avatar: '', nickname: '', @@ -154,71 +158,31 @@ prescriptBPower: 0, }, dataRule: { - name: [{ - required: true, - message: '姓名不能为空', - trigger: 'blur' - }], password: [{ required: true, message: '密码不能为空', trigger: 'blur' }], - // age: [ - // { required: true, message: '年龄不能为空', trigger: 'blur' } - // ], - // sex: [ - // { required: true, message: '性别不能为空', trigger: 'blur' } - // ], - // avatar: [ - // { required: true, message: '头像不能为空', trigger: 'blur' } - // ], - // nickname: [ - // { required: true, message: '昵称不能为空', trigger: 'blur' } - // ], - tel: [{ - required: true, - message: '电话不能为空', - trigger: 'blur' - }, - { - validator: function(rule, value, callback) { - if (/^1[34578]\d{9}$/.test(value) == false) { - callback(new Error("手机号格式错误")); - } else { - callback(); - } - }, - trigger: "blur" - } - ], - // password: [ - // { required: true, message: '密码不能为空', trigger: 'blur' } - // ], - // vip: [ - // { required: true, message: '0-普通 1-vip不能为空', trigger: 'blur' } - // ], - // vipValidtime: [ - // { required: true, message: 'vip 有效期不能为空', trigger: 'blur' } - // ], - // peanutCoin: [ - // { required: true, message: '花生币不能为空', trigger: 'blur' } - // ], - // readTime: [ - // { required: true, message: '阅读时间不能为空', trigger: 'blur' } - // ], - // lastLoginTime: [ - // { required: true, message: '最后登录时间不能为空', trigger: 'blur' } - // ], - // createTime: [ - // { required: true, message: '创建时间不能为空', trigger: 'blur' } - // ], - // updateTime: [ - // { required: true, message: '更新时间不能为空', trigger: 'blur' } - // ], - // delFlag: [ - // { required: true, message: '删除标记不能为空', trigger: 'blur' } - // ] + // tel: [{ + // validator: function(rule, value, callback) { + // if (/^1[34578]\d{9}$/.test(value) == false) { + // callback(new Error("手机号格式错误")); + // } else { + // callback(); + // } + // }, + // trigger: "blur" + // }], + // email: [{ + // validator: function(rule, value, callback) { + // if (/^\w+@\w+(\.[a-zA-Z]{2,3}){1,2}$/.test(value) == false) { + // callback(new Error("邮箱格式错误")); + // } else { + // callback(); + // } + // }, + // trigger: "blur" + // }], } } }, @@ -238,6 +202,7 @@ }) => { if (data && data.code === 0) { this.dataForm.name = data.user.name + this.dataForm.email = data.user.email this.dataForm.age = data.user.age this.dataForm.sex = data.user.sex this.dataForm.avatar = data.user.avatar @@ -273,63 +238,83 @@ }, // 表单提交 dataFormSubmit() { - this.$refs['dataForm'].validate((valid) => { - let myData = {} - if (!this.dataForm.id) { - myData = { - 'name': this.dataForm.name, - 'tel': this.dataForm.tel, - } - } else { - myData = { - 'id': this.dataForm.id, - 'name': this.dataForm.name, - 'age': this.dataForm.age, - 'sex': this.dataForm.sex, - 'avatar': this.dataForm.avatar, - 'nickname': this.dataForm.nickname, - 'tel': this.dataForm.tel, - 'pointPower': this.dataForm.pointPower, - 'tgdzPower': this.dataForm.tgdzPower, - 'wylqPower': this.dataForm.wylqPower, - 'prescriptAPower': this.dataForm.prescriptAPower, - 'prescriptBPower': this.dataForm.prescriptBPower, - // 'password': this.dataForm.password, - // 'vip': this.dataForm.vip, - // 'vipValidtime': this.dataForm.vipValidtime, - // 'peanutCoin': this.dataForm.peanutCoin, - // 'readTime': this.dataForm.readTime, - // 'lastLoginTime': this.dataForm.lastLoginTime, - // 'createTime': this.dataForm.createTime, - // 'updateTime': this.dataForm.updateTime, - // 'delFlag': this.dataForm.delFlag - } + if (!this.dataForm.email && !this.dataForm.tel) { + this.$message.error("手机号或邮箱不为空!") + return + } + + if (this.dataForm.email) { + if (/^\w+@\w+(\.[a-zA-Z]{2,3}){1,2}$/.test(this.dataForm.email) == false) { + this.$message.error("邮箱格式错误!") + return } - console.log('myData', myData) - if (valid) { - this.$http({ - url: this.$http.adornUrl(`/book/user/${!this.dataForm.id ? 'save' : 'update'}`), - method: 'post', - data: this.$http.adornData(myData) - }).then(({ - data - }) => { - if (data && data.code === 0) { - this.$message({ - message: '操作成功', - type: 'success', - duration: 1500, - onClose: () => { - this.visible = false - this.$emit('refreshDataList') - } - }) - } else { - this.$message.error(data.msg) + } + + if (this.dataForm.tel) { + if (/^1[34578]\d{9}$/.test(this.dataForm.tel) == false) { + this.$message.error("手机格式错误!") + return + } + } + + let myData = {} + if (!this.dataForm.id) { + myData = { + 'name': this.dataForm.name, + 'tel': this.dataForm.tel, + } + } else { + myData = { + 'id': this.dataForm.id, + 'name': this.dataForm.name, + 'email': this.dataForm.email, + 'age': this.dataForm.age, + 'sex': this.dataForm.sex, + 'avatar': this.dataForm.avatar, + 'nickname': this.dataForm.nickname, + 'tel': this.dataForm.tel, + 'pointPower': this.dataForm.pointPower, + 'tgdzPower': this.dataForm.tgdzPower, + 'wylqPower': this.dataForm.wylqPower, + 'prescriptAPower': this.dataForm.prescriptAPower, + 'prescriptBPower': this.dataForm.prescriptBPower, + // 'password': this.dataForm.password, + // 'vip': this.dataForm.vip, + // 'vipValidtime': this.dataForm.vipValidtime, + // 'peanutCoin': this.dataForm.peanutCoin, + // 'readTime': this.dataForm.readTime, + // 'lastLoginTime': this.dataForm.lastLoginTime, + // 'createTime': this.dataForm.createTime, + // 'updateTime': this.dataForm.updateTime, + // 'delFlag': this.dataForm.delFlag + } + } + + console.log('myData', myData) + + this.$http({ + url: this.$http.adornUrl(`/book/user/${!this.dataForm.id ? 'save' : 'update'}`), + method: 'post', + data: this.$http.adornData(myData) + }).then(({ + data + }) => { + if (data && data.code === 0) { + this.$message({ + message: '操作成功', + type: 'success', + duration: 1500, + onClose: () => { + this.visible = false + this.$emit('refreshDataList') } }) + } else { + this.$message.error(data.msg) } }) + + }, handlePictureCardPreview(file) { this.dataForm.avatar = file.url; @@ -355,4 +340,4 @@ }, } } - \ No newline at end of file + diff --git a/src/views/modules/user/user.vue b/src/views/modules/user/user.vue index 38ca952..6145425 100644 --- a/src/views/modules/user/user.vue +++ b/src/views/modules/user/user.vue @@ -47,6 +47,8 @@ + +