From 7fdd20c0543670233c03727532ffbf808be54b84 Mon Sep 17 00:00:00 2001
From: RuoYi <yzz_ivy@163.com>
Date: Tue, 28 Feb 2023 15:02:20 +0800
Subject: [PATCH] 优化文件下载出现的异常(I6DLNU)
---
ruoyi-ui/src/utils/request.js | 6 +++---
ruoyi-ui/src/utils/ruoyi.js | 10 ++--------
ruoyi-ui/src/plugins/download.js | 6 +++---
3 files changed, 8 insertions(+), 14 deletions(-)
diff --git a/ruoyi-ui/src/plugins/download.js b/ruoyi-ui/src/plugins/download.js
index cfb7c24..6cbc06c 100644
--- a/ruoyi-ui/src/plugins/download.js
+++ b/ruoyi-ui/src/plugins/download.js
@@ -15,9 +15,9 @@
url: url,
responseType: 'blob',
headers: { 'Authorization': 'Bearer ' + getToken() }
- }).then(async (res) => {
- const isLogin = await blobValidate(res.data);
- if (isLogin) {
+ }).then((res) => {
+ const isBlob = blobValidate(res.data);
+ if (isBlob) {
const blob = new Blob([res.data], { type: 'application/zip' })
this.saveAs(blob, name)
} else {
diff --git a/ruoyi-ui/src/utils/request.js b/ruoyi-ui/src/utils/request.js
index fc39f67..48298ec 100644
--- a/ruoyi-ui/src/utils/request.js
+++ b/ruoyi-ui/src/utils/request.js
@@ -72,7 +72,7 @@
// 获取错误信息
const msg = errorCode[code] || res.data.msg || errorCode['default']
// 二进制数据则直接返回
- if(res.request.responseType === 'blob' || res.request.responseType === 'arraybuffer'){
+ if (res.request.responseType === 'blob' || res.request.responseType === 'arraybuffer') {
return res.data
}
if (code === 401) {
@@ -125,8 +125,8 @@
responseType: 'blob',
...config
}).then(async (data) => {
- const isLogin = await blobValidate(data);
- if (isLogin) {
+ const isBlob = blobValidate(data);
+ if (isBlob) {
const blob = new Blob([data])
saveAs(blob, filename)
} else {
diff --git a/ruoyi-ui/src/utils/ruoyi.js b/ruoyi-ui/src/utils/ruoyi.js
index 243c4c7..44bf9c4 100644
--- a/ruoyi-ui/src/utils/ruoyi.js
+++ b/ruoyi-ui/src/utils/ruoyi.js
@@ -228,12 +228,6 @@
}
// 验证是否为blob格式
-export async function blobValidate(data) {
- try {
- const text = await data.text();
- JSON.parse(text);
- return false;
- } catch (error) {
- return true;
- }
+export function blobValidate(data) {
+ return data.type !== 'application/json'
}
--
Gitblit v1.9.3