From f3457fbe8f79bd85870b13b5ca8164acd1bdbc48 Mon Sep 17 00:00:00 2001 From: fit2cloud-chenyw Date: Fri, 25 Jul 2025 22:09:58 +0800 Subject: [PATCH] fix: User edit pwd validate --- frontend/src/components/layout/PwdForm.vue | 48 ++++++++++++---------- frontend/src/i18n/zh-CN.json | 3 +- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/frontend/src/components/layout/PwdForm.vue b/frontend/src/components/layout/PwdForm.vue index abe92bfc..4d46f7b8 100644 --- a/frontend/src/components/layout/PwdForm.vue +++ b/frontend/src/components/layout/PwdForm.vue @@ -10,6 +10,30 @@ const pwdForm = reactive({ confirm_pwd: '', }) +// eslint-disable-next-line @typescript-eslint/ban-ts-comment +// @ts-ignore +const validatePass = (rule: any, value: any, callback: any) => { + if (value === '') { + callback(new Error(t('common.please_input', { msg: t('user.upgrade_pwd.new_pwd') }))) + } else { + if (pwdForm.confirm_pwd !== '') { + if (!pwdRef.value) return + pwdRef.value.validateField('confirm_pwd') + } + callback() + } +} +// eslint-disable-next-line @typescript-eslint/ban-ts-comment +// @ts-ignore +const validatePass2 = (rule: any, value: any, callback: any) => { + if (value === '') { + callback(new Error(t('common.please_input', { msg: t('user.upgrade_pwd.confirm_pwd') }))) + } else if (value !== pwdForm.new_pwd) { + callback(new Error(t('user.upgrade_pwd.two_pwd_not_match'))) + } else { + callback() + } +} const rules = { pwd: [ { @@ -18,27 +42,8 @@ const rules = { trigger: 'blur', }, ], - new_pwd: [ - { - required: true, - message: t('common.please_input', { msg: t('user.upgrade_pwd.new_pwd') }), - trigger: 'blur', - }, - ], - confirm_pwd: [ - { - required: true, - message: t('common.please_input', { msg: t('user.upgrade_pwd.confirm_pwd') }), - trigger: 'blur', - }, - ], -} - -const initForm = (item: any) => { - if (item) { - Object.assign(pwdForm, { ...item }) - } - pwdRef.value.clearValidate() + new_pwd: [{ validator: validatePass, trigger: 'blur' }], + confirm_pwd: [{ validator: validatePass2, trigger: 'blur' }], } const emits = defineEmits(['pwdSaved']) @@ -61,7 +66,6 @@ const submit = () => { }) } defineExpose({ - initForm, submit, }) diff --git a/frontend/src/i18n/zh-CN.json b/frontend/src/i18n/zh-CN.json index 4234340a..e42b6bf6 100644 --- a/frontend/src/i18n/zh-CN.json +++ b/frontend/src/i18n/zh-CN.json @@ -336,7 +336,8 @@ "title": "修改密码", "old_pwd": "旧密码", "new_pwd": "新密码", - "confirm_pwd": "确认密码" + "confirm_pwd": "确认密码", + "two_pwd_not_match": "两次输入的密码不一致" } }, "workspace": {