handleExport() {
this.$confirm('确认导出文件?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
const loading = this.$loading({
lock: true,
text: '正在下载',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.7)'
});
getExportExcel({ id: this.id, year: this.year }).then(res => {
const blob = new Blob([res], { type: res.type });
// 检查this.year是否为null
const yearPart = this.year ? `${this.year}` : ``;
// 构建文件名
const fileName = `${this.staffName}${yearPart}培训记录.xlsx`;
// 使用隐藏的a标签来触发下载
const downloadLink = document.createElement('a');
downloadLink.href = window.URL.createObjectURL(blob);
downloadLink.download = fileName;
downloadLink.style.display = 'none';
document.body.appendChild(downloadLink);
downloadLink.click();
// 清理
window.URL.revokeObjectURL(downloadLink.href);
document.body.removeChild(downloadLink);
loading.close();
});
}).catch(() => {
loading.close();
this.$message.error('下载请求错误');
});
},
06-27
2168
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
05-12
1万+
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
10-11
1456
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)