优化修改密码

This commit is contained in:
zjl 2024-12-17 15:02:01 +08:00
parent 440a157027
commit 6b50a4d9ba

View File

@ -9,17 +9,20 @@
</template>
<script lang="ts" setup>
import { ref,nextTick } from 'vue';
import { ref, nextTick } from 'vue';
import { basicModal, useModal } from '@/components/Modal';
import { ElMessage } from 'element-plus';
import { BasicForm, FormSchema, useForm } from '@/components/Form/index';
import { changePassword } from '@/api/system/user';
/**
* 创建表单
*/
const schemas: FormSchema[] = [
{
field: 'password',
component: 'Input',
type:'password',
type: 'password',
label: '旧密码',
componentProps: {
placeholder: '请输入旧密码',
@ -29,7 +32,7 @@
{
field: 'newPassword',
component: 'Input',
type:'password',
type: 'password',
label: '新密码',
componentProps: {
placeholder: '请输入新密码',
@ -39,7 +42,7 @@
{
field: 'confirmPassword',
component: 'Input',
type:'password',
type: 'password',
label: '确认密码',
componentProps: {
placeholder: '请再次输入新密码',
@ -50,7 +53,10 @@
const modalRef: any = ref(null);
const [register, { submit,resetFields,getFieldsValue }] = useForm({
/**
* 定义页面
*/
const [register, { submit, resetFields, getFieldsValue }] = useForm({
collapsedRows: 3,
labelWidth: 80,
layout: 'horizontal',
@ -58,38 +64,53 @@
schemas,
});
/**
* 定义模态
*/
const [modalRegister, { openModal, closeModal, setSubLoading }] = useModal({
title: '修改密码',
subBtuText: '提交修改',
});
/**
* 提交表单数据
*/
async function formSubmit() {
const formRes = await submit();
if (formRes) {
try{
await changePassword(getFieldsValue())
closeModal();
ElMessage.success('修改成功');
} catch(e){
try {
await changePassword(getFieldsValue());
closeModal();
ElMessage.success('修改成功');
} catch (e) {
setSubLoading(false);
}
} else {
ElMessage.error('验证失败,请填写完整信息');
setSubLoading(false);
}
}
/**
* 显示弹窗
*/
async function showModal() {
openModal();
await nextTick()
resetFields()
await nextTick();
resetFields();
}
/**
* 执行重置
* @param values 参数
*/
function handleReset(values: Recordable) {
console.log(values);
}
/**
* 定义函数
*/
defineExpose({
showModal,
});