From efff5c8410c9657915eb05615c13c2de7421c61a Mon Sep 17 00:00:00 2001
From: ludc
Date: 星期四, 27 七月 2023 17:38:11 +0800
Subject: [PATCH] 修改文件下载不成功问题

---
 Source/UBCS-WEB/src/api/resource/file.js                                                                   |    1 
 Source/UBCS-WEB/src/views/code/code.vue                                                                    |    4 +-
 Source/UBCS-WEB/src/components/Master/MasterTransfer.vue                                                   |   37 +++++++-----------
 Source/UBCS-WEB/src/views/system/menu.vue                                                                  |   12 ++++++
 Source/UBCS-WEB/src/components/file/main.vue                                                               |   30 ++++++++++++++-
 Source/UBCS-WEB/src/api/GetItem.js                                                                         |    8 ---
 Source/UBCS-WEB/src/components/code-dialog-page/formulaEditor.vue                                          |   11 +++--
 Source/UBCS-WEB/src/store/modules/user.js                                                                  |    1 
 Source/UBCS/ubcs-ops-api/ubcs-resource-api/src/main/java/com/vci/ubcs/resource/utils/FileDownloadUtil.java |    4 +-
 9 files changed, 67 insertions(+), 41 deletions(-)

diff --git a/Source/UBCS-WEB/src/api/GetItem.js b/Source/UBCS-WEB/src/api/GetItem.js
index a1ade96..24c75dc 100644
--- a/Source/UBCS-WEB/src/api/GetItem.js
+++ b/Source/UBCS-WEB/src/api/GetItem.js
@@ -61,13 +61,7 @@
   return request({
     url: 'api/ubcs-code/mdmEngineController/exportCode',
     method: 'excel',
-    responseType: 'json', // 璁剧疆鍝嶅簲绫诲瀷涓篴rraybuffer
-    headers: {
-      'Content-Type': 'application/vnd.ms-excel', // 璁剧疆璇锋眰澶翠负浜岃繘鍒舵祦绫诲瀷
-      // 鍦ㄨ繖閲屽彲浠ヨ缃叾浠栬姹傚ご淇℃伅
-      // 渚嬪锛�
-      // 'Authorization': 'Bearer your-token',
-    },
+    responseType: 'blob', // 璁剧疆鍝嶅簲绫诲瀷涓篵lob
     params:{
       ...data
     }
diff --git a/Source/UBCS-WEB/src/api/resource/file.js b/Source/UBCS-WEB/src/api/resource/file.js
index ef26a06..0af8963 100644
--- a/Source/UBCS-WEB/src/api/resource/file.js
+++ b/Source/UBCS-WEB/src/api/resource/file.js
@@ -41,6 +41,7 @@
     url: '/api/ubcs-resource/fileController/downloadFilesByOids',
     method: 'post',
     headers:{'Content-Type':'application/x-www-form-urlencoded;charset=UTF-8'},
+    responseType: 'blob',
     data: data
 
   })
diff --git a/Source/UBCS-WEB/src/components/Master/MasterTransfer.vue b/Source/UBCS-WEB/src/components/Master/MasterTransfer.vue
index 5af0fcb..fe85e28 100644
--- a/Source/UBCS-WEB/src/components/Master/MasterTransfer.vue
+++ b/Source/UBCS-WEB/src/components/Master/MasterTransfer.vue
@@ -134,30 +134,21 @@
           exportCode({codeClassifyOid:this.codeClassifyOid,'conditionMap[oid]':ids,...exportArr}).then(res=>{
             console.log('res',res)
             const filename = '涓嬭浇.xlsx'; // 涓嬭浇鐨勬枃浠跺悕
-            const blob = new Blob([res.data], { type: 'application/vnd.ms-excel' });
-            const a = document.createElement('a');
-            const url = window.URL.createObjectURL(blob);
-            a.href = url;
-            a.download = filename;
-            a.style.display = 'none';
-            document.body.appendChild(a);
-            a.click();
-            document.body.removeChild(a);
-            window.URL.revokeObjectURL(url);
-
-            // const filename = '涓嬭浇.xlsx'; // 涓嬭浇鐨勬枃浠跺悕
-            // const blob = new Blob([response.data], { type: 'application/vnd.ms-excel' });
-            //
-            // const url = window.URL.createObjectURL(blob);
-            // const link = document.createElement('a');
-            // link.href = url;
-            // link.setAttribute('download', filename);
-            // document.body.appendChild(link);
-            // link.click();
-            // document.body.removeChild(link);
-            // URL.revokeObjectURL(url);
+            let blob = new Blob([res.data], {
+              type: res.data.type + ";charset=utf-8",
+            });
+            let src = window.URL.createObjectURL(blob);
+            if (src) {
+              let link = document.createElement("a");
+              link.style.display = "none";
+              link.href = src;
+              link.setAttribute("download", "鏂囦欢鍚嶅瓧.xls");
+              document.body.appendChild(link);
+              link.click();
+              document.body.removeChild(link); //涓嬭浇瀹屾垚绉婚櫎鍏冪礌
+              window.URL.revokeObjectURL(src); //閲婃斁鎺塨lob瀵硅薄
+            }
           })
-
         }
       };
     },
diff --git a/Source/UBCS-WEB/src/components/code-dialog-page/formulaEditor.vue b/Source/UBCS-WEB/src/components/code-dialog-page/formulaEditor.vue
index ff11590..4f61aaa 100644
--- a/Source/UBCS-WEB/src/components/code-dialog-page/formulaEditor.vue
+++ b/Source/UBCS-WEB/src/components/code-dialog-page/formulaEditor.vue
@@ -649,13 +649,14 @@
     };
   },
   watch: {
-      // 鐩戝惉鐖剁粍浠朵紶鐨勭獥鍙f樉绀洪殣钘忕殑鍊�
-      visible (){
-          this.isShowformulaEdit = this.visible;
-      }
+      // 鐩戝惉鐖剁粍浠朵紶鐨勭獥鍙f樉绀洪殣钘忕殑鍊硷紝浠ュ強鍊肩殑鍥炲~
+      visible() {
+        this.isShowformulaEdit = this.visible;
+        this.formulaContent=this.componentRuleText || '';
+      },
   },
   mounted() {
-    this.formulaContent=this.componentRuleText
+
   },
   methods: {
 
diff --git a/Source/UBCS-WEB/src/components/file/main.vue b/Source/UBCS-WEB/src/components/file/main.vue
index 2391abf..cb4d046 100644
--- a/Source/UBCS-WEB/src/components/file/main.vue
+++ b/Source/UBCS-WEB/src/components/file/main.vue
@@ -65,6 +65,7 @@
 import {mapGetters} from "vuex";
 import {dateFormat} from "@/util/date";
 import {validatenull} from "@/util/validate";
+import func from "@/util/func";
 
 export default {
   props: ["options","visible","ownbizOid"],
@@ -380,16 +381,41 @@
       let data=new FormData();
       if(row && row.oid){
         data.append('fileOids',row.oid)
-        download(data)
+        this.downloadFile(data);
       }else{
         if (this.selectionList.length === 0) {
           this.$message.warning("璇烽�夋嫨鑷冲皯涓�鏉℃暟鎹�");
           return;
         }
         data.append('fileOids',this.oids)
-        download(data);
+        this.downloadFile(data);
       }
     },
+    downloadFile(data){
+      download(data).then(res=>{
+        // console.log(res);
+        if(res){
+          const fileNames = res.headers['content-disposition'].split(";");
+          let characterSet = fileNames[2].split("filename*=")[1];
+          let fileName = decodeURI(fileNames[1].split("filename=")[1],characterSet);
+          // console.log(fileName)
+          let blob = new Blob([res.data], {
+            type: res.data.type + ";charset=utf-8",
+          });
+          let src = window.URL.createObjectURL(blob);
+          if (src) {
+            let link = document.createElement("a");
+            link.style.display = "none";
+            link.href = src;
+            link.setAttribute("download", fileName);
+            document.body.appendChild(link);
+            link.click();
+            document.body.removeChild(link); //涓嬭浇瀹屾垚绉婚櫎鍏冪礌
+            window.URL.revokeObjectURL(src); //閲婃斁鎺塨lob瀵硅薄
+          }
+        }
+      });
+    },
     rowDel(row) {
       this.$confirm("纭畾灏嗛�夋嫨鏂囦欢鍒犻櫎?", {
         confirmButtonText: "纭畾",
diff --git a/Source/UBCS-WEB/src/store/modules/user.js b/Source/UBCS-WEB/src/store/modules/user.js
index fed7910..eb2859a 100644
--- a/Source/UBCS-WEB/src/store/modules/user.js
+++ b/Source/UBCS-WEB/src/store/modules/user.js
@@ -224,6 +224,7 @@
       return new Promise((resolve) => {
         getButtons().then(res => {
           const data = res.data.data;
+          // console.log(data);
           commit('SET_PERMISSION', data);
           resolve();
         })
diff --git a/Source/UBCS-WEB/src/views/code/code.vue b/Source/UBCS-WEB/src/views/code/code.vue
index 43e6077..b7734a3 100644
--- a/Source/UBCS-WEB/src/views/code/code.vue
+++ b/Source/UBCS-WEB/src/views/code/code.vue
@@ -767,6 +767,7 @@
         <formula-editor
           ref="formulaEditor"
           @updateFormulaContent="updateFormulaContent"
+          :componentRuleText="form.getValueClass"
           :visible.sync="formulaEditorParams.formulaEditorSettingBox"
           :thisSceneTableData="formulaEditorParams.thisSceneTableData"
           :systemVariableTableData="formulaEditorParams.systemVariableTableData">
@@ -2571,7 +2572,6 @@
             this.loadlistClassifyLinkAttr();
           }else if(condition === 'value'){
             //鎵撳紑鍏紡缂栬緫妗嗭紝绗簩灞傚祵濂楀璇濇
-            //this.$refs.formulaEditor.isShowformulaEdit = true;
             this.formulaEditorParams.formulaEditorSettingBox = true;
           }else if(condition === 'parentClassifySecOid'){
             this.parentClsfyParams.isShowParentClassifySettingBox = true;
@@ -2768,7 +2768,7 @@
           if(enumCach == null) {
             getDictionary("codeFillSeparator").then(res=>{
               this.enumParam.codeFillSeparator = res.data.data;
-              localStorage.setItem(key,JSON.stringify(res.data.data));
+              localStorage.setItem("codeFillSeparator",JSON.stringify(res.data.data));
             })
           }
         },
diff --git a/Source/UBCS-WEB/src/views/system/menu.vue b/Source/UBCS-WEB/src/views/system/menu.vue
index 710ca16..5382466 100644
--- a/Source/UBCS-WEB/src/views/system/menu.vue
+++ b/Source/UBCS-WEB/src/views/system/menu.vue
@@ -34,6 +34,12 @@
           plain
           @click="cloneMenuButton">浠庡叾浠栬彍鍗曞厠闅嗘寜閽�
         </el-button>
+        <el-button type="info"
+          size="small"
+          icon="el-icon-connection"
+          plain
+          @click="test">test
+        </el-button>
       </template>
       <template slot-scope="scope" slot="menu">
         <el-button
@@ -431,6 +437,7 @@
       },
     },
     computed: {
+      // mapGetters: 杈呭姪鍑芥暟浠呬粎灏唖tore 涓殑 getter 鏄犲皠鍒板眬閮ㄨ绠楀睘鎬�
       ...mapGetters(["userInfo", "permission"]),
       permissionList() {
         return {
@@ -439,6 +446,7 @@
           delBtn: this.vaildData(this.permission.menu_delete, false),
           editBtn: this.vaildData(this.permission.menu_edit, false)
         };
+        
       },
       ids() {
         let ids = [];
@@ -450,6 +458,10 @@
     },
     methods: {
 
+      test(){
+        console.log(this.permission)
+      },
+
       /** 浠庡叾浠栬彍鍗曞厠闅嗘寜閽� */
       cloneMenuButton(){
         if(this.selectionList.length != 1 || this.selectionList[0].category === 2){
diff --git a/Source/UBCS/ubcs-ops-api/ubcs-resource-api/src/main/java/com/vci/ubcs/resource/utils/FileDownloadUtil.java b/Source/UBCS/ubcs-ops-api/ubcs-resource-api/src/main/java/com/vci/ubcs/resource/utils/FileDownloadUtil.java
index 1e047fa..89450ec 100644
--- a/Source/UBCS/ubcs-ops-api/ubcs-resource-api/src/main/java/com/vci/ubcs/resource/utils/FileDownloadUtil.java
+++ b/Source/UBCS/ubcs-ops-api/ubcs-resource-api/src/main/java/com/vci/ubcs/resource/utils/FileDownloadUtil.java
@@ -41,10 +41,10 @@
     public static void downloadFile(HttpServletResponse response, FileObjectBO fileObjectBO,boolean closeInputStream) throws IOException {
         MediaType mediaType = MediaTypeFactory.getMediaType(fileObjectBO.getBucketName() + "." + fileObjectBO.getFileExtension()).orElse(MediaType.APPLICATION_OCTET_STREAM);
         // 璁剧疆寮哄埗涓嬭浇涓嶆墦寮�
-        response.setContentType(mediaType.toString());
+        response.setContentType(mediaType.toString()+";application/force-download;charset=UTF-8");
         try{
             String fileName = URLEncoder.encode(fileObjectBO.getName() + "." + fileObjectBO.getFileExtension(), "UTF8");
-            response.addHeader("Content-Disposition", "attachment; filename="+ fileName+ ";filename*=utf-8''" + fileName);
+            response.addHeader("Content-Disposition", "attachment;filename="+ fileName+ ";filename*=utf-8''");
         }catch(Exception e){
             if(log.isErrorEnabled()){
                 log.error("璁剧疆鏂囦欢鐨勫悕绉板埌鍝嶅簲娴佺殑鏃跺�欏嚭閿�",e);

--
Gitblit v1.9.3