2024-09-26 09:50:10 +08:00
|
|
|
<script setup lang="ts">
|
2025-01-20 03:43:19 +00:00
|
|
|
import type { ResetPwdParam, User } from '#/api/system/user/model';
|
2024-09-26 09:50:10 +08:00
|
|
|
|
2025-04-04 19:55:49 +08:00
|
|
|
import { ref } from 'vue';
|
|
|
|
|
2024-09-26 09:50:10 +08:00
|
|
|
import { useVbenModal, z } from '@vben/common-ui';
|
|
|
|
|
2025-04-04 19:55:49 +08:00
|
|
|
import { Descriptions, DescriptionsItem } from 'ant-design-vue';
|
|
|
|
|
2024-10-17 15:16:22 +08:00
|
|
|
import { useVbenForm } from '#/adapter/form';
|
2024-09-26 09:50:10 +08:00
|
|
|
import { userResetPassword } from '#/api/system/user';
|
|
|
|
|
|
|
|
const emit = defineEmits<{ reload: [] }>();
|
|
|
|
|
|
|
|
const [BasicModal, modalApi] = useVbenModal({
|
2025-04-04 19:55:49 +08:00
|
|
|
onClosed: handleClosed,
|
2024-09-26 09:50:10 +08:00
|
|
|
onConfirm: handleSubmit,
|
|
|
|
onOpenChange: handleOpenChange,
|
|
|
|
});
|
|
|
|
|
|
|
|
const [BasicForm, formApi] = useVbenForm({
|
|
|
|
schema: [
|
|
|
|
{
|
|
|
|
component: 'Input',
|
|
|
|
dependencies: {
|
|
|
|
show: () => false,
|
|
|
|
triggerFields: [''],
|
|
|
|
},
|
|
|
|
fieldName: 'userId',
|
|
|
|
label: '用户ID',
|
|
|
|
rules: 'required',
|
|
|
|
},
|
|
|
|
{
|
2024-10-05 22:08:32 +08:00
|
|
|
component: 'InputPassword',
|
2024-09-26 09:50:10 +08:00
|
|
|
componentProps: {
|
|
|
|
placeholder: '请输入新的密码, 密码长度为5 - 20',
|
|
|
|
},
|
|
|
|
fieldName: 'password',
|
|
|
|
label: '新的密码',
|
|
|
|
rules: z
|
|
|
|
.string()
|
|
|
|
.min(5, { message: '密码长度为5 - 20' })
|
|
|
|
.max(20, { message: '密码长度为5 - 20' }),
|
|
|
|
},
|
|
|
|
],
|
2024-10-05 22:08:32 +08:00
|
|
|
showDefaultActions: false,
|
|
|
|
commonConfig: {
|
|
|
|
labelWidth: 80,
|
|
|
|
},
|
2024-09-26 09:50:10 +08:00
|
|
|
});
|
|
|
|
|
2025-04-04 19:55:49 +08:00
|
|
|
const currentUser = ref<null | User>(null);
|
2024-09-26 09:50:10 +08:00
|
|
|
async function handleOpenChange(open: boolean) {
|
|
|
|
if (!open) {
|
|
|
|
return null;
|
|
|
|
}
|
2025-04-04 19:55:49 +08:00
|
|
|
modalApi.modalLoading(true);
|
|
|
|
|
2025-01-20 03:43:19 +00:00
|
|
|
const { record } = modalApi.getData() as { record: User };
|
2025-04-04 19:55:49 +08:00
|
|
|
currentUser.value = record;
|
2024-09-26 09:50:10 +08:00
|
|
|
await formApi.setValues({ userId: record.userId });
|
2025-04-04 19:55:49 +08:00
|
|
|
|
|
|
|
modalApi.modalLoading(false);
|
2024-09-26 09:50:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
async function handleSubmit() {
|
|
|
|
try {
|
|
|
|
modalApi.modalLoading(true);
|
|
|
|
const { valid } = await formApi.validate();
|
|
|
|
if (!valid) {
|
|
|
|
return;
|
|
|
|
}
|
2024-10-06 00:00:27 +08:00
|
|
|
const data = await formApi.getValues();
|
2025-01-20 03:43:19 +00:00
|
|
|
await userResetPassword(data as ResetPwdParam);
|
2024-09-26 09:50:10 +08:00
|
|
|
emit('reload');
|
2025-04-04 19:55:49 +08:00
|
|
|
handleClosed();
|
2024-09-26 09:50:10 +08:00
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
} finally {
|
|
|
|
modalApi.modalLoading(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-04-04 19:55:49 +08:00
|
|
|
async function handleClosed() {
|
2024-09-26 09:50:10 +08:00
|
|
|
modalApi.close();
|
|
|
|
await formApi.resetForm();
|
2025-04-04 19:55:49 +08:00
|
|
|
currentUser.value = null;
|
2024-09-26 09:50:10 +08:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2024-10-05 22:08:32 +08:00
|
|
|
<BasicModal
|
|
|
|
:close-on-click-modal="false"
|
|
|
|
:fullscreen-button="false"
|
|
|
|
title="重置密码"
|
|
|
|
>
|
|
|
|
<div class="flex flex-col gap-[12px]">
|
2025-04-04 19:55:49 +08:00
|
|
|
<Descriptions v-if="currentUser" size="small" :column="1" bordered>
|
|
|
|
<DescriptionsItem label="用户ID">
|
|
|
|
{{ currentUser.userId }}
|
|
|
|
</DescriptionsItem>
|
|
|
|
<DescriptionsItem label="用户名">
|
|
|
|
{{ currentUser.userName }}
|
|
|
|
</DescriptionsItem>
|
|
|
|
<DescriptionsItem label="昵称">
|
|
|
|
{{ currentUser.nickName }}
|
|
|
|
</DescriptionsItem>
|
|
|
|
</Descriptions>
|
2024-10-05 22:08:32 +08:00
|
|
|
<BasicForm />
|
|
|
|
</div>
|
2024-09-26 09:50:10 +08:00
|
|
|
</BasicModal>
|
|
|
|
</template>
|