mirror of
https://github.com/element-plus/element-plus.git
synced 2026-03-13 07:51:17 +08:00
fix(components): [upload] drag use before-upload to intercepting files (#15861)
This commit is contained in:
@@ -44,35 +44,7 @@ const onDrop = (e: DragEvent) => {
|
||||
e.stopPropagation()
|
||||
|
||||
const files = Array.from(e.dataTransfer!.files)
|
||||
const accept = uploaderContext.accept.value
|
||||
if (!accept) {
|
||||
emit('file', files)
|
||||
return
|
||||
}
|
||||
|
||||
const filesFiltered = files.filter((file) => {
|
||||
const { type, name } = file
|
||||
const extension = name.includes('.') ? `.${name.split('.').pop()}` : ''
|
||||
const baseType = type.replace(/\/.*$/, '')
|
||||
return accept
|
||||
.split(',')
|
||||
.map((type) => type.trim())
|
||||
.filter((type) => type)
|
||||
.some((acceptedType) => {
|
||||
if (acceptedType.startsWith('.')) {
|
||||
return extension === acceptedType
|
||||
}
|
||||
if (/\/\*$/.test(acceptedType)) {
|
||||
return baseType === acceptedType.replace(/\/\*$/, '')
|
||||
}
|
||||
if (/^[^/]+\/[^/]+$/.test(acceptedType)) {
|
||||
return type === acceptedType
|
||||
}
|
||||
return false
|
||||
})
|
||||
})
|
||||
|
||||
emit('file', filesFiltered)
|
||||
emit('file', files)
|
||||
}
|
||||
|
||||
const onDragover = () => {
|
||||
|
||||
Reference in New Issue
Block a user