From 2bbb2e19cdbf4100065110523c335b07280f565e Mon Sep 17 00:00:00 2001 From: "851673013@qq.com" <851673013@qq.com> Date: Tue, 2 Aug 2022 17:39:06 +0800 Subject: [PATCH] bug729 --- .../views/modules/sys/user-add-or-update.vue | 316 ++++++++++++------ 1 file changed, 216 insertions(+), 100 deletions(-) diff --git a/back/src/views/modules/sys/user-add-or-update.vue b/back/src/views/modules/sys/user-add-or-update.vue index c366c760..30a03606 100644 --- a/back/src/views/modules/sys/user-add-or-update.vue +++ b/back/src/views/modules/sys/user-add-or-update.vue @@ -1,40 +1,110 @@ @@ -93,8 +165,22 @@ export default { const low = /^.*[a-z]+.*/ const up = /^.*[A-Z]+.*/ const spe = /^.*[^a-zA-Z0-9]+.*/ - console.log('包含数字', num.test(value), '包含字母', low.test(value), up.test(value), '包含特殊符号', spe.test(value)) - if (!(num.test(value) && (low.test(value) || up.test(value)) && spe.test(value))) { + console.log( + '包含数字', + num.test(value), + '包含字母', + low.test(value), + up.test(value), + '包含特殊符号', + spe.test(value) + ) + if ( + !( + num.test(value) && + (low.test(value) || up.test(value)) && + spe.test(value) + ) + ) { return callback(new Error(this.$t('validate.pwdStrength'))) } // if (!this.dataForm.id && !/\S/.test(value)) { @@ -113,38 +199,52 @@ export default { } var validateEmail = (rule, value, callback) => { if (value && !isEmail(value)) { - return callback(new Error(this.$t('validate.format', { attr: this.$t('user.email') }))) + return callback( + new Error( + this.$t('validate.format', { attr: this.$t('user.email') }) + ) + ) } callback() } var validateMobile = (rule, value, callback) => { if (value && !isMobile(value)) { - return callback(new Error(this.$t('validate.format', { attr: this.$t('user.mobile') }))) + return callback( + new Error( + this.$t('validate.format', { attr: this.$t('user.mobile') }) + ) + ) } callback() } return { username: [ - { required: true, message: this.$t('validate.required'), trigger: 'blur' } + { + required: true, + message: this.$t('validate.required'), + trigger: 'blur' + } ], deptName: [ - { required: true, message: this.$t('validate.required'), trigger: 'change' } - ], - password: [ - { validator: validatePassword, trigger: 'blur' } + { + required: true, + message: this.$t('validate.required'), + trigger: 'change' + } ], + password: [{ validator: validatePassword, trigger: 'blur' }], confirmPassword: [ { validator: validateConfirmPassword, trigger: 'blur' } ], realName: [ - { required: true, message: this.$t('validate.required'), trigger: 'blur' } + { + required: true, + message: this.$t('validate.required'), + trigger: 'blur' + } ], - email: [ - { validator: validateEmail, trigger: 'blur' } - ], - mobile: [ - { validator: validateMobile, trigger: 'blur' } - ] + email: [{ validator: validateEmail, trigger: 'blur' }], + mobile: [{ validator: validateMobile, trigger: 'blur' }] } } }, @@ -165,10 +265,7 @@ export default { this.$nextTick(() => { this.$refs.dataForm.resetFields() this.roleIdListDefault = [] - Promise.all([ - this.getRoleList(), - this.getPostList() - ]).then(() => { + Promise.all([this.getRoleList(), this.getPostList()]).then(() => { if (this.dataForm.id) { this.getInfo() } else { @@ -193,79 +290,98 @@ export default { }, // 获取角色列表 getRoleList () { - return this.$http.get('/sys/role/list').then(({ data: res }) => { - if (res.code !== 0) { - return this.$message.error(res.msg) - } - this.roleList = res.data - }).catch(() => {}) + return this.$http + .get('/sys/role/list') + .then(({ data: res }) => { + if (res.code !== 0) { + return this.$message.error(res.msg) + } + this.roleList = res.data + }) + .catch(() => {}) }, // 获取岗位列表 getPostList () { - return this.$http.get('/sys/post/list').then(({ data: res }) => { - if (res.code !== 0) { - return this.$message.error(res.msg) - } - this.postList = res.data - }).catch(() => {}) + return this.$http + .get('/sys/post/list') + .then(({ data: res }) => { + if (res.code !== 0) { + return this.$message.error(res.msg) + } + this.postList = res.data + }) + .catch(() => {}) }, // 获取信息 getInfo () { - this.$http.get(`/sys/user/${this.dataForm.id}`).then(({ data: res }) => { - if (res.code !== 0) { - return this.$message.error(res.msg) - } - this.dataForm = { - ...this.dataForm, - ...res.data, - roleIdList: [] - } - // 角色配置, 区分是否为默认角色 - for (var i = 0; i < res.data.roleIdList.length; i++) { - if (this.roleList.filter(item => item.id === res.data.roleIdList[i])[0]) { - this.dataForm.roleIdList.push(res.data.roleIdList[i]) - continue + this.$http + .get(`/sys/user/${this.dataForm.id}`) + .then(({ data: res }) => { + if (res.code !== 0) { + return this.$message.error(res.msg) } - this.roleIdListDefault.push(res.data.roleIdList[i]) - } - }).catch(() => {}) + this.dataForm = { + ...this.dataForm, + ...res.data, + roleIdList: [] + } + // 角色配置, 区分是否为默认角色 + for (var i = 0; i < res.data.roleIdList.length; i++) { + if ( + this.roleList.filter( + (item) => item.id === res.data.roleIdList[i] + )[0] + ) { + this.dataForm.roleIdList.push(res.data.roleIdList[i]) + continue + } + this.roleIdListDefault.push(res.data.roleIdList[i]) + } + }) + .catch(() => {}) }, // 表单提交 - dataFormSubmitHandle: debounce(function () { - this.$refs.dataForm.validate((valid) => { - if (!valid) { - return false - } - if (this.submitFlag) { - this.submitFlag = false - this.dataForm.password = Encrypt(this.dataForm.password) - if (this.dataForm.id) { - delete this.dataForm.password + dataFormSubmitHandle: debounce( + function () { + this.$refs.dataForm.validate((valid) => { + if (!valid) { + return false } - this.$http[!this.dataForm.id ? 'post' : 'put']('/sys/user', { - ...this.dataForm, - roleIdList: [ - ...this.dataForm.roleIdList, - ...this.roleIdListDefault - ] - }).then(({ data: res }) => { - if (res.code !== 0) { - return this.$message.error(res.msg) + if (this.submitFlag) { + this.submitFlag = false + this.dataForm.password = Encrypt(this.dataForm.password) + if (this.dataForm.id) { + delete this.dataForm.password } - this.$message({ - message: this.$t('prompt.success'), - type: 'success', - duration: 500, - onClose: () => { - this.visible = false - this.$emit('refreshDataList') - } + this.$http[!this.dataForm.id ? 'post' : 'put']('/sys/user', { + ...this.dataForm, + roleIdList: [ + ...this.dataForm.roleIdList, + ...this.roleIdListDefault + ] }) - this.submitFlag = true - }).catch(() => {}) - } - }) - }, 1000, { leading: true, trailing: false }) + .then(({ data: res }) => { + if (res.code !== 0) { + return this.$message.error(res.msg) + } + this.$message({ + message: this.$t('prompt.success'), + type: 'success', + duration: 500, + onClose: () => { + this.visible = false + this.$emit('refreshDataList') + } + }) + this.submitFlag = true + }) + .catch(() => {}) + } + }) + }, + 1000, + { leading: true, trailing: false } + ) } }