ElementUi Upload组件判断文件是否上传中

// 是否存在上传中
let isUploading = false
function broadcast(componentName, eventName, params) {
  this.$children.forEach(child => {
    var name = child.$options.name
    if (name === componentName) {
      console.log('child.uploadFiles', child.uploadFiles)
      if (child.uploadFiles && child.uploadFiles.length > 0) {
        child.uploadFiles.forEach((item) => {
          if (item.status && item.status === 'uploading') {
            isUploading = true
            return
          }
        })
      }
    } else {
      broadcast.apply(child, [componentName, eventName].concat([params]))
    }
  })
}
export default {
  methods: {
    // 是否存在上传中文件
    isUploading(componentName = 'ElUpload', eventName, params) {
      isUploading = false
      broadcast.call(this, componentName, eventName, params)
      return new Promise((resolve) => {
        if (isUploading) {
          this.$confirm('您确认要放弃未完成的文件上传吗?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            resolve(true)
          }).catch(() => {
            resolve(false)
          })
        } else {
          resolve(true)
        }
      })
    }
  }
}
posted @ 2022-11-23 20:12  吃饭七分饱  阅读(748)  评论(0编辑  收藏  举报