<el-button type="success" @click="exportExcel">导出</el-button>
//确认导出
exportExcel() {
if(this.total>60000){
this.$alert("导出数据超出Excel的限制,请缩小查询范围");
return;
}
this.$confirm('当前待导出的数据行数过多,请确认是否需要导出?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.$message({
type: 'success',
message: '已将导出请求传导到后台,请耐心等待!'
});
this.downloadData();
}).catch(() => {
this.$message({
type: 'info',
message: '已取消导出'
});
});
},
//导出接口请求
downloadData() {
this.$axios.patch("api/ExportExcel", {
platformName: this.searchForm.platformId,
queryKey: this.searchForm.queryKey,
sdkName: this.searchForm.sdkId,
province:this.searchForm.province,
queryPhone:this.searchForm.queryPhone
},{headers: {'Content-Type': 'application/json'},responseType:'blob'}).then(res=> {
this.download(res.data)
}).catch(error=>{
alert(error);
});
},
//前端数据处理
download(data) {
if(!data){
return
}
var blob = new Blob([data], {type: 'application/vnd.ms-excel'});
var url = window.URL.createObjectURL(blob);
var aLink = document.createElement("a");
aLink.style.display = "none";
aLink.href = url;
aLink.setAttribute("download", document.title+".xls");
document.body.appendChild(aLink);
aLink.click();
document.body.removeChild(aLink);
window.URL.revokeObjectURL(url);
},
前端导出excel
最新推荐文章于 2021-07-30 12:15:19 发布