Skip to content

Commit

Permalink
fix(upload): null and type
Browse files Browse the repository at this point in the history
  • Loading branch information
uyarn committed Aug 24, 2022
1 parent ffa441f commit 540b43c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/config-provider/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ export interface UploadTriggerUploadText {
normal?: string;
fileInput?: string;
reupload?: string;
continueUpload: string;
continueUpload?: string;
delete?: string;
}

Expand Down
20 changes: 10 additions & 10 deletions src/upload/upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,20 @@ const Upload = forwardRef((props: UploadProps, ref) => {

const getLimitedFiles = (files: Array<TdUploadFile> = []) => {
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);
}

// 限制了最大张数
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(
Expand Down Expand Up @@ -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) {
Expand All @@ -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' });
}
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -506,7 +506,7 @@ const Upload = forwardRef((props: UploadProps, ref) => {
max={max}
onRemove={handleMultipleRemove}
onTrigger={triggerUpload}
files={fileList}
files={fileList || []}
showUploadProgress={showUploadProgress}
localeFromProps={localeFromProps}
/>
Expand All @@ -531,7 +531,7 @@ const Upload = forwardRef((props: UploadProps, ref) => {
</BooleanRender>
<BooleanRender boolExpression={showUploadList}>
<FlowList
files={fileList}
files={fileList || []}
placeholder={placeholder}
toUploadFiles={toUploadFiles}
remove={handleListRemove}
Expand Down

0 comments on commit 540b43c

Please sign in to comment.