Эх сурвалжийг харах

文件删除与同一文件只能上传一次的bug

lkk 5 сар өмнө
parent
commit
36fa5d7302

+ 62 - 6
src/views/farmlandProtection/components/exportFile.vue

@@ -4,7 +4,7 @@
       <div class="miniBtn">
         <!-- <el-button plain size="mini">导入监测数据包</el-button> -->
         <!-- <el-button plain size="mini">导入核查</el-button> -->
-        <el-upload
+        <!-- <el-upload
           class="upload-demo"
           :on-change="handleChange"
           :auto-upload="false"
@@ -12,6 +12,20 @@
           :file-list="fileList"
           :limit="1"
           accept=".zip"
+          :action="uploadFileUrl"
+        > -->
+        <el-upload
+          ref="fileUploadBtn"
+          class="upload-demo"
+          :action="uploadFileUrl"
+          :before-upload="handleBeforeUpload"
+          :on-error="handleUploadError"
+          :on-success="handleUploadSuccess"
+          :limit="1"
+          accept=".zip"
+          :file-list="fileList"
+          :show-file-list="false"
+          :data="additionalData"
         >
           <el-button plain size="mini">导入监测数据包</el-button>
         </el-upload>
@@ -95,9 +109,19 @@ export default {
       pageSize: 5,
       total: 0,
       showExp: true,
+      // uploadFileUrl: window.axiosURI + "/file/upload", // 上传文件服务器地址
+      uploadFileUrl: window.axiosURI + "/file/upload/geom/v1", // 上传文件服务器地址
       fileList: [], //文件
       fileDataID: "", //存储上传文件获取到的id
       tableData: [],
+      additionalData: {
+        // file: null,
+        fromType: 2,
+        fromRoute: this.$route.path,
+        storeStats: "",
+        followup: 1,
+      },
+      loading:null,
     };
   },
   computed: {},
@@ -125,15 +149,47 @@ export default {
         this.total = res.total;
       });
     },
+    handleBeforeUpload(file) {
+      // this.additionalData.file = file;
+      // this.$modal.loading("正在上传文件,请稍候...");
+     this.loading = this.$loading({
+          lock: true,
+          text: '正在上传中...',
+          spinner: 'el-icon-loading',
+          background: 'rgba(0, 0, 0, 0.7)'
+        });
+      return true;
+    },
+    // 上传失败
+    handleUploadError(err) {
+      this.$message.error("上传文件失败,请重试");
+    }, 
+    // 上传成功回调
+    handleUploadSuccess(res, file) {
+      if (res.success) {
+        this.$message({
+          message: "导入文件成功!",
+          type: "success",
+        });
+        this.loading.close();
+        this.fileDataID = res.data.id;
+        this.init();
+        this.$refs.fileUploadBtn.clearFiles(); //上传成功之后清除历史记录
+      }else{
+        this.loading.close();
+        this.$refs.fileUploadBtn.clearFiles(); //上传成功之后清除历史记录
+      }
+    },
     //上传文件
     handleChange(file, fileList) {
       this.fileDataID = "";
-      this.fileList = [];
-      if (fileList.length > 0) {
-        this.fileList = [fileList[fileList.length - 1]]; //这一步,是展示最后一次选择文件
-      }
+      // this.fileList = [];
+      // if (fileList.length > 0) {
+      //   this.fileList = [fileList[fileList.length - 1]]; //这一步,是展示最后一次选择文件
+      // }
       const formdata = new FormData();
-      formdata.append("file", file.raw);
+      // formdata.append("file", file.raw);
+      formdata.append("file", file.file);
       formdata.append("fromType", 2);
       formdata.append("fromRoute", this.$route.path);
       formdata.append("storeStats", "");

+ 1 - 1
src/views/farmlandProtection/jctb/index.vue

@@ -125,7 +125,7 @@
     <el-dialog
       title="选择图斑"
       :visible.sync="dialogVisible"
-      width="45%"
+                                                                                                                                                                                 width="45%"
       :before-close="handleClose"
       :modal-append-to-body="false"
       :close-on-click-modal="false"