From 6466267722b3a11bc386407a9cf62c9390a9f01e Mon Sep 17 00:00:00 2001 From: ykcory Date: Thu, 28 Dec 2023 06:32:55 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=8E=BB=E9=99=A4=20esportXls=20?= =?UTF-8?q?=E4=B8=AD=20IE=E6=B5=8F=E8=A7=88=E5=99=A8=E7=9A=84=E6=94=AF?= =?UTF-8?q?=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/system/useMethods.ts | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/src/hooks/system/useMethods.ts b/src/hooks/system/useMethods.ts index e46724b..f0569d3 100644 --- a/src/hooks/system/useMethods.ts +++ b/src/hooks/system/useMethods.ts @@ -29,25 +29,21 @@ export function useMethods() { if (!name || typeof name != 'string') { name = '导出文件'; } - let blobOptions = { type: 'application/vnd.ms-excel' }; + const blobOptions = { type: 'application/vnd.ms-excel' }; let fileSuffix = '.xls'; - if (isXlsx === true) { + if (isXlsx) { blobOptions['type'] = XLSX_MIME_TYPE; fileSuffix = XLSX_FILE_SUFFIX; } - if (typeof window.navigator.msSaveBlob !== 'undefined') { - window.navigator.msSaveBlob(new Blob([data], blobOptions), name + fileSuffix); - } else { - let url = window.URL.createObjectURL(new Blob([data], blobOptions)); - let link = document.createElement('a'); - link.style.display = 'none'; - link.href = url; - link.setAttribute('download', name + fileSuffix); - document.body.appendChild(link); - link.click(); - document.body.removeChild(link); //下载完成移除元素 - window.URL.revokeObjectURL(url); //释放掉blob对象 - } + const objectURL = window.URL.createObjectURL(new Blob([data], blobOptions)); + const link = document.createElement('a'); + link.style.display = 'none'; + link.href = objectURL; + link.setAttribute('download', name + fileSuffix); + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); //下载完成移除元素 + window.URL.revokeObjectURL(objectURL); //释放掉blob对象 } /** @@ -60,11 +56,11 @@ export function useMethods() { const isReturn = (fileInfo) => { try { if (fileInfo.code === 201) { - let { + const { message, result: { msg, fileUrl, fileName }, } = fileInfo; - let href = glob.uploadUrl + fileUrl; + const href = glob.uploadUrl + fileUrl; createWarningModal({ title: message, centered: false,