exportBakingRecords(this.Idarr).then((res) => {
const fileName = res.headers["content-disposition"].substring(
res.headers["content-disposition"].indexOf("=") + 1,
res.headers["content-disposition"].length
);
const blob = new Blob([res.data], { type: "application/zip" });
//这里的type要和后端约定一致
const downloadElement = document.createElement("a");
const href = window.URL.createObjectURL(blob);
//后台再header中传文件名
downloadElement.href = href;
downloadElement.download = window.decodeURI(fileName);
document.body.appendChild(downloadElement);
downloadElement.click();
document.body.removeChild(downloadElement); // 下载完成移除元素
window.URL.revokeObjectURL(href); // 释放掉blob对象
});
请求头中要规定流类型
// 批量导出
export const exportBakingRecords = (data) => {
return request({
url: "/api/blade-pcm/baking-records/exportBakingRecords",
// url: "/center/baking-records/exportBakingRecords",
method: "post",
responseType: "blob", // 添加响应类型
data,
});
};