bitchDownload(){
const rows = this.checkData;
if (rows.length == 0) {
Message({
message: LangHelper.getMessage("order.SingleRmInfo.lang_130") as string,
type: "error",
});
return;
}else{
const ids = [];
for (let i = 0; i < rows.length; i++) {
ids.push((rows[i] as any).id);
}
const params: any = {
hotelId: UserModule.GetHotelId,
ids: ids,
};
axios.post(`${getter.vikingUrl()}/regform/downloadZip`, params, {
headers: {
"auth-type": "auth-token",
"application-token": UserModule.GetToken,
},
responseType: "blob",
})
.then((res: any) => {
let blob = new Blob([res.data], {type: res.data.type})
let url = window.URL.createObjectURL(blob);
const link = document.createElement("a");
let temp = res.headers["content-disposition"].split(";")[1].split("filename=")[1];
const fileName = decodeURIComponent(temp);
console.log('fileName_',fileName)
link.style.display = "none";
link.href = url;
link.setAttribute("download", fileName + "");
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
window.URL.revokeObjectURL(url);
})
.catch((err: any) => {});
}
}
如果前端无法获取后端给的文件名,可能是后端没有暴露出来,前端只能从接口看到,却取不到。
那么请后端参考下面的文章:
https://blog.csdn.net/PGguoqi/article/details/106824957