From 84a14c24edf92f7072e50b51ee37143d658ecfd4 Mon Sep 17 00:00:00 2001
From: xiangpei <xiangpei@timesnew.cn>
Date: 星期二, 11 三月 2025 14:28:09 +0800
Subject: [PATCH] 项目库展示总年度投资金额

---
 src/views/projectEngineering/projectLibrary/component/FileDialog.vue |  138 ++++++++++++++++++---------------------------
 1 files changed, 56 insertions(+), 82 deletions(-)

diff --git a/src/views/projectEngineering/projectLibrary/component/FileDialog.vue b/src/views/projectEngineering/projectLibrary/component/FileDialog.vue
index 357d39e..6e923d2 100644
--- a/src/views/projectEngineering/projectLibrary/component/FileDialog.vue
+++ b/src/views/projectEngineering/projectLibrary/component/FileDialog.vue
@@ -17,13 +17,13 @@
       <template slot="default">
         <div v-if="!isImportOrExport" class="dialog-content">
           <el-upload
-            ref="uploadRef"
+            ref="upload"
             class="upload-demo"
-            :action="uploadUrl"
+            :action="upload.url"
             :limit="1"
             :accept="accept"
-            :headers="uploadHeaders"
-            :disabled="uploadIsUploading"
+            :headers="upload.headers"
+            :disabled="upload.isUploading"
             :on-progress="handleFileUploadProgress"
             :on-success="handleFileSuccess"
             :auto-upload="false"
@@ -37,9 +37,9 @@
         </div>
         <div v-else-if="isImportOrExport" class="dialog-content">
           <el-button class="export-button" @click="handleDownloadTargetList">瀵煎嚭鐩爣鍒楄〃鍐呭</el-button>
-          <el-button class="export-button">瀵煎嚭鎵�鏈夊垪琛ㄥ唴瀹�</el-button>
-          <el-button class="export-button">瀵煎嚭鐩爣椤圭洰璇︽儏</el-button>
-          <el-button class="export-button">瀵煎嚭鎵�鏈夐」鐩鎯�</el-button>
+          <el-button class="export-button" @click="handleDownloadAllList">瀵煎嚭鎵�鏈夊垪琛ㄥ唴瀹�</el-button>
+          <el-button class="export-button" @click="handleDownloadDetailList">瀵煎嚭鐩爣椤圭洰璇︽儏</el-button>
+          <el-button class="export-button" @click="handleDownloadAllList">瀵煎嚭鎵�鏈夐」鐩鎯�</el-button>
         </div>
       </template>
       <template slot="footer">
@@ -54,7 +54,7 @@
 </template>
 
 <script>
-import { globalHeaders } from '@/utils/request';
+
 import {getToken} from "@/utils/auth";
 
 export default {
@@ -73,16 +73,31 @@
       default: function () {
         return [];
       }
-    }
+    },
+    dataIdList: {
+      type: Array,
+      default: function () {
+        return [];
+      }
+    },
   },
   data() {
     return {
-      uploadRef: null,
+      queryParams: {},
       targetColumn: [],
       accept: `.zip`,
-      uploadUrl: '/project/import',
-      uploadHeaders: {},
-      uploadIsUploading: false
+      upload:{
+        // 鏄惁鏄剧ず寮瑰嚭灞傦紙鐢ㄦ埛瀵煎叆锛�
+        open: false,
+        // 寮瑰嚭灞傛爣棰橈紙鐢ㄦ埛瀵煎叆锛�
+        title: '',
+        // 鏄惁绂佺敤涓婁紶
+        isUploading: false,
+        // 璁剧疆涓婁紶鐨勮姹傚ご閮�
+        headers: { Authorization: "Bearer " + getToken() },
+        // 涓婁紶鐨勫湴鍧�
+        url: process.env.VUE_APP_BASE_API + '/project/info/import'
+      },
     };
   },
   methods: {
@@ -90,88 +105,47 @@
       console.log("瀛愮粍浠秙ubmit")
     },
     handleFileUploadProgress() {
-      this.uploadIsUploading = true;
+      this.upload.uploadIsUploading = true;
     },
-    handleFileSuccess(response, file) {
-      this.uploadIsUploading = false;
-      if (this.uploadRef) {
-        this.uploadRef.handleRemove(file);
-      }
-      if (response.code === 200) {
-        this.$emit('fileDialogCancel');
-        this.$message({
-          message: response.msg,
-          type: 'success'
-        });
-      } else {
-        this.$message.error(response.msg);
-      }
+    // 鏂囦欢涓婁紶鎴愬姛澶勭悊
+    handleFileSuccess(response, file, fileList) {
+      this.upload.open = false;
+      this.upload.isUploading = false;
+      this.$refs.upload.clearFiles();
+      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "瀵煎叆缁撴灉", { dangerouslyUseHTMLString: true });
     },
     handleDownloadFile() {
-      // fetch(`${process.env.VITE_APP_BASE_API}/project/info/export/template`, {
-      //   method: 'GET',
-      //   headers: self.upload.headers
-      // })
-      //   .then(response => response.blob())
-      //   .then(blob => {
-      //     const url = window.URL.createObjectURL(blob);
-      //     const a = document.createElement('a');
-      //     a.style.display = 'none';
-      //     a.href = url;
-      //     a.download = `椤圭洰鏂囦欢妯℃澘_${new Date().getTime()}.zip`;
-      //     document.body.appendChild(a);
-      //     a.click();
-      //     window.URL.revokeObjectURL(url);
-      //   })
-      //   .catch(error => {
-      //     console.error('鏂囦欢涓嬭浇澶辫触:', error);
-      //   });
-
-      const url = process.env.VUE_APP_BASE_API + '/project/info/export/template';
-      axios.post(url, [], { // 鍙戦�佷竴涓┖鏁扮粍鑰屼笉鏄┖瀵硅薄
-        responseType: 'blob', // 鍛婅瘔axios鏈熸湜鏈嶅姟鍣ㄨ繑鍥炵殑鏄痓lob绫诲瀷
-        headers: {
-          'Content-Type': 'application/json',
-          Authorization: "Bearer " + getToken()
-        }
-      })
-        .then(response => {
-          // 澶勭悊鏂囦欢涓嬭浇
-          const blob = new Blob([response.data], { type: 'application/zip' }); // 鎸囧畾MIME绫诲瀷涓簔ip
-          const url = window.URL.createObjectURL(blob);
-          const a = document.createElement('a');
-          a.style.display = 'none';
-          a.href = url;
-          a.download = `椤圭洰鏂囦欢妯℃澘_${new Date().getTime()}.zip`;
-          document.body.appendChild(a);
-          a.click();
-          document.body.removeChild(a);
-          window.URL.revokeObjectURL(url);
-        })
-        .catch(error => {
-          console.error('There was an error!', error);
-        });
+      this.download('/project/info/export/template', {}, `椤圭洰鏂囦欢妯℃澘_${new Date().getTime()}.zip`)
     },
     submitFileForm() {
-      if (this.uploadRef) {
-        this.uploadRef.submit();
-      }
+        this.$refs.upload.submit();
     },
     closeDialog() {
       this.$emit('fileDialogCancel');
     },
     handleDownloadTargetList() {
-      console.log('瀵煎嚭鐩爣鍒楄〃鍐呭', this.currentColumns);
-      this.targetColumn = this.currentColumns.filter(item => item.visible);
+      this.queryParams.fieldList = this.currentColumns.filter(item => item.visible).map(item =>item.id);
+      this.queryParams.requireFile = false;
+      this.download('project/info/export', {
+          ...this.queryParams
+        }, `椤圭洰搴�${new Date().getTime()}.xlsx`)
+    },
+    handleDownloadAllList() {
+      this.queryParams.fieldList = this.currentColumns;
+      this.queryParams.requireFile = false;
+      this.download('project/info/export', {
+        ...this.queryParams
+      }, `椤圭洰搴�${new Date().getTime()}.xlsx`)
+    },
+    handleDownloadDetailList() {
+      this.queryParams.dataIdList = this.dataIdList
+      this.queryParams.requireFile = true;
+      this.download('project/info/export', {
+        ...this.queryParams
+      }, `椤圭洰搴�${new Date().getTime()}.zip`)
     }
   },
-  mounted() {
-    this.uploadRef = this.$refs.uploadRef;
-  },
-  created() {
 
-    this.isFileDialogVisible = this.fileDialogVisible;
-  }
 };
 </script>
 

--
Gitblit v1.8.0