在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Python  HTML/ 請問瀏覽器對連續(xù)點(diǎn)擊事件的節(jié)流時限是多少呢?

請問瀏覽器對連續(xù)點(diǎn)擊事件的節(jié)流時限是多少呢?

現(xiàn)在需要實(shí)現(xiàn)的功能是文件多選,批量下載,下載利用了a標(biāo)簽的download屬性,這里動態(tài)添加a標(biāo)簽,并手動觸發(fā)a標(biāo)簽的click事件。。。如下:循環(huán)調(diào)用getDownloadURL函數(shù)時,每次都只能觸發(fā)最后一個a標(biāo)簽的click事件,即只能下載最后一個文件。。。

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
      }
      /* 這里循環(huán)調(diào)用getDownloadURL函數(shù) */
      ids.forEach((id) => this.getDownloadURL(id))
      
      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)
    },

這里是因為瀏覽器對連續(xù)點(diǎn)擊事件,有節(jié)流處理,所以這里調(diào)用getDownloadURL函數(shù)時加了延時處理,如下:

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)
    },

加了setTimeout之后,連續(xù)點(diǎn)擊事件都可以依次正確觸發(fā),但是setTimeout的時間小于500時,每次第二個點(diǎn)擊事件都會失敗,這里懷疑:瀏覽器對連續(xù)點(diǎn)擊事件的節(jié)流處理時間大于500,所以這里設(shè)置延時小于500時,第二個點(diǎn)擊事件都不會被觸發(fā)。

請問各位大佬,瀏覽器對連續(xù)點(diǎn)擊事件的節(jié)流處理,具體的時限是多少,臨界值具體是多少呢?可以推薦些學(xué)習(xí)資料嗎?

回答
編輯回答
瘋浪

文件批量下載可以讓后端打zip包來下載,你這個hack方法一方面瀏覽器兼容性不一致,另一方面下載出來一堆文件用戶體驗不是很好。如果不考慮這些問題就直接使用500ms即可

2017年3月6日 04:39