From 612164abde3a9cda59a89e174866807938d4ff7d Mon Sep 17 00:00:00 2001 From: RuoYi Date: Tue, 28 Feb 2023 14:42:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=96=87=E4=BB=B6=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E5=87=BA=E7=8E=B0=E7=9A=84=E5=BC=82=E5=B8=B8(I6DLNU)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/download.js | 18 +++++++++--------- src/utils/request.js | 6 +++--- src/utils/ruoyi.js | 12 +++--------- 3 files changed, 15 insertions(+), 21 deletions(-) diff --git a/src/plugins/download.js b/src/plugins/download.js index 41b2934..33d9a8d 100644 --- a/src/plugins/download.js +++ b/src/plugins/download.js @@ -15,9 +15,9 @@ export default { 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]) this.saveAs(blob, decodeURIComponent(res.headers['download-filename'])) } else { @@ -32,9 +32,9 @@ export default { 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]) this.saveAs(blob, decodeURIComponent(res.headers['download-filename'])) } else { @@ -49,9 +49,9 @@ export default { 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/src/utils/request.js b/src/utils/request.js index 001ec11..adc7491 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -72,7 +72,7 @@ service.interceptors.response.use(res => { // 获取错误信息 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 @@ export function download(url, params, filename, config) { 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/src/utils/ruoyi.js b/src/utils/ruoyi.js index 3ba2868..2714962 100644 --- a/src/utils/ruoyi.js +++ b/src/utils/ruoyi.js @@ -241,12 +241,6 @@ export function getNormalPath(p) { } // 验证是否为blob格式 -export async function blobValidate(data) { - try { - const text = await data.text(); - JSON.parse(text); - return false; - } catch (error) { - return true; - } -} \ No newline at end of file +export function blobValidate(data) { + return data.type !== 'application/json' +}