Browse Source

优化upload上传业务

lfz 1 year ago
parent
commit
4205b700e0
1 changed files with 21 additions and 8 deletions
  1. 21 8
      src/views/GATHER/index.vue

+ 21 - 8
src/views/GATHER/index.vue

@@ -376,14 +376,12 @@ export default {
     //导入
     uploadFile(file) {
       let formData = new FormData();
-      formData.append('file', file);
-      formData.append('type', this.uploadForm.type);
-      upload(formData).then(res => {
-        this.$modal.msgSuccess('上传采集附件成功!');
-        this.getList();
-        this.cancel();
-        this.openUpload = false;
-      });
+      formData.append("file", file);
+      formData.append("type", this.uploadForm.type);
+      this.handleFormDataUpload(formData);
+      //upload(formData);
+      this.cancel()
+      this.openUpload = false
     },
     //下载模板
     handleDownload() {
@@ -634,6 +632,21 @@ export default {
         },
         `GATHER_${new Date().getTime()}.xlsx`
       );
+    },
+    /** 上传文件 */
+    handleFormDataUpload(data){
+      upload(data).then((res) => {
+        if(res.code == 200){
+          this.$modal.msgSuccess(res.msg);
+          this.getList();
+        }else {
+          this.$modal.msgError(res.msg);
+        }
+      }).catch(error => {
+          this.$modal.msgError(error);
+          this.cancel()
+          this.openUpload = false
+        });
     }
   }
 };