<template>
|
<BasicModal v-bind="$attrs" @register="registerModal" :title="getTitle" @ok="handleSubmit">
|
<PageWrapper title="修改当前用户密码" content="修改成功后会自动退出当前登录!">
|
<div class="py-8 bg-white flex flex-col justify-center items-center">
|
<BasicForm @register="register" />
|
<!-- <div class="flex justify-center">
|
<a-button @click="resetFields"> 重置 </a-button>
|
<a-button class="!ml-4" type="primary" @click="handleSubmit"> 确认 </a-button>
|
</div> -->
|
</div>
|
</PageWrapper>
|
</BasicModal>
|
</template>
|
<script lang="ts">
|
import { defineComponent, ref, computed, reactive } from 'vue';
|
// import { useRoute } from 'vue-router';
|
import { PageWrapper } from '/@/components/Page';
|
import { BasicForm, useForm } from '/@/components/Form';
|
import { BasicModal, useModalInner } from '/@/components/Modal';
|
import { useUserStore } from '/@/store/modules/user';
|
|
import { formSchema } from './pwd.data';
|
import { getUser, SaveUser } from '/@/api/tigerapi/account';
|
import { AccountListItem } from '/@/api/tigerapi/model/systemModel';
|
export default defineComponent({
|
name: 'ChangePassword',
|
components: { BasicForm, BasicModal, PageWrapper },
|
emits: ['success', 'register'],
|
setup(_, { emit }) {
|
const userStore = useUserStore();
|
const [register, { validate, resetFields, setFieldsValue }] = useForm({
|
size: 'large',
|
labelWidth: 100,
|
showActionButtonGroup: false,
|
schemas: formSchema,
|
});
|
|
const userInfo: AccountListItem[] = reactive([]);
|
|
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
|
resetFields();
|
setModalProps({ confirmLoading: false });
|
//获取密码api
|
getUser(data.passwordOld).then((action) => {
|
if (action.IsSuccessed) {
|
userInfo.values[0] = action.Data[0];
|
setFieldsValue({
|
passwordOld: action.Data[0].USER_PWD,
|
});
|
}
|
});
|
});
|
|
const getTitle = computed(() => '修改密码');
|
|
async function handleSubmit() {
|
try {
|
const values = await validate();
|
const { passwordOld, passwordNew } = values;
|
userInfo.values[0].USER_PWD = passwordNew;
|
// TODO custom api
|
console.log(passwordOld, passwordNew);
|
SaveUser(userInfo.values[0], true).then((action) => {
|
if (action.IsSuccessed) {
|
closeModal();
|
emit('success');
|
userStore.confirmLoginOut(); //登出系统注销用户
|
}
|
});
|
} catch (error) {}
|
}
|
|
return { register, registerModal, resetFields, getTitle, handleSubmit, closeModal };
|
},
|
});
|
</script>
|