2023-02-11 00:44:00 +08:00
|
|
|
<template>
|
|
|
|
<el-form ref="formRef" :model="password" :rules="rules" label-width="80px">
|
|
|
|
<el-form-item :label="t('profile.password.oldPassword')">
|
|
|
|
<InputPassword v-model="password.oldPassword" />
|
|
|
|
</el-form-item>
|
|
|
|
<el-form-item :label="t('profile.password.newPassword')">
|
|
|
|
<InputPassword v-model="password.newPassword" strength />
|
|
|
|
</el-form-item>
|
|
|
|
<el-form-item :label="t('profile.password.confirmPassword')">
|
|
|
|
<InputPassword v-model="password.confirmPassword" strength />
|
|
|
|
</el-form-item>
|
|
|
|
<el-form-item>
|
2023-04-14 21:32:11 +08:00
|
|
|
<XButton :title="t('common.save')" type="primary" @click="submit(formRef)" />
|
|
|
|
<XButton :title="t('common.reset')" type="danger" @click="reset(formRef)" />
|
2023-02-11 00:44:00 +08:00
|
|
|
</el-form-item>
|
|
|
|
</el-form>
|
|
|
|
</template>
|
2023-06-21 19:14:34 +08:00
|
|
|
<script lang="ts" setup>
|
2023-04-14 21:32:11 +08:00
|
|
|
import type { FormInstance, FormRules } from 'element-plus'
|
2023-02-11 00:44:00 +08:00
|
|
|
|
|
|
|
import { InputPassword } from '@/components/InputPassword'
|
2023-04-05 20:13:35 +08:00
|
|
|
import { updateUserPassword } from '@/api/system/user/profile'
|
2023-02-11 00:44:00 +08:00
|
|
|
|
2023-06-21 19:14:34 +08:00
|
|
|
defineOptions({ name: 'ResetPwd' })
|
|
|
|
|
2023-02-11 00:44:00 +08:00
|
|
|
const { t } = useI18n()
|
|
|
|
const message = useMessage()
|
|
|
|
const formRef = ref<FormInstance>()
|
|
|
|
const password = reactive({
|
|
|
|
oldPassword: '',
|
|
|
|
newPassword: '',
|
|
|
|
confirmPassword: ''
|
|
|
|
})
|
|
|
|
|
|
|
|
// 表单校验
|
|
|
|
const equalToPassword = (value, callback) => {
|
|
|
|
if (password.newPassword !== value) {
|
|
|
|
callback(new Error(t('profile.password.diffPwd')))
|
|
|
|
} else {
|
|
|
|
callback()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const rules = reactive<FormRules>({
|
|
|
|
oldPassword: [
|
|
|
|
{ required: true, message: t('profile.password.oldPwdMsg'), trigger: 'blur' },
|
|
|
|
{ min: 3, max: 5, message: t('profile.password.pwdRules'), trigger: 'blur' }
|
|
|
|
],
|
|
|
|
newPassword: [
|
|
|
|
{ required: true, message: t('profile.password.newPwdMsg'), trigger: 'blur' },
|
|
|
|
{ min: 6, max: 20, message: t('profile.password.pwdRules'), trigger: 'blur' }
|
|
|
|
],
|
|
|
|
confirmPassword: [
|
|
|
|
{ required: true, message: t('profile.password.cfPwdMsg'), trigger: 'blur' },
|
|
|
|
{ required: true, validator: equalToPassword, trigger: 'blur' }
|
|
|
|
]
|
|
|
|
})
|
|
|
|
const submit = (formEl: FormInstance | undefined) => {
|
|
|
|
if (!formEl) return
|
|
|
|
formEl.validate(async (valid) => {
|
|
|
|
if (valid) {
|
2023-04-05 20:13:35 +08:00
|
|
|
await updateUserPassword(password.oldPassword, password.newPassword)
|
2023-02-11 00:44:00 +08:00
|
|
|
message.success(t('common.updateSuccess'))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
const reset = (formEl: FormInstance | undefined) => {
|
|
|
|
if (!formEl) return
|
|
|
|
formEl.resetFields()
|
|
|
|
}
|
|
|
|
</script>
|