根据base64下载 PDF/EXCEL/doc/ppt/图片等文件(可下载多种格式的文件)
export function downloadExportFile(blob, fileName, fileType) {
let downloadElement = document.createElement("a");
let href = blob;
if (typeof blob == "string") {
downloadElement.target = "_blank";
} else {
href = window.URL.createObjectURL(blob);
}
downloadElement.href = href;
downloadElement.download = fileName + "." + fileType;
document.body.appendChild(downloadElement);
downloadElement.click();
document.body.removeChild(downloadElement);
if (typeof blob != "string") {
window.URL.revokeObjectURL(href);
}
}
根据url下载 PDF/EXCEL/doc/ppt图片等文件(可下载多种格式的文件)
export function fileDownload(url, fileName){
const urlStr = url.replace(/\\/g, "/");
const xhr = new XMLHttpRequest();
xhr.open("GET", urlStr, true);
xhr.responseType = "blob";
xhr.onload = () => {
if (xhr.status === 200) {
saveAs(xhr.response, fileName);
}
};
xhr.send();
}
|