Commit f8df3dfca0f61c2c2ac14866c4cc2115a5c55d31
1 parent
c73313b4
fix: DEFECT-1644 所有可以上传图片的都需要预览个删除按钮
Showing
2 changed files
with
44 additions
and
62 deletions
@@ -8,24 +8,6 @@ | @@ -8,24 +8,6 @@ | ||
8 | @ok="handleSubmit" | 8 | @ok="handleSubmit" |
9 | > | 9 | > |
10 | <BasicForm @register="registerForm"> | 10 | <BasicForm @register="registerForm"> |
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 | <template #videoPlatformIdSlot="{ model, field }"> | 11 | <template #videoPlatformIdSlot="{ model, field }"> |
30 | <a-select | 12 | <a-select |
31 | placeholder="请选择流媒体配置" | 13 | placeholder="请选择流媒体配置" |
@@ -52,23 +34,20 @@ | @@ -52,23 +34,20 @@ | ||
52 | import { formSchema } from './config.data'; | 34 | import { formSchema } from './config.data'; |
53 | import { BasicDrawer, useDrawerInner } from '/@/components/Drawer'; | 35 | import { BasicDrawer, useDrawerInner } from '/@/components/Drawer'; |
54 | import { createOrEditCameraManage } from '/@/api/camera/cameraManager'; | 36 | import { createOrEditCameraManage } from '/@/api/camera/cameraManager'; |
55 | - import { message, Upload } from 'ant-design-vue'; | ||
56 | import { useMessage } from '/@/hooks/web/useMessage'; | 37 | import { useMessage } from '/@/hooks/web/useMessage'; |
57 | - import { PlusOutlined, LoadingOutlined } from '@ant-design/icons-vue'; | ||
58 | - import { upload } from '/@/api/oss/ossFileUploader'; | ||
59 | - import { FileItem } from '/@/components/Upload/src/typing'; | 38 | + import { PlusOutlined } from '@ant-design/icons-vue'; |
60 | import { getStreamingMediaList } from '/@/api/camera/cameraManager'; | 39 | import { getStreamingMediaList } from '/@/api/camera/cameraManager'; |
61 | import SteramingDrawer from '../streaming/SteramingDrawer.vue'; | 40 | import SteramingDrawer from '../streaming/SteramingDrawer.vue'; |
62 | import { useDrawer } from '/@/components/Drawer'; | 41 | import { useDrawer } from '/@/components/Drawer'; |
42 | + import { FileItem } from '/@/components/Form/src/components/ApiUpload.vue'; | ||
43 | + import { buildUUID } from '/@/utils/uuid'; | ||
63 | 44 | ||
64 | export default defineComponent({ | 45 | export default defineComponent({ |
65 | name: 'ContactDrawer', | 46 | name: 'ContactDrawer', |
66 | components: { | 47 | components: { |
67 | BasicDrawer, | 48 | BasicDrawer, |
68 | BasicForm, | 49 | BasicForm, |
69 | - Upload, | ||
70 | PlusOutlined, | 50 | PlusOutlined, |
71 | - LoadingOutlined, | ||
72 | SteramingDrawer, | 51 | SteramingDrawer, |
73 | VNodes: (_, { attrs }) => { | 52 | VNodes: (_, { attrs }) => { |
74 | return attrs.vnodes; | 53 | return attrs.vnodes; |
@@ -118,42 +97,19 @@ | @@ -118,42 +97,19 @@ | ||
118 | if (unref(isUpdate)) { | 97 | if (unref(isUpdate)) { |
119 | await nextTick(); | 98 | await nextTick(); |
120 | editId.value = data.record.id; | 99 | editId.value = data.record.id; |
121 | - tenantLogo.value = data.record?.avatar; | ||
122 | - await setFieldsValue(data.record); | 100 | + if (data.record.avatar) { |
101 | + setFieldsValue({ | ||
102 | + avatar: [{ uid: buildUUID(), name: 'name', url: data.record.avatar } as FileItem], | ||
103 | + }); | ||
104 | + } | ||
105 | + const { avatar, ...params } = data.record; | ||
106 | + console.log(avatar); | ||
107 | + await setFieldsValue({ ...params }); | ||
123 | } else { | 108 | } else { |
124 | - tenantLogo.value = ''; | ||
125 | editId.value = ''; | 109 | editId.value = ''; |
126 | } | 110 | } |
127 | }); | 111 | }); |
128 | 112 | ||
129 | - const tenantLogo = ref(''); | ||
130 | - | ||
131 | - async function customUpload({ file }) { | ||
132 | - if (beforeUpload(file)) { | ||
133 | - tenantLogo.value = ''; | ||
134 | - loading.value = true; | ||
135 | - const formData = new FormData(); | ||
136 | - formData.append('file', file); | ||
137 | - const response = await upload(formData); | ||
138 | - if (response.fileStaticUri) { | ||
139 | - tenantLogo.value = response.fileStaticUri; | ||
140 | - loading.value = false; | ||
141 | - } | ||
142 | - } | ||
143 | - } | ||
144 | - | ||
145 | - const beforeUpload = (file: FileItem) => { | ||
146 | - const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png'; | ||
147 | - if (!isJpgOrPng) { | ||
148 | - message.error('只能上传图片文件!'); | ||
149 | - } | ||
150 | - const isLt2M = (file.size as number) / 1024 / 1024 < 5; | ||
151 | - if (!isLt2M) { | ||
152 | - message.error('图片大小不能超过5MB!'); | ||
153 | - } | ||
154 | - return isJpgOrPng && isLt2M; | ||
155 | - }; | ||
156 | - | ||
157 | const getTitle = computed(() => (!unref(isUpdate) ? '新增视频配置' : '编辑视频配置')); | 113 | const getTitle = computed(() => (!unref(isUpdate) ? '新增视频配置' : '编辑视频配置')); |
158 | 114 | ||
159 | async function handleSubmit() { | 115 | async function handleSubmit() { |
@@ -162,8 +118,9 @@ | @@ -162,8 +118,9 @@ | ||
162 | const { createMessage } = useMessage(); | 118 | const { createMessage } = useMessage(); |
163 | const values = await validate(); | 119 | const values = await validate(); |
164 | if (!values) return; | 120 | if (!values) return; |
165 | - if (tenantLogo.value !== '') { | ||
166 | - values.avatar = tenantLogo.value; | 121 | + if (Reflect.has(values, 'avatar')) { |
122 | + const file = (values.avatar || []).at(0) || {}; | ||
123 | + values.avatar = file.url || null; | ||
167 | } | 124 | } |
168 | if (editId.value !== '') { | 125 | if (editId.value !== '') { |
169 | values.id = editId.value; | 126 | values.id = editId.value; |
@@ -188,9 +145,6 @@ | @@ -188,9 +145,6 @@ | ||
188 | registerDrawer, | 145 | registerDrawer, |
189 | registerForm, | 146 | registerForm, |
190 | handleSubmit, | 147 | handleSubmit, |
191 | - customUpload, | ||
192 | - beforeUpload, | ||
193 | - tenantLogo, | ||
194 | loading, | 148 | loading, |
195 | streamConfigOptions, | 149 | streamConfigOptions, |
196 | registerSteramingDrawer, | 150 | registerSteramingDrawer, |
@@ -5,6 +5,9 @@ import { CameraVideoUrl, CameraMaxLength } from '/@/utils/rules'; | @@ -5,6 +5,9 @@ import { CameraVideoUrl, CameraMaxLength } from '/@/utils/rules'; | ||
5 | import { h } from 'vue'; | 5 | import { h } from 'vue'; |
6 | import SnHelpMessage from './SnHelpMessage.vue'; | 6 | import SnHelpMessage from './SnHelpMessage.vue'; |
7 | import { OrgTreeSelect } from '../../common/OrgTreeSelect'; | 7 | import { OrgTreeSelect } from '../../common/OrgTreeSelect'; |
8 | +import { FileItem } from '/@/components/Form/src/components/ApiUpload.vue'; | ||
9 | +import { createImgPreview } from '/@/components/Preview'; | ||
10 | +import { uploadThumbnail } from '/@/api/configuration/center/configurationCenter'; | ||
8 | 11 | ||
9 | useComponentRegister('OrgTreeSelect', OrgTreeSelect); | 12 | useComponentRegister('OrgTreeSelect', OrgTreeSelect); |
10 | 13 | ||
@@ -102,8 +105,33 @@ export const formSchema: QFormSchema[] = [ | @@ -102,8 +105,33 @@ export const formSchema: QFormSchema[] = [ | ||
102 | { | 105 | { |
103 | field: 'avatar', | 106 | field: 'avatar', |
104 | label: '视频封面', | 107 | label: '视频封面', |
105 | - slot: 'iconSelect', | ||
106 | - component: 'Input', | 108 | + component: 'ApiUpload', |
109 | + changeEvent: 'update:fileList', | ||
110 | + valueField: 'fileList', | ||
111 | + componentProps: () => { | ||
112 | + return { | ||
113 | + listType: 'picture-card', | ||
114 | + maxFileLimit: 1, | ||
115 | + accept: '.png,.jpg,.jpeg,.gif', | ||
116 | + api: async (file: File) => { | ||
117 | + try { | ||
118 | + const formData = new FormData(); | ||
119 | + formData.set('file', file); | ||
120 | + const { fileStaticUri, fileName } = await uploadThumbnail(formData); | ||
121 | + return { | ||
122 | + uid: fileStaticUri, | ||
123 | + name: fileName, | ||
124 | + url: fileStaticUri, | ||
125 | + } as FileItem; | ||
126 | + } catch (error) { | ||
127 | + return {}; | ||
128 | + } | ||
129 | + }, | ||
130 | + onPreview: (fileList: FileItem) => { | ||
131 | + createImgPreview({ imageList: [fileList.url!] }); | ||
132 | + }, | ||
133 | + }; | ||
134 | + }, | ||
107 | }, | 135 | }, |
108 | { | 136 | { |
109 | field: 'name', | 137 | field: 'name', |