核心思路:浏览器是限制瞬间下载10条,所以每下载10条让他休息会就行,用async await实现
小坑:forEach只支持同步,不支持异步,所以不能在forEach里使用async
downFile(url){
let a = document.createElement('a')
console.log(this.downUrl+url)
// window.location.href = this.downUrl+url;
a.setAttribute('href', this.downUrl+url)
a.setAttribute('download', url)
document.body.appendChild(a)
a.click()
document.body.removeChild(a)
},
pause(msec) { // 异步暂停函数
return new Promise(
(resolve, reject) => {
setTimeout(resolve, msec || 1000);
}
);
},
// 批量下载弹窗
async batchDown(){
if(this.currentSelectList.length == 0){
this.$tMsgbox.info({
contentTitle: '请先选择一条数据',
contentBody: ''
});
return ;
}
// let downFileList = [];
let count = 0; // 已下载的文件数
for(let file of this.currentSelectList){
this.downFile(file.erptFilePath)
if(++count >= 10){
await this.pause(1000);
count = 0;
}
}
},