Kermit
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with
38 additions and
8 deletions
-
components/upload/UploadList/index.tsx
-
components/upload/__tests__/type.test.tsx
-
components/upload/interface.tsx
-
components/upload/utils.tsx
|
|
@ -6,7 +6,7 @@ import PaperClipOutlined from '@ant-design/icons/PaperClipOutlined'; |
|
|
|
import PictureTwoTone from '@ant-design/icons/PictureTwoTone'; |
|
|
|
import FileTwoTone from '@ant-design/icons/FileTwoTone'; |
|
|
|
import { cloneElement, isValidElement } from '../../_util/reactNode'; |
|
|
|
import { UploadListProps, UploadFile, UploadListType } from '../interface'; |
|
|
|
import { UploadListProps, UploadFile, UploadListType, InternalUploadFile } from '../interface'; |
|
|
|
import { previewImage, isImageUrl } from '../utils'; |
|
|
|
import collapseMotion from '../../_util/motion'; |
|
|
|
import { ConfigContext } from '../../config-provider'; |
|
|
@ -53,7 +53,7 @@ const InternalUploadList: React.ForwardRefRenderFunction<unknown, UploadListProp |
|
|
|
if (listType !== 'picture' && listType !== 'picture-card') { |
|
|
|
return; |
|
|
|
} |
|
|
|
(items || []).forEach(file => { |
|
|
|
(items || []).forEach((file: InternalUploadFile) => { |
|
|
|
if ( |
|
|
|
typeof document === 'undefined' || |
|
|
|
typeof window === 'undefined' || |
|
|
|
|
|
@ -46,4 +46,27 @@ describe('Upload.typescript', () => { |
|
|
|
); |
|
|
|
expect(upload).toBeTruthy(); |
|
|
|
}); |
|
|
|
|
|
|
|
it('defaultFileList/fileList', () => { |
|
|
|
const fileList = [ |
|
|
|
{ |
|
|
|
uid: '-1', |
|
|
|
name: 'xxx.png', |
|
|
|
status: 'done' as const, |
|
|
|
url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png', |
|
|
|
thumbUrl: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png', |
|
|
|
}, |
|
|
|
{ |
|
|
|
uid: '-2', |
|
|
|
name: 'yyy.png', |
|
|
|
status: 'error' as const, |
|
|
|
}, |
|
|
|
]; |
|
|
|
const upload = ( |
|
|
|
<Upload fileList={fileList} defaultFileList={fileList}> |
|
|
|
<span>click to upload</span> |
|
|
|
</Upload> |
|
|
|
); |
|
|
|
expect(upload).toBeTruthy(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
@ -17,7 +17,7 @@ export interface HttpRequestHeader { |
|
|
|
|
|
|
|
export interface UploadFile<T = any> { |
|
|
|
uid: string; |
|
|
|
size: number; |
|
|
|
size?: number; |
|
|
|
name: string; |
|
|
|
fileName?: string; |
|
|
|
lastModified?: number; |
|
|
@ -26,15 +26,19 @@ export interface UploadFile<T = any> { |
|
|
|
status?: UploadFileStatus; |
|
|
|
percent?: number; |
|
|
|
thumbUrl?: string; |
|
|
|
originFileObj: RcFile; |
|
|
|
originFileObj?: RcFile; |
|
|
|
response?: T; |
|
|
|
error?: any; |
|
|
|
linkProps?: any; |
|
|
|
type: string; |
|
|
|
type?: string; |
|
|
|
xhr?: T; |
|
|
|
preview?: string; |
|
|
|
} |
|
|
|
|
|
|
|
export interface InternalUploadFile<T = any> extends UploadFile<T> { |
|
|
|
originFileObj: RcFile; |
|
|
|
} |
|
|
|
|
|
|
|
export interface UploadChangeParam<T extends object = UploadFile> { |
|
|
|
// https://github.com/ant-design/ant-design/issues/14420
|
|
|
|
file: T; |
|
|
@ -86,7 +90,10 @@ export interface UploadProps<T = any> { |
|
|
|
showUploadList?: boolean | ShowUploadListInterface; |
|
|
|
multiple?: boolean; |
|
|
|
accept?: string; |
|
|
|
beforeUpload?: (file: RcFile, FileList: RcFile[]) => boolean | string | Promise<void | Blob | File>; |
|
|
|
beforeUpload?: ( |
|
|
|
file: RcFile, |
|
|
|
FileList: RcFile[], |
|
|
|
) => boolean | string | Promise<void | Blob | File>; |
|
|
|
onChange?: (info: UploadChangeParam) => void; |
|
|
|
listType?: UploadListType; |
|
|
|
className?: string; |
|
|
|
|
|
@ -1,6 +1,6 @@ |
|
|
|
import { RcFile, UploadFile } from './interface'; |
|
|
|
import { RcFile, UploadFile, InternalUploadFile } from './interface'; |
|
|
|
|
|
|
|
export function file2Obj(file: RcFile): UploadFile { |
|
|
|
export function file2Obj(file: RcFile): InternalUploadFile { |
|
|
|
return { |
|
|
|
...file, |
|
|
|
lastModified: file.lastModified, |
|
|
|