From e0ae878a6dbec50465b99f992fd259d1543e34ad Mon Sep 17 00:00:00 2001 From: Xu Zhimeng Date: Tue, 14 Nov 2023 11:12:31 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E6=97=B6=E4=B9=B1=E7=A0=81=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/file.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/utils/file.js b/src/utils/file.js index 6df6fdd..4366430 100644 --- a/src/utils/file.js +++ b/src/utils/file.js @@ -104,7 +104,7 @@ export function getFileNameByHeaderContentDisposition(contentDisposition) { return fileName } -export const fetchAndDownload = async (url, data, method='post') => { +export const fetchAndDownload = async (url, data, method = 'post') => { const apiBaseUrl = window._CONFIG['domianURL'] || '/jeecg-boot' const sign = signMd5Utils.getSign(url, data) @@ -113,7 +113,7 @@ export const fetchAndDownload = async (url, data, method='post') => { method, url, data, - + responseType: 'blob', headers: { 'X-Sign': sign, 'X-TIMESTAMP': signMd5Utils.getTimestamp(), @@ -121,25 +121,24 @@ export const fetchAndDownload = async (url, data, method='post') => { 'tenant-id': Vue.ls.get(TENANT_ID) } } - if(method == 'get') { + if (method == 'get') { config.params = data } const response = await Axios(config) const { status, headers, data: responseData } = response if (status == 200) { - if (typeof responseData == 'object') { - const { message: msg } = responseData + if (responseData.type == 'application/json') { + const res = await readFile(responseData) + const parsed = JSON.parse(res) + const { message: msg } = parsed message.error(msg) throw new Error(msg) } else { const disposition = headers['content-disposition'] const fileName = getFileNameByHeaderContentDisposition(disposition) - if (typeof responseData == 'string') { - const blob = new Blob([responseData], { type: headers['content-type'] }) - saveAs(blob, fileName) - return fileName - } + saveAs(responseData, fileName) + return fileName } } else { message.error('This operation fails. Contact your system administrator')