Commit 5b2888aafa0f2a0eb48eba8391ca9a0882276c23

Authored by fengwotao
1 parent 6c08bd8b

fix: DEFECT-1644 所有可以上传图片的都需要预览个删除按钮

... ... @@ -12,6 +12,9 @@ import ObjectModelValidateForm from '/@/components/Form/src/externalCompns/compo
12 12 import { CommandDeliveryWayEnum, ServiceCallTypeEnum } from '/@/enums/toolEnum';
13 13 import { TaskTypeEnum } from '/@/views/task/center/config';
14 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 19 useComponentRegister('JSONEditor', JSONEditor);
17 20 useComponentRegister('ObjectModelValidateForm', ObjectModelValidateForm);
... ... @@ -29,8 +32,33 @@ export const step1Schemas: FormSchema[] = [
29 32 {
30 33 field: 'icon',
31 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 64 field: 'alias',
... ...
... ... @@ -157,7 +157,7 @@
157 157 sn: stepRecord.name,
158 158 customerId: currentDeviceData.customerId,
159 159 deviceInfo: {
160   - avatar: DeviceStep1Ref.value?.devicePic,
  160 + avatar: stepRecord?.icon,
161 161 ...DeviceStep1Ref.value?.devicePositionState,
162 162 },
163 163 };
... ... @@ -169,7 +169,7 @@
169 169 ...stepRecord,
170 170 sn: stepRecord.name,
171 171 deviceInfo: {
172   - avatar: DeviceStep1Ref.value?.devicePic,
  172 + avatar: stepRecord?.icon,
173 173 ...DeviceStep1Ref.value?.devicePositionState,
174 174 },
175 175 deviceToken:
... ...
... ... @@ -22,24 +22,6 @@
22 22 </div>
23 23 </div>
24 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 25 <template #snCode="{ model, field }">
44 26 <div class="flex">
45 27 <Input v-model:value="model[field]" placeholder="请输入设备名称" />
... ... @@ -115,10 +97,9 @@
115 97 import { BasicForm, useForm } from '/@/components/Form';
116 98 import { step1Schemas } from '../../config/data';
117 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 102 import { upload } from '/@/api/oss/ossFileUploader';
121   - import { FileItem } from '/@/components/Upload/src/typing';
122 103 import { BAI_DU_MAP_URL } from '/@/utils/fnUtils';
123 104 import { generateSNCode } from '/@/api/device/deviceManager';
124 105 import icon from '/@/assets/images/wz.png';
... ... @@ -130,21 +111,20 @@
130 111 import DeptDrawer from '/@/views/system/organization/OrganizationDrawer.vue';
131 112 import { TaskTypeEnum } from '/@/views/task/center/config';
132 113 import { toRaw } from 'vue';
  114 + import { FileItem } from '/@/components/Form/src/components/ApiUpload.vue';
  115 + import { buildUUID } from '/@/utils/uuid';
133 116
134 117 export default defineComponent({
135 118 components: {
136 119 BasicForm,
137 120 Input,
138 121 AutoComplete,
139   - Upload,
140 122 EnvironmentTwoTone,
141   - PlusOutlined,
142 123 Modal,
143 124 Form,
144 125 FormItem: Form.Item,
145 126 Row,
146 127 Col,
147   - LoadingOutlined,
148 128 DeptDrawer,
149 129 },
150 130 props: {
... ... @@ -202,8 +182,11 @@
202 182 async function nextStep() {
203 183 try {
204 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 190 delete values.deviceAddress;
208 191 emit('next', values);
209 192 // 获取输入的数据
... ... @@ -405,6 +388,11 @@
405 388 positionState.address = deviceInfo.address;
406 389 devicePositionState.value = { ...toRaw(positionState) };
407 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 396 setFieldsValue({
409 397 ...data,
410 398 code: data?.code,
... ... @@ -414,6 +402,10 @@
414 402 // 父组件调用获取字段值的方法
415 403 function parentGetFieldsValue() {
416 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 409 return {
418 410 ...value,
419 411 ...(value?.code || value?.addressCode
... ...