//文件zip下载
export async function dwonUpload(data) {
return request({
url: `/system/config/manage/main/output`,
method: 'post',
//设置下载文件为blob转zip
responseType: 'blob',
data:data,
});
}
处理二进制流及blob解析及提示
dwonUpload(params).then((res) => {
var blob = res;
let that=this
//通过FileReader读取数据
var reader = new FileReader();
//以下这两种方式我都可以解析出来,因为Blob对象的数据可以按文本或二进制的格式进行读取
// reader.readAsBinaryString(blob, 'utf8');
reader.readAsText(blob, 'utf8');
reader.onload = function(result){
if(that.isJSON(result.target.result)){
that.$message.warning(JSON.parse(result.target.result).msg)
that.loadingBut=false
}else{
that.downloadFile(res)
}
}
})
导出文件
// 导出
downloadFile(data) {
let blob = new Blob([data], { type: 'application/zip' })
if (window.navigator.msSaveOrOpenBlob) {
navigator.msSaveOrOpenBlob(blob, '导出数据源.zip')
return
}
let url = window.URL.createObjectURL(blob)
const link = document.createElement('a') // 创建a标签
link.href = url
link.download = `导出数据源` // 重命名文件
link.click()
URL.revokeObjectURL(url) // 释放内存
this.loadingBut = false
},
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)