what you need to achieve now is to select multiple files, download in batches, and download using the download attribute of the a tag, where the a tag is dynamically added and the click event of the a tag is manually triggered. This is as follows: when the getDownloadURL function is called in a loop, only the click event of the last a tag can be triggered each time, that is, only the last file can be downloaded.
downloadFile() {
if (this.multipleSelection.some(e => e.type === FILE_TYPE_DIR)) {
this.$message.warning("")
return
}
let ids = this.multipleSelection.map(e => e.file_library_id)
if (ids.length === 0) {
this.$message.info("")
return
}
/* */
ids.forEach((id, i) =>
setTimeout(() => {
this.getDownloadURL(id)
}, 500 * i)
)
this.$refs.table.clearSelection()
},
async getDownloadURL(id) {
let targetEl = document.createElement("a")
targetEl.setAttribute("download", "download")
document.body.appendChild(targetEl)
let { error_code, result } = await SDK.media.getDownloadURL(id)
if (error_code) return
targetEl.setAttribute("href", result)
targetEl.click()
document.body.removeChild(targetEl)
},
after adding setTimeout, successive click events can be triggered correctly in turn, but when the setTimeout time is less than 500, each second click event will fail. It is suspected that the throttling processing time for continuous click events in the browser is greater than 500, so if the delay is less than 500, the second click event will not be triggered.
I would like to ask all bosses, what is the specific time limit for the browser"s throttling handling of continuous click events, and what is the specific critical value? Can you recommend some study materials?