mirror of
https://github.com/element-plus/element-plus.git
synced 2026-03-13 07:51:17 +08:00
fix(components): [upload] drag file add isDirectory attribute (#20012)
* fix(components): [upload] drag file add isDirectory attribute * fix: compatibility test * fix: extend UploadRawFile
This commit is contained in:
@@ -175,6 +175,7 @@ interface UploadProgressEvent extends ProgressEvent {
|
||||
|
||||
interface UploadRawFile extends File {
|
||||
uid: number
|
||||
isDirectory?: boolean
|
||||
}
|
||||
|
||||
interface UploadRequestOptions {
|
||||
|
||||
@@ -17,6 +17,8 @@ import { throwError } from '@element-plus/utils/error'
|
||||
import { uploadContextKey } from './constants'
|
||||
import { uploadDraggerEmits, uploadDraggerProps } from './upload-dragger'
|
||||
|
||||
import type { UploadRawFile } from './upload'
|
||||
|
||||
const COMPONENT_NAME = 'ElUploadDrag'
|
||||
|
||||
defineOptions({
|
||||
@@ -44,7 +46,15 @@ const onDrop = (e: DragEvent) => {
|
||||
|
||||
e.stopPropagation()
|
||||
|
||||
const files = Array.from(e.dataTransfer!.files)
|
||||
const files = Array.from(e.dataTransfer!.files) as UploadRawFile[]
|
||||
const items = e.dataTransfer!.items || []
|
||||
files.forEach((file, index) => {
|
||||
const item = items[index]
|
||||
const entry = item?.webkitGetAsEntry?.()
|
||||
if (entry) {
|
||||
file.isDirectory = entry.isDirectory
|
||||
}
|
||||
})
|
||||
emit('file', files)
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ export type UploadUserFile = Omit<UploadFile, 'status' | 'uid'> &
|
||||
export type UploadFiles = UploadFile[]
|
||||
export interface UploadRawFile extends File {
|
||||
uid: number
|
||||
isDirectory?: boolean
|
||||
}
|
||||
export type UploadRequestHandler = (
|
||||
options: UploadRequestOptions
|
||||
|
||||
Reference in New Issue
Block a user