通过在url中拼接参数 baseURL+apiName+token+this.listQuery里的参数+ids
listQuery = {
page: 1,
limit: 30,
count: 0,
};
创建a标签进行下载
// 导出所有
handleExportList() {
this.$confirm("导出数据较大,请耐心等待1~3分钟", "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
}).then(() => {
//去除page=1,limit=30的限制,导出所有
const setParams = Object.keys(this.listQuery)
.map((key: string) => {
if (key != "page" && key != "limit") { return `&${key}=${(this.listQuery as any)[key]}`; }
})
.join("");
const apiName = "/device/assetsCheckOrder/exportExcel";//导出接口
const link = document.createElement("a");
link.style.display = "none";
link.href = `${baseURL}${apiName}?token=${getToken()}${setParams}`;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
});
}
//导出当前页勾选
get ids() {//先计算勾选的ids
return this.multipleSelection.map(it => {
return it.id;
});
}
async handleExport() {
this.exportLoading = true;
setTimeout(() => {
const setParams = Object.keys(this.listQuery)
.map((key: string) => {
return `&${key}=${(this.listQuery as any)[key]}`;
})
.join("");
const apiName = "/device/warrantyContract/warrantyContractExport";
const link = document.createElement("a");
link.style.display = "none";
link.href = `${baseURL}${apiName}?token=${getToken()}${setParams}&ids=${this.ids}`;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
this.exportLoading = false;
}, 1000);
}