Skip to content

Commit f3457fb

Browse files
fix: User edit pwd validate
1 parent a37fc35 commit f3457fb

File tree

2 files changed

+28
-23
lines changed

2 files changed

+28
-23
lines changed

frontend/src/components/layout/PwdForm.vue

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,30 @@ const pwdForm = reactive({
1010
confirm_pwd: '',
1111
})
1212
13+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
14+
// @ts-ignore
15+
const validatePass = (rule: any, value: any, callback: any) => {
16+
if (value === '') {
17+
callback(new Error(t('common.please_input', { msg: t('user.upgrade_pwd.new_pwd') })))
18+
} else {
19+
if (pwdForm.confirm_pwd !== '') {
20+
if (!pwdRef.value) return
21+
pwdRef.value.validateField('confirm_pwd')
22+
}
23+
callback()
24+
}
25+
}
26+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
27+
// @ts-ignore
28+
const validatePass2 = (rule: any, value: any, callback: any) => {
29+
if (value === '') {
30+
callback(new Error(t('common.please_input', { msg: t('user.upgrade_pwd.confirm_pwd') })))
31+
} else if (value !== pwdForm.new_pwd) {
32+
callback(new Error(t('user.upgrade_pwd.two_pwd_not_match')))
33+
} else {
34+
callback()
35+
}
36+
}
1337
const rules = {
1438
pwd: [
1539
{
@@ -18,27 +42,8 @@ const rules = {
1842
trigger: 'blur',
1943
},
2044
],
21-
new_pwd: [
22-
{
23-
required: true,
24-
message: t('common.please_input', { msg: t('user.upgrade_pwd.new_pwd') }),
25-
trigger: 'blur',
26-
},
27-
],
28-
confirm_pwd: [
29-
{
30-
required: true,
31-
message: t('common.please_input', { msg: t('user.upgrade_pwd.confirm_pwd') }),
32-
trigger: 'blur',
33-
},
34-
],
35-
}
36-
37-
const initForm = (item: any) => {
38-
if (item) {
39-
Object.assign(pwdForm, { ...item })
40-
}
41-
pwdRef.value.clearValidate()
45+
new_pwd: [{ validator: validatePass, trigger: 'blur' }],
46+
confirm_pwd: [{ validator: validatePass2, trigger: 'blur' }],
4247
}
4348
4449
const emits = defineEmits(['pwdSaved'])
@@ -61,7 +66,6 @@ const submit = () => {
6166
})
6267
}
6368
defineExpose({
64-
initForm,
6569
submit,
6670
})
6771
</script>

frontend/src/i18n/zh-CN.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,8 @@
336336
"title": "修改密码",
337337
"old_pwd": "旧密码",
338338
"new_pwd": "新密码",
339-
"confirm_pwd": "确认密码"
339+
"confirm_pwd": "确认密码",
340+
"two_pwd_not_match": "两次输入的密码不一致"
340341
}
341342
},
342343
"workspace": {

0 commit comments

Comments
 (0)