function download(res, fileName) {
const content = res.data.flow;
// const name = decodeURI(res.headers['content-disposition'].split('filename=')[1]);
// const blob = new Blob(content, {type: 'application/vnd.ms-excel;charset=utf-8'}); // 创建一个类文件对象:Blob对象表示一个不可变的、原始数据的类文件对象
const blob = str2Blob(content, 'application/vnd.ms-excel;charset=utf-8'); // 创建一个类文件对象:Blob对象表示一个不可变的、原始数据的类文件对象
const url = window.URL.createObjectURL(blob);// URL.createObjectURL(object)表示生成一个File对象或Blob对象
let dom = document.createElement('a');// 设置一个隐藏的a标签,href为输出流,设置download
dom.style.display = 'none';
dom.href = url;
dom.setAttribute('download', name || fileName);// 指示浏览器下载url,而不是导航到它;因此将提示用户将其保存为本地文件
document.body.appendChild(dom);
dom.click();
}
function str2Blob(str, mime) {
var arr = str.split(',')
bstr = atob(arr[0]), n = bstr.length, u8arr = new Uint8Array(n);
while (n--) {
u8arr[n] = bstr.charCodeAt(n);
}
return new Blob([u8arr], { type: mime });
}
const data = {
"retCode": "000000",
"retMessage": "操作成功",
"data": {
"flow": "UEsDBBQACAgIAHl2K1EAAAAAAAAAAAAAAAALAAAAX3JlbHMvLnJlbHOtksFqwzAMhl/F6N447WCMUbeXMuhtjO4BNFtJTGLL2NqWvf3MLltLChvsKCR9/wfSdj+HSb1RLp6jgXXTgqJo2fnYG3g+PazuQBXB6HDiSAYiw363faIJpW6UwaeiKiIWA4NIute62IECloYTxdrpOAeUWuZeJ7Qj9qQ3bXur808GnDPV0RnIR7cGdcLckxiYJ/3OeXxhHpuKrY2PRL8J5a7zlg5sXwNFWci+mAC97LL5dnFsHzPXTUzpv2VoFoqO3CrVBMriqVwzulkwspzpb0rXj6IDCToU/KJeCOmzH9h9AlBLBwinjHq94wAAAEkCAABQSwMEFAAICAgAeXYrUQAAAAAAAAAAAAAAABMAAABbQ29udGVudF9UeXBlc10ueG1stVPLbsIwEPyVyNcqNvRQVRWBQx/HFqn0A1x7k1j4Ja+h8PddBziUUokKcfJjZmdmV/ZktnG2WkNCE3zDx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AAAMwIAABoAAAAAAAAAAAAAAAAAcgoAAHhsL19yZWxzL3dvcmtib29rLnhtbC5yZWxzUEsBAhQAFAAICAgAeXYrUUha2sPHAwAA6BYAABgAAAAAAAAAAAAAAAAAjgsAAHhsL3dvcmtzaGVldHMvc2hlZXQxLnhtbFBLBQYAAAAACQAJAD8CAACbDwAAAAA="
}
}
window.onload = function() {
download(data, '123.xls');
}
string转blob
最新推荐文章于 2024-06-20 10:33:02 发布