fix: 去除 downloadByData 中 IE 的支持

pull/960/head
ykcory 2023-12-28 06:56:55 +08:00
parent e6c3d59071
commit 20a4579808
1 changed files with 11 additions and 15 deletions

View File

@ -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) { export function downloadByData(data: BlobPart, filename: string, mime?: string, bom?: BlobPart) {
const blobData = typeof bom !== 'undefined' ? [bom, data] : [data]; const blobData = typeof bom !== 'undefined' ? [bom, data] : [data];
const blob = new Blob(blobData, { type: mime || 'application/octet-stream' }); const blob = new Blob(blobData, { type: mime || 'application/octet-stream' });
if (typeof window.navigator.msSaveBlob !== 'undefined') { const blobURL = window.URL.createObjectURL(blob);
window.navigator.msSaveBlob(blob, filename); const tempLink = document.createElement('a');
} else { tempLink.style.display = 'none';
const blobURL = window.URL.createObjectURL(blob); tempLink.href = blobURL;
const tempLink = document.createElement('a'); tempLink.setAttribute('download', filename);
tempLink.style.display = 'none'; if (typeof tempLink.download === 'undefined') {
tempLink.href = blobURL; tempLink.setAttribute('target', '_blank');
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);
} }
document.body.appendChild(tempLink);
tempLink.click();
document.body.removeChild(tempLink);
window.URL.revokeObjectURL(blobURL);
} }
/** /**