// 下载文件
async downList (item, index) {
let res = await api.downLoadExportList({fileName: item.fileName}, {responseType: "blob"})
this.currentdown = index
let _this = this
try{
if(res) {
let blob = new Blob([res])
// 创建文件流URL
let URL = window.URL || window.webkitURL
let link = URL.createObjectURL(blob)
if(navigator.appVersion.toString().indexOf('.NEF')>0) {
window.navigator.msSaveBlob(blob, this.taskName + dateFtt('yyy.MM.dd', new Date()) + '.xlsx')
} else { // 非IE浏览器
// 创建a标签元素
let downloadElement = document.createElement('a')
// 赋值给a标签
downloadElement.href = link
// 设置文件名称, 可与后端约定
downloadElement.download = _this.tasName + dateFtt('yyy.MM.dd', new Date()) + '.xlsx'
// 将包装好的a标签添加到页面中
document.body.appendChild(downloadElement)
// 触发a标签点击事件
downloadElement.click()
// 移除标签
document.body.removeChild(downloadElement)
// 释放创建的href
window.URL.revokeObjectURL(link)
}
this.currentdown = -1
}else {
translateBlobToJSON(this.responseResult, (_rs) => {
toastTip(_this, {message: _rs.message || '系统异常,稍后再试'})
})
this.currentdown = -1
}
} catch (err) {
errorTip(_this, err)
this.currentdown = -1
}
},
// 生成下载文件的列表(后端提供接口)
通过文件流-下载文件 (结合自己的项目写的, dateFtt()是转换日期格式方法)
于 2021-12-29 00:32:56 首次发布
这段代码实现了异步下载文件的功能,通过调用api.downLoadExportList接口并设置responseType为blob。根据浏览器类型,使用不同的方式触发文件下载,如IE使用msSaveBlob,非IE则通过创建a标签模拟点击下载。如果下载失败,会进行错误提示。
部署运行你感兴趣的模型镜像
您可能感兴趣的与本文相关的镜像
AutoGPT
AI应用
AutoGPT于2023年3月30日由游戏公司Significant Gravitas Ltd.的创始人Toran Bruce Richards发布,AutoGPT是一个AI agent(智能体),也是开源的应用程序,结合了GPT-4和GPT-3.5技术,给定自然语言的目标,它将尝试通过将其分解成子任务,并在自动循环中使用互联网和其他工具来实现这一目标
2626

被折叠的 条评论
为什么被折叠?



