...
|
...
|
@@ -7,50 +7,25 @@ |
7
|
7
|
width="500px"
|
8
|
8
|
@ok="handleSubmit"
|
9
|
9
|
>
|
10
|
|
- <BasicForm @register="tenantForm">
|
11
|
|
- <template #iconSelect>
|
12
|
|
- <Upload
|
13
|
|
- name="avatar"
|
14
|
|
- accept=".png,.jpg,.jpeg,.gif"
|
15
|
|
- list-type="picture-card"
|
16
|
|
- class="avatar-uploader"
|
17
|
|
- :show-upload-list="false"
|
18
|
|
- :customRequest="customUpload"
|
19
|
|
- :before-upload="beforeUpload"
|
20
|
|
- >
|
21
|
|
- <img v-if="tenantLogo" :src="tenantLogo" alt="avatar" />
|
22
|
|
- <div v-else>
|
23
|
|
- <LoadingOutlined v-if="loading" />
|
24
|
|
- <plus-outlined v-else />
|
25
|
|
- <div class="ant-upload-text">上传</div>
|
26
|
|
- </div>
|
27
|
|
- </Upload>
|
28
|
|
- </template>
|
29
|
|
- </BasicForm>
|
|
10
|
+ <BasicForm @register="tenantForm" />
|
30
|
11
|
</BasicDrawer>
|
31
|
12
|
</template>
|
32
|
13
|
<script lang="ts">
|
33
|
14
|
import { defineComponent, ref, computed, unref } from 'vue';
|
34
|
15
|
import { BasicForm, useForm } from '/@/components/Form/index';
|
35
|
16
|
import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
|
36
|
|
- import { PlusOutlined, LoadingOutlined } from '@ant-design/icons-vue';
|
37
|
|
- import { message, Upload } from 'ant-design-vue';
|
38
|
|
-
|
39
|
17
|
import { useI18n } from '/@/hooks/web/useI18n';
|
40
|
18
|
import { tenantFormSchema } from '/@/views/tenant/list/tenantBaseColumns';
|
41
|
|
- import { FileItem } from '/@/components/Upload/src/typing';
|
42
|
|
- import { upload } from '/@/api/oss/ossFileUploader';
|
43
|
19
|
import { getTenantRoles, updateOrCreateTenant } from '/@/api/tenant/tenantApi';
|
44
|
20
|
import { useMessage } from '/@/hooks/web/useMessage';
|
|
21
|
+ import { FileItem } from '/@/components/Form/src/components/ApiUpload.vue';
|
|
22
|
+ import { buildUUID } from '/@/utils/uuid';
|
45
|
23
|
|
46
|
24
|
export default defineComponent({
|
47
|
25
|
name: 'TenantDrawer',
|
48
|
26
|
components: {
|
49
|
27
|
BasicDrawer,
|
50
|
28
|
BasicForm,
|
51
|
|
- Upload,
|
52
|
|
- PlusOutlined,
|
53
|
|
- LoadingOutlined,
|
54
|
29
|
},
|
55
|
30
|
emits: ['success', 'register'],
|
56
|
31
|
setup(_, { emit }) {
|
...
|
...
|
@@ -58,33 +33,7 @@ |
58
|
33
|
const { createMessage } = useMessage();
|
59
|
34
|
|
60
|
35
|
const isUpdate = ref(true);
|
61
|
|
- const tenantLogo = ref('');
|
62
|
|
-
|
63
|
|
- async function customUpload({ file }) {
|
64
|
|
- if (beforeUpload(file)) {
|
65
|
|
- tenantLogo.value = '';
|
66
|
|
- loading.value = true;
|
67
|
|
- const formData = new FormData();
|
68
|
|
- formData.append('file', file);
|
69
|
|
- const response = await upload(formData);
|
70
|
|
- if (response.fileStaticUri) {
|
71
|
|
- tenantLogo.value = response.fileStaticUri;
|
72
|
|
- loading.value = false;
|
73
|
|
- }
|
74
|
|
- }
|
75
|
|
- }
|
76
|
36
|
|
77
|
|
- const beforeUpload = (file: FileItem) => {
|
78
|
|
- const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png';
|
79
|
|
- if (!isJpgOrPng) {
|
80
|
|
- message.error('只能上传图片文件!');
|
81
|
|
- }
|
82
|
|
- const isLt2M = (file.size as number) / 1024 / 1024 < 5;
|
83
|
|
- if (!isLt2M) {
|
84
|
|
- message.error('图片大小不能超过5MB!');
|
85
|
|
- }
|
86
|
|
- return isJpgOrPng && isLt2M;
|
87
|
|
- };
|
88
|
37
|
const [tenantForm, { resetFields, setFieldsValue, updateSchema, validate }] = useForm({
|
89
|
38
|
labelWidth: 100,
|
90
|
39
|
schemas: tenantFormSchema,
|
...
|
...
|
@@ -96,7 +45,6 @@ |
96
|
45
|
//默认传递页面数据
|
97
|
46
|
const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => {
|
98
|
47
|
await resetFields();
|
99
|
|
- tenantLogo.value = '';
|
100
|
48
|
setDrawerProps({ confirmLoading: false });
|
101
|
49
|
isUpdate.value = !!data?.isUpdate;
|
102
|
50
|
|
...
|
...
|
@@ -104,11 +52,19 @@ |
104
|
52
|
await updateSchema({ field: 'title', componentProps: { disabled: false } });
|
105
|
53
|
//如果是编辑操作,设置页面数据
|
106
|
54
|
if (unref(isUpdate)) {
|
|
55
|
+ if (data.record.icon) {
|
|
56
|
+ setFieldsValue({
|
|
57
|
+ icon: [{ uid: buildUUID(), name: 'name', url: data.record.icon } as FileItem],
|
|
58
|
+ });
|
|
59
|
+ }
|
107
|
60
|
getTenantRoles(data.record.tenantId).then((result) => {
|
108
|
|
- Reflect.set(data.record, 'roleIds', result);
|
|
61
|
+ const { icon, ...params } = data.record;
|
|
62
|
+ console.log(icon);
|
109
|
63
|
//为表单赋值
|
110
|
|
- setFieldsValue(data.record);
|
111
|
|
- tenantLogo.value = data.record.icon;
|
|
64
|
+ setFieldsValue({
|
|
65
|
+ ...params,
|
|
66
|
+ roleIds: result,
|
|
67
|
+ });
|
112
|
68
|
//编辑模式,菜单名称为不可用
|
113
|
69
|
updateSchema({ field: 'title', componentProps: { disabled: true } });
|
114
|
70
|
});
|
...
|
...
|
@@ -126,9 +82,13 @@ |
126
|
82
|
setDrawerProps({ confirmLoading: true });
|
127
|
83
|
try {
|
128
|
84
|
const values = await validate();
|
|
85
|
+ if (Reflect.has(values, 'icon')) {
|
|
86
|
+ const file = (values.icon || []).at(0) || {};
|
|
87
|
+ values.icon = file.url || null;
|
|
88
|
+ }
|
129
|
89
|
const req = {
|
130
|
90
|
id: values.id,
|
131
|
|
- icon: tenantLogo.value,
|
|
91
|
+ icon: values.icon,
|
132
|
92
|
name: values.name,
|
133
|
93
|
enabled: values.enabled,
|
134
|
94
|
description: values.description,
|
...
|
...
|
@@ -161,9 +121,6 @@ |
161
|
121
|
tenantForm,
|
162
|
122
|
getTitle,
|
163
|
123
|
handleSubmit,
|
164
|
|
- tenantLogo,
|
165
|
|
- beforeUpload,
|
166
|
|
- customUpload,
|
167
|
124
|
loading,
|
168
|
125
|
};
|
169
|
126
|
},
|
...
|
...
|
|