This commit is contained in:
BianLzhaoMin 2025-12-19 14:32:44 +08:00
parent 413be114e5
commit 1b7f370d06
2 changed files with 32 additions and 3 deletions

View File

@ -146,5 +146,6 @@ export const downloadTaskAPI = (url) => {
return request({ return request({
url: `/bmw/zipDownload/downloadFile${url}`, url: `/bmw/zipDownload/downloadFile${url}`,
method: 'GET', method: 'GET',
responseType: 'blob',
}) })
} }

View File

@ -270,6 +270,8 @@ export default {
subId: '', subId: '',
teamId: '', teamId: '',
}, },
//
downloadTaskTimer: null,
} }
}, },
methods: { methods: {
@ -500,12 +502,38 @@ export default {
return return
} }
if (this.downloadTaskTimer) {
this.$modal.msgError('已有下载任务,请稍后再试')
return
}
try { try {
const res = await getDownloadTaskAPI(this.queryDownloadTask) const res = await getDownloadTaskAPI(this.queryDownloadTask)
if (res.taskId) { if (res.taskId) {
const result = await getDownloadTaskLinkAPI(res.taskId) this.downloadTaskTimer = setInterval(async () => {
const result1 = await downloadTaskAPI(result.downloadUrl) const result = await getDownloadTaskLinkAPI(res.taskId)
console.log('result1', result1)
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) { } catch (error) {
console.error('下载文件失败', error) console.error('下载文件失败', error)