提交 | 用户 | 时间
|
314507
|
1 |
<template> |
H |
2 |
<el-form ref="formRef" :model="password" :rules="rules" :label-width="200"> |
|
3 |
<el-form-item :label="t('profile.password.oldPassword')" prop="oldPassword"> |
|
4 |
<InputPassword v-model="password.oldPassword" /> |
|
5 |
</el-form-item> |
|
6 |
<el-form-item :label="t('profile.password.newPassword')" prop="newPassword"> |
|
7 |
<InputPassword v-model="password.newPassword" strength /> |
|
8 |
</el-form-item> |
|
9 |
<el-form-item :label="t('profile.password.confirmPassword')" prop="confirmPassword"> |
|
10 |
<InputPassword v-model="password.confirmPassword" strength /> |
|
11 |
</el-form-item> |
|
12 |
<el-form-item> |
|
13 |
<XButton :title="t('common.save')" type="primary" @click="submit(formRef)" /> |
|
14 |
<XButton :title="t('common.reset')" type="danger" @click="reset(formRef)" /> |
|
15 |
</el-form-item> |
|
16 |
</el-form> |
|
17 |
</template> |
|
18 |
<script lang="ts" setup> |
|
19 |
import type { FormInstance, FormRules } from 'element-plus' |
|
20 |
|
|
21 |
import { InputPassword } from '@/components/InputPassword' |
|
22 |
import { updateUserPassword } from '@/api/system/user/profile' |
|
23 |
|
|
24 |
defineOptions({ name: 'ResetPwd' }) |
|
25 |
|
|
26 |
const { t } = useI18n() |
|
27 |
const message = useMessage() |
|
28 |
const formRef = ref<FormInstance>() |
|
29 |
const password = reactive({ |
|
30 |
oldPassword: '', |
|
31 |
newPassword: '', |
|
32 |
confirmPassword: '' |
|
33 |
}) |
|
34 |
|
|
35 |
// 表单校验 |
|
36 |
const equalToPassword = (_rule, value, callback) => { |
|
37 |
if (password.newPassword !== value) { |
|
38 |
callback(new Error(t('profile.password.diffPwd'))) |
|
39 |
} else { |
|
40 |
callback() |
|
41 |
} |
|
42 |
} |
|
43 |
|
|
44 |
const rules = reactive<FormRules>({ |
|
45 |
oldPassword: [ |
|
46 |
{ required: true, message: t('profile.password.oldPwdMsg'), trigger: 'blur' }, |
|
47 |
{ min: 6, max: 20, message: t('profile.password.pwdRules'), trigger: 'blur' } |
|
48 |
], |
|
49 |
newPassword: [ |
|
50 |
{ required: true, message: t('profile.password.newPwdMsg'), trigger: 'blur' }, |
|
51 |
{ min: 6, max: 20, message: t('profile.password.pwdRules'), trigger: 'blur' } |
|
52 |
], |
|
53 |
confirmPassword: [ |
|
54 |
{ required: true, message: t('profile.password.cfPwdMsg'), trigger: 'blur' }, |
|
55 |
{ required: true, validator: equalToPassword, trigger: 'blur' } |
|
56 |
] |
|
57 |
}) |
|
58 |
|
|
59 |
const submit = (formEl: FormInstance | undefined) => { |
|
60 |
if (!formEl) return |
|
61 |
formEl.validate(async (valid) => { |
|
62 |
if (valid) { |
|
63 |
await updateUserPassword(password.oldPassword, password.newPassword) |
|
64 |
message.success(t('common.updateSuccess')) |
|
65 |
} |
|
66 |
}) |
|
67 |
} |
|
68 |
|
|
69 |
const reset = (formEl: FormInstance | undefined) => { |
|
70 |
if (!formEl) return |
|
71 |
formEl.resetFields() |
|
72 |
} |
|
73 |
</script> |