Sfoglia il codice sorgente

修改批次数据文件批量上传功能

gushoubang 2 mesi fa
parent
commit
e6f957d7dd
1 ha cambiato i file con 35 aggiunte e 9 eliminazioni
  1. 35 9
      src/views/remote/satellite/index.vue

+ 35 - 9
src/views/remote/satellite/index.vue

@@ -297,7 +297,8 @@
         :before-upload="handleBeforeUpload"
         :on-error="handleUploadError"
         :on-success="handleUploadSuccess"
-        :limit="1"
+        :on-change="handleChange"
+        :limit="10"
         accept=".zip"
         :file-list="fileList"
         :show-file-list="true"
@@ -387,6 +388,9 @@ export default {
       fileUploadDiv: false, //文件上传弹窗
       loading2: null,
       uploadFileUrl: process.env.VUE_APP_BASE_API + "/file/uploadSpotZip",
+      uploadingCount: 0, // 正在上传的文件数量
+      uploadingFileSUccess: [], 
+      uploadingFileFail: [], 
       // 部门树选项
       deptOptions: [],
       selectedValues: [],
@@ -421,7 +425,13 @@ export default {
       this.selectedValues = value.district;
       this.queryParams.xzqdm = value.district;
     },
-    handleChange() {},
+      // 文件状态改变时触发
+    handleChange(file, fileList) {
+      this.fileList = fileList;
+      if (file.status === 'ready') {
+        this.uploadingCount++; // 增加上传计数
+      }
+    },
     /** 转换部门数据结构 */
     normalizer(node) {
       if (node.children && !node.children.length) {
@@ -444,18 +454,34 @@ export default {
       return true;
     },
     // 上传失败
-    handleUploadError(err) {
+    handleUploadError(err, file) {
+      this.uploadingCount--;
       this.$modal.msgError("上传文件失败,请重试");
-      this.$modal.closeLoading();
+      this.uploadingFileFail.push(file.name);
+      if (this.uploadingCount === 0) {
+        this.handleUploadClose(res);
+      }
     },
     // 上传成功回调
     handleUploadSuccess(res, file) {
+      this.uploadingCount--;
       console.log("handleUploadSuccess");
-      this.fileList = [];
-      this.fileUploadDiv = false;
-      this.$modal.closeLoading();
-      this.$modal.msgSuccess(res.message);
-      this.getList();
+      console.log(this.uploadingCount);
+      this.uploadingFileSUccess.push(file.name);
+      if (this.uploadingCount === 0) {
+         this.handleUploadClose(res);
+      }
+      
+    },
+    // 上传成功关闭
+    handleUploadClose(res) {
+      if (this.uploadingCount === 0) {
+        this.fileList = [];
+        this.fileUploadDiv = false;
+        this.$modal.closeLoading();
+        this.$modal.msgSuccess(" 执行完成。上传成功:"+this.uploadingFileSUccess +"上传失败:"+this.uploadingFileFail);
+        this.getList();
+      }
     },
     handleDownload(row) {
       const zipfile = row.proxypath + ".zip";