This commit is contained in:
parent
413be114e5
commit
1b7f370d06
|
|
@ -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',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue