1.api
export(data) {
return request({
url: `${baseURL}/benchmark/export`,
method: 'post',
responseType: 'blob',
data
});
},
2.导出方法
batchExport() {
this.lding = true;
const ids = this.selArr.map(e => e.id);
const names = this.selArr.map(e => e.fileNum + '文件');
const urls = [];
ids.forEach(e => {
urls.push(export({ids: [e]}));
})
Promise.all(urls).then((res = []) => {
res.forEach((e,index) => {
this.fileExport(e, names[index]);
});
this.loading = false;
}).catch(() => {
this.loading = false;
})
}
fileExport(res, name, ept='.xlsx') {
const url = window.URL.createObjectURL(new Blob([res]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', name+ept);
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
window.URL.revokeObjectURL(url);
}