async download(row){
this.currentRow=row;
// 查询文件id
const res=await this.getFileIdById(row.id);
if(res.data.code==1){
const file=await this.downloadFile(res.data.data[0].id);
// 下载文件流
if(file.data){
const blob = file.data;
const filename = res.data.data[0].name;
if(window.navigator.msSaveOrOpenBlob){
// ie,直接调用msSaveBlob方法
navigator.msSaveBlob(blob, filename);
}else{
// 非ie
const reader = new FileReader();
reader.readAsDataURL(blob);
reader.onload = (e) => {
const a = document.createElement('a');
a.download = filename;
a.href = e.target.result;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
};
}
}
}
}
网友评论