TenantAdminFormDrawer.vue
3.8 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<template>
<BasicDrawer
v-bind="$attrs"
@register="tenantAdminFormDrawer"
showFooter
:title="getTitle"
width="60%"
@ok="handleSubmit"
>
<BasicForm @register="tenantAdminForm" />
</BasicDrawer>
</template>
<script lang="ts">
import { computed, defineComponent, ref, unref } from 'vue';
import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
import { saveTenantAdmin } from '/@/api/tenant/tenantApi';
import { UserDTO } from '/@/api/tenant/tenantInfo';
import { emailRule, phoneRule } from '/@/utils/rules';
export default defineComponent({
name: 'TenantAdminFormDrawer',
components: {
BasicDrawer,
BasicForm,
},
emits: ['success'],
setup(_, { emit }) {
const isUpdate = ref(true);
const tenantId = ref('');
const formSchema: FormSchema[] = [
{
field: 'id',
label: 'id:',
show: false,
component: 'Input',
},
{
field: 'username',
label: '账号:',
required: true,
component: 'Input',
},
{
field: 'realName',
label: '真实名字:',
required: true,
component: 'Input',
},
{
field: 'phoneNumber',
label: '电话号码:',
required: true,
component: 'Input',
rules: phoneRule,
},
{
field: 'email',
label: '邮件:',
required: true,
component: 'Input',
rules: emailRule,
},
{
field: 'enabled',
label: '状态',
required: true,
component: 'RadioButtonGroup',
defaultValue: true,
componentProps: {
options: [
{ label: '启用', value: true },
{ label: '停用', value: false },
],
},
},
];
const [tenantAdminForm, { resetFields, setFieldsValue, updateSchema, validate }] = useForm({
labelWidth: 100,
schemas: formSchema,
showActionButtonGroup: false,
baseColProps: { lg: 24, md: 24 },
});
const [tenantAdminFormDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(
async (data) => {
await resetFields();
isUpdate.value = !!data?.isUpdate;
tenantId.value = data?.tenantId;
await updateSchema({ field: 'title', componentProps: { disabled: false } });
if (unref(isUpdate)) {
await setFieldsValue({
...data.record,
});
}
}
);
const getTitle = computed(() => (!unref(isUpdate) ? '新增租户管理员' : '编辑租户管理员'));
async function handleSubmit() {
try {
const values = await validate();
const requestParams = {
id: values.id,
username: values.username,
realName: values.realName,
phoneNumber: values.phoneNumber,
email: values.email,
enabled: values.enabled,
tenantExpireTime:
typeof values.tenantExpireTime != 'undefined' && values.tenantExpireTime != null
? values.tenantExpireTime.format('YYYY-MM-DD HH:mm:ss')
: null,
tenantId: tenantId.value,
};
setDrawerProps({ confirmLoading: true });
saveTenantAdmin(requestParams as any as UserDTO).then(() => {
closeDrawer(); //关闭侧框
emit('success');
});
} finally {
setDrawerProps({ confirmLoading: false });
}
}
return {
tenantAdminFormDrawer,
handleSubmit,
tenantAdminForm,
getTitle,
};
},
});
</script>