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

浙公网安备 33010602011771号