Browse Source

修改上传配置

tongshangming 5 months ago
parent
commit
215470fda2
3 changed files with 23 additions and 32 deletions
  1. 16 10
      src/config/uploadConfig.ts
  2. 5 9
      src/views/extension/imageUpload/index.vue
  3. 2 13
      src/views/form/Basic.vue

+ 16 - 10
src/config/uploadConfig.ts

@@ -19,15 +19,21 @@ export default {
       })
   },
   transformData: (data: string) => {
-    // 将逗号分隔的字符串转换为数组
-    return data
-      .split(',')
-      .filter((item: string) => item)
-      .map(x => ({
-        key: uuid(),
-        url: x,
-        status: 'success',
-        name: x.split('/').pop()
-      }))
+    if (typeof data === 'string') {
+      // 将逗号分隔的字符串转换为数组
+      return data
+        .split(',')
+        .filter((item: string) => item)
+        .map(x => ({
+          key: uuid(),
+          url: x,
+          status: 'success',
+          name: x.split('/').pop()
+        }))
+    } else if (Array.isArray(data)) {
+      return data
+    } else {
+      return []
+    }
   }
 }

+ 5 - 9
src/views/extension/imageUpload/index.vue

@@ -13,17 +13,13 @@ const onRemove = (file: any) => {
   console.log(file)
 }
 
-const uploadFunction = (item: any) => {
-  return new Promise(() => {
-    item.status = 'uploading'
-    item.progress = 50
+const uploadFunction = () => {
+  return new Promise(resolve => {
     setTimeout(() => {
-      item.progress = 90
+      resolve({
+        data: 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png'
+      })
     }, 1000)
-    setTimeout(() => {
-      item.progress = 100
-      item.status = Math.random() > 0.5 ? 'success' : 'danger'
-    }, 1500)
   })
 }
 

+ 2 - 13
src/views/form/Basic.vue

@@ -242,7 +242,7 @@ const formConfig = reactive<BasicForm>({
     },
     {
       label: '图片',
-      value: [],
+      value: '',
       name: 'image',
       type: 'image-upload',
       slots: [
@@ -254,18 +254,7 @@ const formConfig = reactive<BasicForm>({
     },
     {
       label: '文件',
-      value: 'erp/prod/temp/1702626281947.png',
-      name: 'picture',
-      type: 'image-upload',
-      props: {
-        limit: 9,
-        multiple: true
-      }
-    },
-    {
-      label: '文件',
-      value:
-        '[{"name":"4.png","url":"erp/prod/temp/1702626281947.png"},{"name":"background_image3.png","url":"erp/prod/temp/1702626287319.png"}]',
+      value: 'erp/prod/temp/1702626281947.png,erp/prod/temp/1702626287319.png',
       name: 'file',
       type: 'file-upload',
       slots: [