From 0cefa99d2ae9ba43e60fe3e1beceb000dd186931 Mon Sep 17 00:00:00 2001 From: fuliqi <fuliqi@qq.com> Date: 星期四, 17 十月 2024 18:31:03 +0800 Subject: [PATCH] 密码失效修改密码,格式校验 --- src/views/login/index.vue | 51 +++++++++++++++++++++++++++++++-------------------- 1 files changed, 31 insertions(+), 20 deletions(-) diff --git a/src/views/login/index.vue b/src/views/login/index.vue index 888e086..d1b9a0e 100644 --- a/src/views/login/index.vue +++ b/src/views/login/index.vue @@ -63,8 +63,8 @@ :show-close="false" > <div style="margin-bottom: 10px; color: #aa1111">鎮ㄧ殑瀵嗙爜宸茬粡杩囨湡锛岃閲嶆柊璁剧疆~</div> - <el-form :model="updatePasswordForm"> - <el-form-item label="鏂板瘑鐮�"> + <el-form ref="updatePasswordForm" :model="updatePasswordForm" :rules="updatePasswordRules"> + <el-form-item label="鏂板瘑鐮�" prop="newPassword"> <el-input v-model="updatePasswordForm.newPassword" placeholder="搴斿寘鍚ぇ灏忓啓銆佹暟瀛�" show-password></el-input> </el-form-item> <el-form-item label="纭瀵嗙爜"> @@ -88,16 +88,15 @@ export default { name: 'Login', data () { - const validateUsername = (rule, value, callback) => { - if (value.length < 5) { - callback(new Error('鐢ㄦ埛鍚嶄笉鑳藉皯浜�5涓瓧绗�')) - } else { - callback() - } - } const validatePassword = (rule, value, callback) => { - if (value.length < 5) { - callback(new Error('瀵嗙爜涓嶈兘灏戜簬5涓瓧绗�')) + if (value === '') { + callback(new Error('璇疯緭鍏ュ瘑鐮�')) + } else if (!/[A-Z]/.test(value)) { + callback(new Error('瀵嗙爜蹇呴』鍖呭惈鑷冲皯涓�涓ぇ鍐欏瓧姣�')) + } else if (!/[a-z]/.test(value)) { + callback(new Error('瀵嗙爜蹇呴』鍖呭惈鑷冲皯涓�涓皬鍐欏瓧姣�')) + } else if (!/[0-9]/.test(value)) { + callback(new Error('瀵嗙爜蹇呴』鍖呭惈鑷冲皯涓�涓暟瀛�')) } else { callback() } @@ -108,6 +107,11 @@ userId: null, newPassword: '', confirmPassword: '' + }, + updatePasswordRules: { + newPassword: [ + { validator: validatePassword, trigger: 'blur' } + ] }, loginForm: { userName: '', @@ -139,15 +143,22 @@ }, methods: { updatePassword () { - if (this.updatePasswordForm.newPassword !== this.updatePasswordForm.confirmPassword) { - this.$message.error('涓ゆ杈撳叆鐨勫瘑鐮佷笉涓�鑷�') - return - } - UserApi.updatePassword(this.updatePasswordForm).then(res => { - if (res.code === 1) { - this.$message.success('瀵嗙爜淇敼鎴愬姛銆傝閲嶆柊鐧诲綍') - this.loginForm.password = '' - this.forceUpdateShow = false + let _this = this + _this.$refs.updatePasswordForm.validate(valid => { + if (valid) { + if (this.updatePasswordForm.newPassword !== this.updatePasswordForm.confirmPassword) { + _this.$message.error('涓ゆ杈撳叆鐨勫瘑鐮佷笉涓�鑷�') + return + } + UserApi.updatePassword(this.updatePasswordForm).then(res => { + if (res.code === 1) { + _this.$message.success('瀵嗙爜淇敼鎴愬姛銆傝閲嶆柊鐧诲綍') + _this.loginForm.password = '' + _this.forceUpdateShow = false + } + }) + } else { + return false } }) }, -- Gitblit v1.8.0