<el-button type="primary" v-if="isAuth('population:export')" icon="el-icon-download" size="small"
@click="exportExcel()" :loading="dcLoading" >导出
</el-button>
exportExcel() {
this.$confirm('是否确认导出检索条件所有数据项?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(async () => {
this.dcLoading = true ;
let res = await this.$http({
url: this.$http.adornUrl(`vgs/population/export`),
method: "POST",
params: this.$http.adornParams({
...this.dataForm,
}),
responseType: 'blob'
}).catch((e) => {
});
console.log("res", res);
// 转化为blob对象
let blob = new Blob([res], {
type: "application/vnd.ms-exce",
});
let filename = "人口信息.xlsx";
// 将blob对象转为一个URL
var blobURL = window.URL.createObjectURL(blob);
// 创建一个a标签
var tempLink = document.createElement("a");
// 隐藏a标签
tempLink.style.display = "none";
// 设置a标签的href属性为blob对象转化的URL
tempLink.href = blobURL;
// 给a标签添加下载属性
tempLink.setAttribute("download", filename);
if (typeof tempLink.download === "undefined") {
tempLink.setAttribute("target", "_blank");
}
// 将a标签添加到body当中
document.body.appendChild(tempLink);
// 启动下载
tempLink.click();
// 下载完毕删除a标签
document.body.removeChild(tempLink);
window.URL.revokeObjectURL(blobURL);
this.dcLoading = false ;
this.$message({
message: "导出成功~",
type: "success",
});
})
},