请求地址设置:
export function downloadFileBdpp(params) {
return get({
url: "/xx/xx/download-file",
params,
});
}
base64转文件流
dataURLtoBlob(base64) {
let bstr = atob(base64);
let n = bstr.length;
let u8arr = new Uint8Array(n);
while (n--) {
u8arr[n] = bstr.charCodeAt(n);
}
return new Blob([u8arr], { type: 'application/zip' });
},
调用接口并下载zip文件
downloadFile() {
downloadFileBdpp({
file_id: 文件ID,
}).then((res) => {
let link = document.createElement("a");
link.href = window.URL.createObjectURL(this.dataURLtoBlob(接口返回的base64));
link.download = "附件.zip";
link.click();
window.URL.revokeObjectURL(link.href);
});
},