Skip to content

Commit f6f6c40

Browse files
committed
chore: simplify
1 parent 8683c42 commit f6f6c40

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/packages/uploader/demos/h5/demo1.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,19 @@ const Demo1 = () => {
77
const onStart = () => {
88
console.log('start触发')
99
}
10+
const beforeUpload = async (files: File[]) => {
11+
console.log('bbb')
12+
const allowedTypes = ['image/png']
13+
const filteredFiles = Array.from(files).filter((file) =>
14+
allowedTypes.includes(file.type)
15+
)
16+
return filteredFiles
17+
}
1018
return (
1119
<>
1220
<Cell style={{ flexWrap: 'wrap', paddingBottom: '0px' }}>
1321
<Uploader
22+
beforeUpload={beforeUpload}
1423
url={uploadUrl}
1524
onStart={onStart}
1625
style={{

src/packages/uploader/uploader.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ const InternalUploader: ForwardRefRenderFunction<
105105
> = (props, ref) => {
106106
const { locale } = useConfig()
107107
const fileListRef = useRef<FileItem[]>([])
108-
const fileInputRef = useRef<HTMLInputElement>(null)
109108
const {
110109
children,
111110
uploadIcon,
@@ -360,7 +359,7 @@ const InternalUploader: ForwardRefRenderFunction<
360359
beforeUpload(new Array<File>().slice.call(files)).then(
361360
(f: Array<File> | boolean) => {
362361
const _files: File[] = filterFiles(new Array<File>().slice.call(f))
363-
if (!_files) fileInputRef.current?.reset()
362+
if (!_files) $el.value = ''
364363
readFile(_files)
365364
}
366365
)
@@ -389,7 +388,6 @@ const InternalUploader: ForwardRefRenderFunction<
389388
)}
390389
{Number(maxCount) > fileList.length && (
391390
<input
392-
ref={fileInputRef}
393391
className="nut-uploader-input"
394392
type="file"
395393
capture={capture}
@@ -430,7 +428,6 @@ const InternalUploader: ForwardRefRenderFunction<
430428

431429
<input
432430
className="nut-uploader-input"
433-
ref={fileInputRef}
434431
type="file"
435432
capture={capture}
436433
name={name}

0 commit comments

Comments
 (0)