Forráskód Böngészése

feat(api): upload

gemercheung 3 éve
szülő
commit
560facb4ce

+ 5 - 2
src/components/Upload/src/UploadModal.vue

@@ -174,7 +174,7 @@
       // }
 
       async function uploadApiByItem(item: FileItem) {
-        const { api } = props;
+        const { api, afterFetch } = props;
         if (!api || !isFunction(api)) {
           return warn('upload api must exist and be a function');
         }
@@ -197,6 +197,10 @@
           item.status = UploadResultStatus.SUCCESS;
           item.responseData = data;
 
+          if (afterFetch && isFunction(afterFetch)) {
+            item.responseData = (await afterFetch(data)) || data;
+          }
+
           return {
             success: true,
             error: null,
@@ -227,7 +231,6 @@
               return uploadApiByItem(item);
             }),
           );
-          debugger;
 
           isUploadingRef.value = false;
           // 生产环境:抛出错误

+ 4 - 0
src/components/Upload/src/props.ts

@@ -42,6 +42,10 @@ export const basicProps = {
     type: String as PropType<string>,
     default: null,
   },
+  afterFetch: {
+    type: Function as PropType<Fn>,
+    default: null,
+  },
 };
 
 export const uploadContainerProps = {

+ 5 - 2
src/views/dashboard/advertisement/schemas.ts

@@ -44,8 +44,11 @@ export const schemas: FormSchema[] = [
     componentProps: {
       api: uploadApi,
       maxNumber: 1,
-      change(data) {
-        console.log('data', data);
+      afterFetch(data) {
+        // console.log('afterFetch1', data);
+        // const covertData = [data.message];
+        Reflect.set(data, 'url', data.message);
+        // console.log('afterFetch2', data);
         return data;
       },
     },