Commit c73313b4037800ba5171102f2c169ad64fc294d8
1 parent
5b2888aa
fix: DEFECT-1644 所有可以上传图片的都需要预览个删除按钮
Showing
2 changed files
with
46 additions
and
67 deletions
| @@ -12,6 +12,9 @@ import { EventType, EventTypeColor, EventTypeName } from '../list/cpns/tabs/Even | @@ -12,6 +12,9 @@ import { EventType, EventTypeColor, EventTypeName } from '../list/cpns/tabs/Even | ||
| 12 | 12 | ||
| 13 | import { useClipboard } from '@vueuse/core'; | 13 | import { useClipboard } from '@vueuse/core'; |
| 14 | import { useMessage } from '/@/hooks/web/useMessage'; | 14 | import { useMessage } from '/@/hooks/web/useMessage'; |
| 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 | export enum Mode { | 19 | export enum Mode { |
| 17 | CARD = 'card', | 20 | CARD = 'card', |
| @@ -158,8 +161,33 @@ export const step1Schemas: FormSchema[] = [ | @@ -158,8 +161,33 @@ export const step1Schemas: FormSchema[] = [ | ||
| 158 | { | 161 | { |
| 159 | field: 'image', | 162 | field: 'image', |
| 160 | label: '上传图片', | 163 | label: '上传图片', |
| 161 | - component: 'Input', | ||
| 162 | - slot: 'imageSelect', | 164 | + component: 'ApiUpload', |
| 165 | + changeEvent: 'update:fileList', | ||
| 166 | + valueField: 'fileList', | ||
| 167 | + componentProps: () => { | ||
| 168 | + return { | ||
| 169 | + listType: 'picture-card', | ||
| 170 | + maxFileLimit: 1, | ||
| 171 | + accept: '.png,.jpg,.jpeg,.gif', | ||
| 172 | + api: async (file: File) => { | ||
| 173 | + try { | ||
| 174 | + const formData = new FormData(); | ||
| 175 | + formData.set('file', file); | ||
| 176 | + const { fileStaticUri, fileName } = await uploadThumbnail(formData); | ||
| 177 | + return { | ||
| 178 | + uid: fileStaticUri, | ||
| 179 | + name: fileName, | ||
| 180 | + url: fileStaticUri, | ||
| 181 | + } as FileItem; | ||
| 182 | + } catch (error) { | ||
| 183 | + return {}; | ||
| 184 | + } | ||
| 185 | + }, | ||
| 186 | + onPreview: (fileList: FileItem) => { | ||
| 187 | + createImgPreview({ imageList: [fileList.url!] }); | ||
| 188 | + }, | ||
| 189 | + }; | ||
| 190 | + }, | ||
| 163 | }, | 191 | }, |
| 164 | { | 192 | { |
| 165 | field: 'deviceType', | 193 | field: 'deviceType', |
| 1 | <template> | 1 | <template> |
| 2 | <div class="step1"> | 2 | <div class="step1"> |
| 3 | - <BasicForm @register="register"> | ||
| 4 | - <template #imageSelect> | ||
| 5 | - <Upload | ||
| 6 | - style="width: 20vw" | ||
| 7 | - name="avatar" | ||
| 8 | - accept=".png,.jpg,.jpeg,.gif" | ||
| 9 | - list-type="picture-card" | ||
| 10 | - class="avatar-uploader" | ||
| 11 | - :show-upload-list="false" | ||
| 12 | - :customRequest="customUploadqrcodePic" | ||
| 13 | - :before-upload="beforeUploadqrcodePic" | ||
| 14 | - > | ||
| 15 | - <img | ||
| 16 | - v-if="deviceConfigPic" | ||
| 17 | - :src="deviceConfigPic" | ||
| 18 | - alt="" | ||
| 19 | - style="width: 6.25rem; height: 6.25rem" | ||
| 20 | - /> | ||
| 21 | - <div v-else> | ||
| 22 | - <LoadingOutlined v-if="loading" /> | ||
| 23 | - <PlusOutlined v-else /> | ||
| 24 | - <div class="ant-upload-text">图片上传</div> | ||
| 25 | - </div> | ||
| 26 | - </Upload> | ||
| 27 | - </template> | ||
| 28 | - </BasicForm> | 3 | + <BasicForm @register="register" /> |
| 29 | </div> | 4 | </div> |
| 30 | </template> | 5 | </template> |
| 31 | <script lang="ts" setup> | 6 | <script lang="ts" setup> |
| 32 | - import { ref, nextTick } from 'vue'; | 7 | + import { nextTick } from 'vue'; |
| 33 | import { BasicForm, useForm } from '/@/components/Form'; | 8 | import { BasicForm, useForm } from '/@/components/Form'; |
| 34 | import { step1Schemas } from '../device.profile.data'; | 9 | import { step1Schemas } from '../device.profile.data'; |
| 35 | - import { uploadApi } from '/@/api/personal/index'; | ||
| 36 | - import { Upload } from 'ant-design-vue'; | ||
| 37 | - import { PlusOutlined, LoadingOutlined } from '@ant-design/icons-vue'; | ||
| 38 | - import { useMessage } from '/@/hooks/web/useMessage'; | ||
| 39 | - import type { FileItem } from '/@/components/Upload/src/typing'; | 10 | + import { FileItem } from '/@/components/Form/src/components/ApiUpload.vue'; |
| 11 | + import { buildUUID } from '/@/utils/uuid'; | ||
| 40 | 12 | ||
| 41 | const emits = defineEmits(['next', 'emitDeviceType']); | 13 | const emits = defineEmits(['next', 'emitDeviceType']); |
| 42 | - const loading = ref(false); | ||
| 43 | - const { createMessage } = useMessage(); | ||
| 44 | - const deviceConfigPic = ref(''); | ||
| 45 | const props = defineProps({ | 14 | const props = defineProps({ |
| 46 | ifShowBtn: { type: Boolean, default: true }, | 15 | ifShowBtn: { type: Boolean, default: true }, |
| 47 | }); | 16 | }); |
| @@ -66,32 +35,6 @@ | @@ -66,32 +35,6 @@ | ||
| 66 | disabled: nameStatus, | 35 | disabled: nameStatus, |
| 67 | }, | 36 | }, |
| 68 | }); | 37 | }); |
| 69 | - const customUploadqrcodePic = async ({ file }) => { | ||
| 70 | - if (beforeUploadqrcodePic(file)) { | ||
| 71 | - deviceConfigPic.value = ''; | ||
| 72 | - loading.value = true; | ||
| 73 | - const formData = new FormData(); | ||
| 74 | - formData.append('file', file); | ||
| 75 | - const response = await uploadApi(formData); | ||
| 76 | - if (response.fileStaticUri) { | ||
| 77 | - deviceConfigPic.value = response.fileStaticUri; | ||
| 78 | - loading.value = false; | ||
| 79 | - } | ||
| 80 | - } | ||
| 81 | - }; | ||
| 82 | - const beforeUploadqrcodePic = (file: FileItem) => { | ||
| 83 | - const isJpgOrPng = | ||
| 84 | - file.type === 'image/jpeg' || file.type === 'image/png' || file.type === 'image/jpg'; | ||
| 85 | - if (!isJpgOrPng) { | ||
| 86 | - createMessage.error('只能上传图片文件!'); | ||
| 87 | - } | ||
| 88 | - const isLt2M = (file.size as number) / 1024 / 1024 < 5; | ||
| 89 | - if (!isLt2M) { | ||
| 90 | - createMessage.error('图片大小不能超过5MB!'); | ||
| 91 | - } | ||
| 92 | - return isJpgOrPng && isLt2M; | ||
| 93 | - }; | ||
| 94 | - | ||
| 95 | const setFieldsdefaultRuleChainId = async (id) => { | 38 | const setFieldsdefaultRuleChainId = async (id) => { |
| 96 | await nextTick(); | 39 | await nextTick(); |
| 97 | setFieldsValue({ defaultRuleChainId: id }); | 40 | setFieldsValue({ defaultRuleChainId: id }); |
| @@ -105,20 +48,28 @@ | @@ -105,20 +48,28 @@ | ||
| 105 | } | 48 | } |
| 106 | //回显数据 | 49 | //回显数据 |
| 107 | const setFormData = (v) => { | 50 | const setFormData = (v) => { |
| 108 | - setFieldsValue(v); | ||
| 109 | - deviceConfigPic.value = v.image; | 51 | + if (v.image) { |
| 52 | + setFieldsValue({ | ||
| 53 | + image: [{ uid: buildUUID(), name: 'name', url: v.image } as FileItem], | ||
| 54 | + }); | ||
| 55 | + } | ||
| 56 | + const { image, ...params } = v; | ||
| 57 | + console.log(image); | ||
| 58 | + setFieldsValue({ ...params }); | ||
| 110 | }; | 59 | }; |
| 111 | //获取数据 | 60 | //获取数据 |
| 112 | async function getFormData() { | 61 | async function getFormData() { |
| 113 | const values = await validate(); | 62 | const values = await validate(); |
| 114 | if (!values) return; | 63 | if (!values) return; |
| 115 | - Reflect.set(values, 'image', deviceConfigPic.value); | 64 | + if (Reflect.has(values, 'image')) { |
| 65 | + const file = (values.image || []).at(0) || {}; | ||
| 66 | + values.image = file.url || null; | ||
| 67 | + } | ||
| 116 | return values; | 68 | return values; |
| 117 | } | 69 | } |
| 118 | //清空数据 | 70 | //清空数据 |
| 119 | const resetFormData = () => { | 71 | const resetFormData = () => { |
| 120 | resetFields(); | 72 | resetFields(); |
| 121 | - deviceConfigPic.value = ''; | ||
| 122 | }; | 73 | }; |
| 123 | 74 | ||
| 124 | const editOrAddDeviceTypeStatus = (status: boolean) => { | 75 | const editOrAddDeviceTypeStatus = (status: boolean) => { |