//点击数据下载按钮的回调
async downloadFun() {
console.log(this.$route.query);
let obj = {};
obj.companyCode = this.$route.query.companyCode;
obj.skuType = this.$route.query.skuType;
obj.startDate = this.$route.query.startDate;
obj.endDate = this.$route.query.endDate;
let res = await outStorageDetailDownload(obj);
if (res.size !== 0) {
this.downloadExcel(res, "出库量明细表");
} else {
this.$message({
message: "暂无数据可下载",
type: "warning",
});
}
},
// 封装的下载方法
downloadExcel(res, filename) {
const blob = new Blob([res], {
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", // 对应下载之后文件的mime类型
});
const objectUrl = window.URL.createObjectURL(blob); // 生成一个url
const aLink = document.createElement("a");
aLink.style.display = "none";
aLink.href = objectUrl;
aLink.setAttribute("download", filename);
document.body.appendChild(aLink);
aLink.click();
document.body.removeChild(aLink);
},
Excel下载
于 2023-07-10 17:28:32 首次发布