From 20a4579808cb1803c19007820e7033182341d949 Mon Sep 17 00:00:00 2001 From: ykcory Date: Thu, 28 Dec 2023 06:56:55 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=8E=BB=E9=99=A4=20downloadByData=20?= =?UTF-8?q?=E4=B8=AD=20IE=20=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/file/download.ts | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/utils/file/download.ts b/src/utils/file/download.ts index 168e235..6674ec3 100644 --- a/src/utils/file/download.ts +++ b/src/utils/file/download.ts @@ -36,22 +36,18 @@ export function downloadByBase64(buf: string, filename: string, mime?: string, b export function downloadByData(data: BlobPart, filename: string, mime?: string, bom?: BlobPart) { const blobData = typeof bom !== 'undefined' ? [bom, data] : [data]; const blob = new Blob(blobData, { type: mime || 'application/octet-stream' }); - if (typeof window.navigator.msSaveBlob !== 'undefined') { - window.navigator.msSaveBlob(blob, filename); - } else { - const blobURL = window.URL.createObjectURL(blob); - const tempLink = document.createElement('a'); - tempLink.style.display = 'none'; - tempLink.href = blobURL; - tempLink.setAttribute('download', filename); - if (typeof tempLink.download === 'undefined') { - tempLink.setAttribute('target', '_blank'); - } - document.body.appendChild(tempLink); - tempLink.click(); - document.body.removeChild(tempLink); - window.URL.revokeObjectURL(blobURL); + const blobURL = window.URL.createObjectURL(blob); + const tempLink = document.createElement('a'); + tempLink.style.display = 'none'; + tempLink.href = blobURL; + tempLink.setAttribute('download', filename); + if (typeof tempLink.download === 'undefined') { + tempLink.setAttribute('target', '_blank'); } + document.body.appendChild(tempLink); + tempLink.click(); + document.body.removeChild(tempLink); + window.URL.revokeObjectURL(blobURL); } /**