downFun() {
this.confirmBox("确认下载所选记录?", "提示")
.then(() => {
exportOrgan({...this.formData,districtCode: this.treeNode.areaCode}).then((res) => {
if (res.code != 200) {
return this.msgError(res.msg);
}
const fileName = res.data;
download(fileName).then((resp) => {
this.downloadFun(resp);
});
});
})
.catch(() => {});
},
downloadFun(resp) {
const mimeType =
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
var patt = new RegExp("filename=([^;]+.[^.;]+);*");
var contentDisposition = decodeURI(resp.headers["content-disposition"]);
var result = patt.exec(contentDisposition);
var fn = result[1].split(";")[0];
const aLink = document.createElement("a");
var blob = new Blob([resp.data], {
type: mimeType,
});
aLink.href = window.URL.createObjectURL(blob);
aLink.setAttribute("download", fn);
document.body.appendChild(aLink);
aLink.click();
document.body.removeChild(aLink);
},
接口
export function exportOrgan(query) {
return get(
'/organ/export',
query
)
}
export function download(fileName){
return http({
method:'get',
url:'/common/download',
params:{fileName:encodeURI(fileName),delete:true},
headers:{Authorization:auth}
})
}
|