This commit is contained in:
parent
413be114e5
commit
1b7f370d06
|
|
@ -146,5 +146,6 @@ export const downloadTaskAPI = (url) => {
|
|||
return request({
|
||||
url: `/bmw/zipDownload/downloadFile${url}`,
|
||||
method: 'GET',
|
||||
responseType: 'blob',
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -270,6 +270,8 @@ export default {
|
|||
subId: '',
|
||||
teamId: '',
|
||||
},
|
||||
// 开启一个下载任务定时器
|
||||
downloadTaskTimer: null,
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
|
@ -500,12 +502,38 @@ export default {
|
|||
return
|
||||
}
|
||||
|
||||
if (this.downloadTaskTimer) {
|
||||
this.$modal.msgError('已有下载任务,请稍后再试')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await getDownloadTaskAPI(this.queryDownloadTask)
|
||||
if (res.taskId) {
|
||||
const result = await getDownloadTaskLinkAPI(res.taskId)
|
||||
const result1 = await downloadTaskAPI(result.downloadUrl)
|
||||
console.log('result1', result1)
|
||||
this.downloadTaskTimer = setInterval(async () => {
|
||||
const result = await getDownloadTaskLinkAPI(res.taskId)
|
||||
|
||||
if (result.status === 'completed') {
|
||||
clearInterval(this.downloadTaskTimer)
|
||||
this.downloadTaskTimer = null
|
||||
const result1 = await downloadTaskAPI(
|
||||
result.downloadUrl,
|
||||
)
|
||||
|
||||
// 创建 Blob 对象
|
||||
const blob = new Blob([result1], {
|
||||
type: 'application/zip',
|
||||
})
|
||||
// 3。创建临时下载链接
|
||||
const link = document.createElement('a')
|
||||
link.href = URL.createObjectURL(blob)
|
||||
link.download = '下载文件.zip'
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
document.body.removeChild(link)
|
||||
URL.revokeObjectURL(link.href)
|
||||
}
|
||||
}, 5000)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('下载文件失败', error)
|
||||
|
|
|
|||
Loading…
Reference in New Issue