From 89cca8af078ad110dbe20a81b2850de98b6f78d0 Mon Sep 17 00:00:00 2001
From: 疯狂的狮子li <15040126243@163.com>
Date: 星期二, 03 八月 2021 19:29:15 +0800
Subject: [PATCH] update 重构 统一使用 zip 工具下载

---
 ruoyi-ui/src/utils/zipdownload.js |   54 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 52 insertions(+), 2 deletions(-)

diff --git a/ruoyi-ui/src/utils/zipdownload.js b/ruoyi-ui/src/utils/zipdownload.js
index 52afcc6..aa92603 100644
--- a/ruoyi-ui/src/utils/zipdownload.js
+++ b/ruoyi-ui/src/utils/zipdownload.js
@@ -3,7 +3,9 @@
 
 const mimeMap = {
   xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
-  zip: 'application/zip'
+  zip: 'application/zip',
+  excel: 'application/vnd.ms-excel',
+  oss: 'application/octet-stream'
 }
 
 const baseUrl = process.env.VUE_APP_BASE_API
@@ -18,6 +20,54 @@
     resolveBlob(res, mimeMap.zip)
   })
 }
+
+export function downLoadOss(ossId) {
+  var url = baseUrl + '/system/oss/download/' + ossId
+  axios({
+    method: 'get',
+    url: url,
+    responseType: 'blob',
+    headers: { 'Authorization': 'Bearer ' + getToken() }
+  }).then(res => {
+    resolveBlob(res, mimeMap.oss)
+  })
+}
+
+export function downLoadExcel(url, params) {
+  // get璇锋眰鏄犲皠params鍙傛暟
+  if (params) {
+    let urlparams = url + '?';
+    for (const propName of Object.keys(params)) {
+      const value = params[propName];
+      var part = encodeURIComponent(propName) + "=";
+      if (value !== null && typeof(value) !== "undefined") {
+        if (typeof value === 'object') {
+          for (const key of Object.keys(value)) {
+            let params = propName + '[' + key + ']';
+            var subPart = encodeURIComponent(params) + "=";
+            urlparams += subPart + encodeURIComponent(value[key]) + "&";
+          }
+        } else {
+          urlparams += part + encodeURIComponent(value) + "&";
+        }
+      }
+    }
+    urlparams = urlparams.slice(0, -1);
+    params = {};
+    url = urlparams;
+  }
+  url = baseUrl + url
+  axios({
+    method: 'get',
+    url: url,
+    params: params,
+    responseType: 'blob',
+    headers: { 'Authorization': 'Bearer ' + getToken() }
+  }).then(res => {
+    resolveBlob(res, mimeMap.excel)
+  })
+}
+
 /**
  * 瑙f瀽blob鍝嶅簲鍐呭骞朵笅杞�
  * @param {*} res blob鍝嶅簲鍐呭
@@ -34,7 +84,7 @@
   fileName = fileName.replace(/\"/g, '')
   aLink.style.display = 'none'
   aLink.href = URL.createObjectURL(blob)
-  aLink.setAttribute('download', fileName) // 璁剧疆涓嬭浇鏂囦欢鍚嶇О
+  aLink.setAttribute('download', decodeURI(fileName)) // 璁剧疆涓嬭浇鏂囦欢鍚嶇О
   document.body.appendChild(aLink)
   aLink.click()
   URL.revokeObjectURL(aLink.href);//娓呴櫎寮曠敤

--
Gitblit v1.9.3