Commit 5b2888aafa0f2a0eb48eba8391ca9a0882276c23
1 parent
6c08bd8b
fix: DEFECT-1644 所有可以上传图片的都需要预览个删除按钮
Showing
3 changed files
with
50 additions
and
30 deletions
@@ -12,6 +12,9 @@ import ObjectModelValidateForm from '/@/components/Form/src/externalCompns/compo | @@ -12,6 +12,9 @@ import ObjectModelValidateForm from '/@/components/Form/src/externalCompns/compo | ||
12 | import { CommandDeliveryWayEnum, ServiceCallTypeEnum } from '/@/enums/toolEnum'; | 12 | import { CommandDeliveryWayEnum, ServiceCallTypeEnum } from '/@/enums/toolEnum'; |
13 | import { TaskTypeEnum } from '/@/views/task/center/config'; | 13 | import { TaskTypeEnum } from '/@/views/task/center/config'; |
14 | import { AddressTypeEnum } from '/@/views/task/center/components/PollCommandInput'; | 14 | import { AddressTypeEnum } from '/@/views/task/center/components/PollCommandInput'; |
15 | +import { FileItem } from '/@/components/Form/src/components/ApiUpload.vue'; | ||
16 | +import { createImgPreview } from '/@/components/Preview'; | ||
17 | +import { uploadThumbnail } from '/@/api/configuration/center/configurationCenter'; | ||
15 | 18 | ||
16 | useComponentRegister('JSONEditor', JSONEditor); | 19 | useComponentRegister('JSONEditor', JSONEditor); |
17 | useComponentRegister('ObjectModelValidateForm', ObjectModelValidateForm); | 20 | useComponentRegister('ObjectModelValidateForm', ObjectModelValidateForm); |
@@ -29,8 +32,33 @@ export const step1Schemas: FormSchema[] = [ | @@ -29,8 +32,33 @@ export const step1Schemas: FormSchema[] = [ | ||
29 | { | 32 | { |
30 | field: 'icon', | 33 | field: 'icon', |
31 | label: '设备图片', | 34 | label: '设备图片', |
32 | - slot: 'iconSelect', | ||
33 | - component: 'Input', | 35 | + component: 'ApiUpload', |
36 | + changeEvent: 'update:fileList', | ||
37 | + valueField: 'fileList', | ||
38 | + componentProps: () => { | ||
39 | + return { | ||
40 | + listType: 'picture-card', | ||
41 | + maxFileLimit: 1, | ||
42 | + accept: '.png,.jpg,.jpeg,.gif', | ||
43 | + api: async (file: File) => { | ||
44 | + try { | ||
45 | + const formData = new FormData(); | ||
46 | + formData.set('file', file); | ||
47 | + const { fileStaticUri, fileName } = await uploadThumbnail(formData); | ||
48 | + return { | ||
49 | + uid: fileStaticUri, | ||
50 | + name: fileName, | ||
51 | + url: fileStaticUri, | ||
52 | + } as FileItem; | ||
53 | + } catch (error) { | ||
54 | + return {}; | ||
55 | + } | ||
56 | + }, | ||
57 | + onPreview: (fileList: FileItem) => { | ||
58 | + createImgPreview({ imageList: [fileList.url!] }); | ||
59 | + }, | ||
60 | + }; | ||
61 | + }, | ||
34 | }, | 62 | }, |
35 | { | 63 | { |
36 | field: 'alias', | 64 | field: 'alias', |
@@ -157,7 +157,7 @@ | @@ -157,7 +157,7 @@ | ||
157 | sn: stepRecord.name, | 157 | sn: stepRecord.name, |
158 | customerId: currentDeviceData.customerId, | 158 | customerId: currentDeviceData.customerId, |
159 | deviceInfo: { | 159 | deviceInfo: { |
160 | - avatar: DeviceStep1Ref.value?.devicePic, | 160 | + avatar: stepRecord?.icon, |
161 | ...DeviceStep1Ref.value?.devicePositionState, | 161 | ...DeviceStep1Ref.value?.devicePositionState, |
162 | }, | 162 | }, |
163 | }; | 163 | }; |
@@ -169,7 +169,7 @@ | @@ -169,7 +169,7 @@ | ||
169 | ...stepRecord, | 169 | ...stepRecord, |
170 | sn: stepRecord.name, | 170 | sn: stepRecord.name, |
171 | deviceInfo: { | 171 | deviceInfo: { |
172 | - avatar: DeviceStep1Ref.value?.devicePic, | 172 | + avatar: stepRecord?.icon, |
173 | ...DeviceStep1Ref.value?.devicePositionState, | 173 | ...DeviceStep1Ref.value?.devicePositionState, |
174 | }, | 174 | }, |
175 | deviceToken: | 175 | deviceToken: |
@@ -22,24 +22,6 @@ | @@ -22,24 +22,6 @@ | ||
22 | </div> | 22 | </div> |
23 | </div> | 23 | </div> |
24 | </template> | 24 | </template> |
25 | - <template #iconSelect> | ||
26 | - <Upload | ||
27 | - name="avatar" | ||
28 | - accept=".png,.jpg,.jpeg,.gif" | ||
29 | - :show-upload-list="false" | ||
30 | - list-type="picture-card" | ||
31 | - class="avatar-uploader" | ||
32 | - :customRequest="customUpload" | ||
33 | - :before-upload="beforeUpload" | ||
34 | - > | ||
35 | - <img v-if="devicePic" :src="devicePic" alt="avatar" /> | ||
36 | - <div v-else> | ||
37 | - <LoadingOutlined v-if="loading" /> | ||
38 | - <PlusOutlined v-else /> | ||
39 | - <div class="ant-upload-text">图片上传</div> | ||
40 | - </div> | ||
41 | - </Upload> | ||
42 | - </template> | ||
43 | <template #snCode="{ model, field }"> | 25 | <template #snCode="{ model, field }"> |
44 | <div class="flex"> | 26 | <div class="flex"> |
45 | <Input v-model:value="model[field]" placeholder="请输入设备名称" /> | 27 | <Input v-model:value="model[field]" placeholder="请输入设备名称" /> |
@@ -115,10 +97,9 @@ | @@ -115,10 +97,9 @@ | ||
115 | import { BasicForm, useForm } from '/@/components/Form'; | 97 | import { BasicForm, useForm } from '/@/components/Form'; |
116 | import { step1Schemas } from '../../config/data'; | 98 | import { step1Schemas } from '../../config/data'; |
117 | import { useScript } from '/@/hooks/web/useScript'; | 99 | import { useScript } from '/@/hooks/web/useScript'; |
118 | - import { Input, Upload, message, Modal, Form, Row, Col, AutoComplete } from 'ant-design-vue'; | ||
119 | - import { EnvironmentTwoTone, PlusOutlined, LoadingOutlined } from '@ant-design/icons-vue'; | 100 | + import { Input, message, Modal, Form, Row, Col, AutoComplete } from 'ant-design-vue'; |
101 | + import { EnvironmentTwoTone } from '@ant-design/icons-vue'; | ||
120 | import { upload } from '/@/api/oss/ossFileUploader'; | 102 | import { upload } from '/@/api/oss/ossFileUploader'; |
121 | - import { FileItem } from '/@/components/Upload/src/typing'; | ||
122 | import { BAI_DU_MAP_URL } from '/@/utils/fnUtils'; | 103 | import { BAI_DU_MAP_URL } from '/@/utils/fnUtils'; |
123 | import { generateSNCode } from '/@/api/device/deviceManager'; | 104 | import { generateSNCode } from '/@/api/device/deviceManager'; |
124 | import icon from '/@/assets/images/wz.png'; | 105 | import icon from '/@/assets/images/wz.png'; |
@@ -130,21 +111,20 @@ | @@ -130,21 +111,20 @@ | ||
130 | import DeptDrawer from '/@/views/system/organization/OrganizationDrawer.vue'; | 111 | import DeptDrawer from '/@/views/system/organization/OrganizationDrawer.vue'; |
131 | import { TaskTypeEnum } from '/@/views/task/center/config'; | 112 | import { TaskTypeEnum } from '/@/views/task/center/config'; |
132 | import { toRaw } from 'vue'; | 113 | import { toRaw } from 'vue'; |
114 | + import { FileItem } from '/@/components/Form/src/components/ApiUpload.vue'; | ||
115 | + import { buildUUID } from '/@/utils/uuid'; | ||
133 | 116 | ||
134 | export default defineComponent({ | 117 | export default defineComponent({ |
135 | components: { | 118 | components: { |
136 | BasicForm, | 119 | BasicForm, |
137 | Input, | 120 | Input, |
138 | AutoComplete, | 121 | AutoComplete, |
139 | - Upload, | ||
140 | EnvironmentTwoTone, | 122 | EnvironmentTwoTone, |
141 | - PlusOutlined, | ||
142 | Modal, | 123 | Modal, |
143 | Form, | 124 | Form, |
144 | FormItem: Form.Item, | 125 | FormItem: Form.Item, |
145 | Row, | 126 | Row, |
146 | Col, | 127 | Col, |
147 | - LoadingOutlined, | ||
148 | DeptDrawer, | 128 | DeptDrawer, |
149 | }, | 129 | }, |
150 | props: { | 130 | props: { |
@@ -202,8 +182,11 @@ | @@ -202,8 +182,11 @@ | ||
202 | async function nextStep() { | 182 | async function nextStep() { |
203 | try { | 183 | try { |
204 | let values = await validate(); | 184 | let values = await validate(); |
205 | - values = { devicePic: devicePic.value, ...positionState, ...values }; | ||
206 | - delete values.icon; | 185 | + if (Reflect.has(values, 'icon')) { |
186 | + const file = (unref(values.icon) || []).at(0) || {}; | ||
187 | + values.icon = file.url || null; | ||
188 | + } | ||
189 | + values = { ...positionState, ...values }; | ||
207 | delete values.deviceAddress; | 190 | delete values.deviceAddress; |
208 | emit('next', values); | 191 | emit('next', values); |
209 | // 获取输入的数据 | 192 | // 获取输入的数据 |
@@ -405,6 +388,11 @@ | @@ -405,6 +388,11 @@ | ||
405 | positionState.address = deviceInfo.address; | 388 | positionState.address = deviceInfo.address; |
406 | devicePositionState.value = { ...toRaw(positionState) }; | 389 | devicePositionState.value = { ...toRaw(positionState) }; |
407 | devicePic.value = deviceInfo.avatar; | 390 | devicePic.value = deviceInfo.avatar; |
391 | + if (deviceInfo.avatar) { | ||
392 | + setFieldsValue({ | ||
393 | + icon: [{ uid: buildUUID(), name: 'name', url: deviceInfo.avatar } as FileItem], | ||
394 | + }); | ||
395 | + } | ||
408 | setFieldsValue({ | 396 | setFieldsValue({ |
409 | ...data, | 397 | ...data, |
410 | code: data?.code, | 398 | code: data?.code, |
@@ -414,6 +402,10 @@ | @@ -414,6 +402,10 @@ | ||
414 | // 父组件调用获取字段值的方法 | 402 | // 父组件调用获取字段值的方法 |
415 | function parentGetFieldsValue() { | 403 | function parentGetFieldsValue() { |
416 | const value = getFieldsValue(); | 404 | const value = getFieldsValue(); |
405 | + if (Reflect.has(value, 'icon')) { | ||
406 | + const file = (value.icon || []).at(0) || {}; | ||
407 | + value.icon = file.url || null; | ||
408 | + } | ||
417 | return { | 409 | return { |
418 | ...value, | 410 | ...value, |
419 | ...(value?.code || value?.addressCode | 411 | ...(value?.code || value?.addressCode |