Просмотр исходного кода

修复GET下载无权限的问题。1.0.46

杨志杰 3 лет назад
Родитель
Сommit
de7a7f5a7f
3 измененных файлов с 27 добавлено и 13 удалено
  1. 1 1
      package.json
  2. 21 7
      packages/common/DownloadService.js
  3. 5 5
      packages/process/src/ProcessReportResult.vue

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "pc-component-v3",
-  "version": "1.0.45",
+  "version": "1.0.46",
   "description": "",
   "main": "dist/pc-component-v3.js",
   "scripts": {

+ 21 - 7
packages/common/DownloadService.js

@@ -1,22 +1,36 @@
 import Common from './Common.js';
-
+import Notify from './Notify.js';
 /**
  * 报表下载服务
  */
 export default {
 
+
   /**
 	 * GET 方式下载文件
 	 * @param {*} url 
 	 * @param {*} fileName 
 	 */
   downloadFile: function (url, fileName) {
-    var a = document.createElement('a');
-    a.download = fileName;
-    a.href = url;
-    $('body').append(a); // 修复firefox中无法触发click
-    a.click();
-    $(a).remove();
+    fetch(url, {
+      method: 'GET',
+      headers: {
+        'token': localStorage.getItem('#token'),
+      },
+    })
+      .then(res => res.blob())
+      .then(data => {
+        const blobUrl = window.URL.createObjectURL(data);
+
+        var a = document.createElement('a');
+        a.download = fileName;
+        a.href = blobUrl;
+        $('body').append(a); // 修复firefox中无法触发click
+        a.click();
+        $(a).remove();
+      }).catch(err => {
+        Notify.error(err.code, err.responseText, true);
+      });
   },
 
 

+ 5 - 5
packages/process/src/ProcessReportResult.vue

@@ -130,11 +130,11 @@ export default {
              * @author GuoZhiBo 20200410
              */
     reportDownload: function (fileName, reportDefinitionType) {
-      if (reportDefinitionType == 'UReport2') {
-        window.open(Common.getRootPath() + fileName);
-      } else {
-        DownloadService.reportDownload(fileName);
-      }
+      // if (reportDefinitionType == 'UReport2') {
+      //   window.open(Common.getRootPath() + fileName);
+      // } else {
+      DownloadService.reportDownload(fileName);
+      // }
     },
   },
 };