1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
| <script setup lang="ts">
| import type { ResetPwdParam, User } from '#/api/system/user/model';
|
| import { useVbenModal, z } from '@vben/common-ui';
|
| import { useVbenForm } from '#/adapter/form';
| import { userResetPassword } from '#/api/system/user';
| import { Description, useDescription } from '#/components/description';
|
| const emit = defineEmits<{ reload: [] }>();
|
| const [BasicModal, modalApi] = useVbenModal({
| onCancel: handleCancel,
| onConfirm: handleSubmit,
| onOpenChange: handleOpenChange,
| });
|
| const [registerDescription, { setDescProps }] = useDescription({
| column: 1,
| schema: [
| {
| field: 'userId',
| label: '用户ID',
| },
| {
| field: 'userName',
| label: '用户名',
| },
| {
| field: 'nickName',
| label: '昵称',
| },
| ],
| });
|
| const [BasicForm, formApi] = useVbenForm({
| schema: [
| {
| component: 'Input',
| dependencies: {
| show: () => false,
| triggerFields: [''],
| },
| fieldName: 'userId',
| label: '用户ID',
| rules: 'required',
| },
| {
| component: 'InputPassword',
| componentProps: {
| placeholder: '请输入新的密码, 密码长度为5 - 20',
| },
| fieldName: 'password',
| label: '新的密码',
| rules: z
| .string()
| .min(5, { message: '密码长度为5 - 20' })
| .max(20, { message: '密码长度为5 - 20' }),
| },
| ],
| showDefaultActions: false,
| commonConfig: {
| labelWidth: 80,
| },
| });
|
| async function handleOpenChange(open: boolean) {
| if (!open) {
| return null;
| }
| const { record } = modalApi.getData() as { record: User };
| setDescProps({ data: record }, true);
| await formApi.setValues({ userId: record.userId });
| }
|
| async function handleSubmit() {
| try {
| modalApi.modalLoading(true);
| const { valid } = await formApi.validate();
| if (!valid) {
| return;
| }
| const data = await formApi.getValues();
| await userResetPassword(data as ResetPwdParam);
| emit('reload');
| handleCancel();
| } catch (error) {
| console.error(error);
| } finally {
| modalApi.modalLoading(false);
| }
| }
|
| async function handleCancel() {
| modalApi.close();
| await formApi.resetForm();
| }
| </script>
|
| <template>
| <BasicModal
| :close-on-click-modal="false"
| :fullscreen-button="false"
| title="重置密码"
| >
| <div class="flex flex-col gap-[12px]">
| <Description @register="registerDescription" />
| <BasicForm />
| </div>
| </BasicModal>
| </template>
|
|