From 540b43c3f2a19fe65cb2517dba99e79eeeb03669 Mon Sep 17 00:00:00 2001 From: Uyarn Date: Wed, 24 Aug 2022 16:55:54 +0800 Subject: [PATCH] fix(upload): null and type --- src/config-provider/type.ts | 2 +- src/upload/upload.tsx | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/config-provider/type.ts b/src/config-provider/type.ts index eba0721e2..1b2bf13dc 100644 --- a/src/config-provider/type.ts +++ b/src/config-provider/type.ts @@ -811,7 +811,7 @@ export interface UploadTriggerUploadText { normal?: string; fileInput?: string; reupload?: string; - continueUpload: string; + continueUpload?: string; delete?: string; } diff --git a/src/upload/upload.tsx b/src/upload/upload.tsx index 222f8aace..9dba40a82 100644 --- a/src/upload/upload.tsx +++ b/src/upload/upload.tsx @@ -119,7 +119,8 @@ const Upload = forwardRef((props: UploadProps, ref) => { const getLimitedFiles = (files: Array = []) => { const isSingleMode = isSingleFile(multiple, theme); - const mergedLen = files.length + fileList.length; + const currentFileList = fileList || []; + const mergedLen = files.length + currentFileList.length; if (isSingleMode) { return files.splice(0, 1); @@ -127,11 +128,11 @@ const Upload = forwardRef((props: UploadProps, ref) => { // 限制了最大张数 if (max > 0) { - const limitedFiles = mergedLen > max ? files.slice(0, max - fileList.length) : files; - return fileList.concat(limitedFiles); + const limitedFiles = mergedLen > max ? files.slice(0, max - currentFileList.length) : files; + return currentFileList.concat(limitedFiles); } - return fileList.concat(files); + return currentFileList.concat(files); }; const onError = useCallback( @@ -317,10 +318,9 @@ const Upload = forwardRef((props: UploadProps, ref) => { }; const uploadFiles = () => { - const { length } = fileList; let count = 0; const newFileList = []; - fileList.forEach((uploadFile) => { + fileList?.forEach((uploadFile) => { handleBeforeUpload(uploadFile).then((canUpload) => { count += 1; if (canUpload) { @@ -329,7 +329,7 @@ const Upload = forwardRef((props: UploadProps, ref) => { upload(uploadFile); } } - if (count === length) { + if (count === fileList?.length) { setToUploadFiles([...new Set([...toUploadFiles, ...newFileList])]); onChange?.(newFileList, { trigger: 'remove' }); } @@ -462,7 +462,7 @@ const Upload = forwardRef((props: UploadProps, ref) => { } }); - const finish = fileList.every((file) => finishUpload(file.status)); + const finish = (fileList || []).every((file) => finishUpload(file.status)); setUploading(!finish); filesRef.current = fileList; }, [fileList]); @@ -506,7 +506,7 @@ const Upload = forwardRef((props: UploadProps, ref) => { max={max} onRemove={handleMultipleRemove} onTrigger={triggerUpload} - files={fileList} + files={fileList || []} showUploadProgress={showUploadProgress} localeFromProps={localeFromProps} /> @@ -531,7 +531,7 @@ const Upload = forwardRef((props: UploadProps, ref) => {