Sfoglia il codice sorgente

优化文件下载出现的异常(I6DLNU)

RuoYi 3 anni fa
parent
commit
7fdd20c054

+ 3 - 3
ruoyi-ui/src/plugins/download.js

@@ -15,9 +15,9 @@ export default {
15
       url: url,
15
       url: url,
16
       responseType: 'blob',
16
       responseType: 'blob',
17
       headers: { 'Authorization': 'Bearer ' + getToken() }
17
       headers: { 'Authorization': 'Bearer ' + getToken() }
18
-    }).then(async (res) => {
19
-      const isLogin = await blobValidate(res.data);
20
-      if (isLogin) {
18
+    }).then((res) => {
19
+      const isBlob = blobValidate(res.data);
20
+      if (isBlob) {
21
         const blob = new Blob([res.data], { type: 'application/zip' })
21
         const blob = new Blob([res.data], { type: 'application/zip' })
22
         this.saveAs(blob, name)
22
         this.saveAs(blob, name)
23
       } else {
23
       } else {

+ 3 - 3
ruoyi-ui/src/utils/request.js

@@ -72,7 +72,7 @@ service.interceptors.response.use(res => {
72
     // 获取错误信息
72
     // 获取错误信息
73
     const msg = errorCode[code] || res.data.msg || errorCode['default']
73
     const msg = errorCode[code] || res.data.msg || errorCode['default']
74
     // 二进制数据则直接返回
74
     // 二进制数据则直接返回
75
-    if(res.request.responseType ===  'blob' || res.request.responseType ===  'arraybuffer'){
75
+    if (res.request.responseType ===  'blob' || res.request.responseType ===  'arraybuffer') {
76
       return res.data
76
       return res.data
77
     }
77
     }
78
     if (code === 401) {
78
     if (code === 401) {
@@ -125,8 +125,8 @@ export function download(url, params, filename, config) {
125
     responseType: 'blob',
125
     responseType: 'blob',
126
     ...config
126
     ...config
127
   }).then(async (data) => {
127
   }).then(async (data) => {
128
-    const isLogin = await blobValidate(data);
129
-    if (isLogin) {
128
+    const isBlob = blobValidate(data);
129
+    if (isBlob) {
130
       const blob = new Blob([data])
130
       const blob = new Blob([data])
131
       saveAs(blob, filename)
131
       saveAs(blob, filename)
132
     } else {
132
     } else {

+ 2 - 8
ruoyi-ui/src/utils/ruoyi.js

@@ -228,12 +228,6 @@ export function tansParams(params) {
228
 }
228
 }
229
 
229
 
230
 // 验证是否为blob格式
230
 // 验证是否为blob格式
231
-export async function blobValidate(data) {
232
-  try {
233
-    const text = await data.text();
234
-    JSON.parse(text);
235
-    return false;
236
-  } catch (error) {
237
-    return true;
238
-  }
231
+export function blobValidate(data) {
232
+  return data.type !== 'application/json'
239
 }
233
 }