2024-01-26 16:15:40 +08:00
|
|
|
<template>
|
2024-10-16 20:31:54 +08:00
|
|
|
<el-dialog draggable width="500px" v-model="dialogVisible" :title="title">
|
2024-01-26 16:15:40 +08:00
|
|
|
<el-scrollbar>
|
2024-01-29 14:57:49 +08:00
|
|
|
<el-form :inline="false" :model="form" label-width="120px" :rules="rules" ref="formRef">
|
|
|
|
|
<el-form-item label="校验密码:" prop="password">
|
2024-12-17 11:05:04 +08:00
|
|
|
<el-input v-model="form.password" type="password"
|
2024-12-13 14:36:23 +08:00
|
|
|
placeholder="请输入校验密码" show-password />
|
2024-01-26 16:15:40 +08:00
|
|
|
</el-form-item>
|
2024-01-29 14:57:49 +08:00
|
|
|
<el-form-item label="新密码:" prop="newPwd" style="margin-top: 20px">
|
2024-12-17 11:05:04 +08:00
|
|
|
<el-input v-model="form.newPwd" type="password" placeholder="请输入新密码"
|
2024-12-13 14:36:23 +08:00
|
|
|
show-password />
|
2024-01-26 16:15:40 +08:00
|
|
|
</el-form-item>
|
2024-01-29 14:57:49 +08:00
|
|
|
<el-form-item label="确认密码:" prop="confirmPwd" style="margin-top: 20px">
|
2024-12-17 11:05:04 +08:00
|
|
|
<el-input v-model="form.confirmPwd" type="password"
|
2024-12-13 14:36:23 +08:00
|
|
|
placeholder="请输入确认密码" show-password />
|
2024-01-26 16:15:40 +08:00
|
|
|
</el-form-item>
|
|
|
|
|
</el-form>
|
|
|
|
|
</el-scrollbar>
|
|
|
|
|
<template #footer>
|
2024-01-29 14:57:49 +08:00
|
|
|
<span class="dialog-footer">
|
|
|
|
|
<el-button @click="dialogVisible = false">取消</el-button>
|
|
|
|
|
<el-button type="primary" @click="submit">确认</el-button>
|
2024-01-26 16:15:40 +08:00
|
|
|
</span>
|
|
|
|
|
</template>
|
|
|
|
|
</el-dialog>
|
|
|
|
|
</template>
|
2024-01-29 14:57:49 +08:00
|
|
|
<script lang="ts" setup>
|
2024-01-26 16:15:40 +08:00
|
|
|
import { ref, inject } from 'vue'
|
|
|
|
|
import { reactive } from 'vue'
|
|
|
|
|
import { ElMessage } from 'element-plus'
|
|
|
|
|
import { passwordConfirm, updatePassword } from '@/api/user-boot/user'
|
|
|
|
|
import { validatePwd } from '@/utils/common'
|
|
|
|
|
import { useAdminInfo } from '@/stores/adminInfo'
|
|
|
|
|
|
|
|
|
|
const adminInfo = useAdminInfo()
|
|
|
|
|
const dialogVisible = ref(false)
|
|
|
|
|
const title = ref('修改密码')
|
|
|
|
|
const formRef = ref()
|
|
|
|
|
// 注意不要和表单ref的命名冲突
|
|
|
|
|
const form = reactive({
|
|
|
|
|
password: '',
|
|
|
|
|
newPwd: '',
|
|
|
|
|
confirmPwd: ''
|
|
|
|
|
})
|
|
|
|
|
const rules = {
|
|
|
|
|
password: [
|
|
|
|
|
{ required: true, message: '请输入校验密码', trigger: 'blur' },
|
|
|
|
|
{
|
|
|
|
|
min: 6,
|
|
|
|
|
max: 16,
|
|
|
|
|
message: '长度在 6 到 16 个字符',
|
|
|
|
|
trigger: 'blur'
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
newPwd: [
|
|
|
|
|
{ required: true, message: '请输入密码', trigger: 'blur' },
|
|
|
|
|
{
|
|
|
|
|
min: 6,
|
|
|
|
|
max: 16,
|
|
|
|
|
message: '长度在 6 到 16 个字符',
|
|
|
|
|
trigger: 'blur'
|
|
|
|
|
},
|
|
|
|
|
{ validator: validatePwd, trigger: 'blur' }
|
|
|
|
|
],
|
|
|
|
|
confirmPwd: [
|
|
|
|
|
{ required: true, message: '请确认密码', trigger: 'blur' },
|
|
|
|
|
{
|
|
|
|
|
min: 6,
|
|
|
|
|
max: 16,
|
|
|
|
|
message: '长度在 6 到 16 个字符',
|
|
|
|
|
trigger: 'blur'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
validator: (rule: any, value: string, callback: any) => {
|
|
|
|
|
if (value === '') {
|
|
|
|
|
callback(new Error('请再次输入密码'))
|
|
|
|
|
} else if (value !== form.newPwd) {
|
|
|
|
|
callback(new Error('两次输入密码不一致!'))
|
|
|
|
|
} else {
|
|
|
|
|
callback()
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
trigger: 'blur',
|
|
|
|
|
required: true
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const open = () => {
|
|
|
|
|
dialogVisible.value = true
|
2024-01-29 14:57:49 +08:00
|
|
|
form.password = ''
|
|
|
|
|
form.newPwd = ''
|
|
|
|
|
form.confirmPwd = ''
|
2024-01-26 16:15:40 +08:00
|
|
|
}
|
|
|
|
|
const submit = () => {
|
2024-01-29 13:57:52 +08:00
|
|
|
formRef.value.validate(async (valid: boolean) => {
|
2024-01-26 16:15:40 +08:00
|
|
|
if (valid) {
|
2024-01-29 14:57:49 +08:00
|
|
|
passwordConfirm(form.password).then(res => {
|
|
|
|
|
updatePassword({
|
|
|
|
|
id: adminInfo.$state.userIndex,
|
|
|
|
|
newPassword: form.newPwd
|
|
|
|
|
}).then((res: any) => {
|
|
|
|
|
ElMessage.success('密码修改成功')
|
|
|
|
|
dialogVisible.value = false
|
2024-01-26 16:15:40 +08:00
|
|
|
})
|
2024-01-29 14:57:49 +08:00
|
|
|
})
|
2024-01-26 16:15:40 +08:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
defineExpose({ open })
|
|
|
|
|
</script>
|