Skip to content

Commit 9784b42

Browse files
committed
refactor: upload types, close #5047
1 parent 06516ec commit 9784b42

16 files changed

+92
-212
lines changed

components/components.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ export {
214214
TypographyTitle,
215215
} from './typography';
216216

217-
export type { UploadProps } from './upload';
217+
export type { UploadProps, UploadListProps, UploadChangeParam } from './upload';
218218

219219
export { default as Upload, UploadDragger } from './upload';
220220

components/upload/Dragger.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { defineComponent } from 'vue';
22
import { getOptionProps, getSlot } from '../_util/props-util';
33
import Upload from './Upload';
4-
import { UploadProps } from './interface';
4+
import { uploadProps } from './interface';
55

66
export default defineComponent({
77
name: 'AUploadDragger',
88
inheritAttrs: false,
9-
props: UploadProps,
9+
props: uploadProps,
1010
render() {
1111
const props = getOptionProps(this);
1212
const { height, ...restProps } = props;

components/upload/Upload.tsx

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,19 @@ import defaultLocale from '../locale-provider/default';
1010
import { defaultConfigProvider } from '../config-provider';
1111
import Dragger from './Dragger';
1212
import UploadList from './UploadList';
13-
import { UploadProps } from './interface';
13+
import type { UploadFile } from './interface';
14+
import { uploadProps } from './interface';
1415
import { T, fileToObject, genPercentAdd, getFileItem, removeFileItem } from './utils';
1516
import { defineComponent, inject } from 'vue';
1617
import { getDataAndAriaProps } from '../_util/util';
1718
import { useInjectFormItemContext } from '../form/FormItemContext';
1819

19-
export type UploadFileStatus = 'error' | 'success' | 'done' | 'uploading' | 'removed';
20-
export interface UploadFile<T = any> {
21-
uid: string;
22-
size?: number;
23-
name: string;
24-
fileName?: string;
25-
lastModified?: number;
26-
lastModifiedDate?: Date;
27-
url?: string;
28-
status?: UploadFileStatus;
29-
percent?: number;
30-
thumbUrl?: string;
31-
originFileObj?: any;
32-
response?: T;
33-
error?: any;
34-
linkProps?: any;
35-
type?: string;
36-
xhr?: T;
37-
preview?: string;
38-
}
39-
4020
export default defineComponent({
4121
name: 'AUpload',
4222
mixins: [BaseMixin],
4323
inheritAttrs: false,
4424
Dragger,
45-
props: initDefaultProps(UploadProps, {
25+
props: initDefaultProps(uploadProps, {
4626
type: 'select',
4727
multiple: false,
4828
action: '',

components/upload/UploadList.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ import EyeOutlined from '@ant-design/icons-vue/EyeOutlined';
2020
import Tooltip from '../tooltip';
2121
import Progress from '../progress';
2222
import classNames from '../_util/classNames';
23-
import { UploadListProps } from './interface';
23+
import { uploadListProps } from './interface';
2424

2525
export default defineComponent({
2626
name: 'AUploadList',
2727
mixins: [BaseMixin],
28-
props: initDefaultProps(UploadListProps, {
28+
props: initDefaultProps(uploadListProps, {
2929
listType: 'text', // or picture
3030
progressAttr: {
3131
strokeWidth: 2,

components/upload/__tests__/upload.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { mount } from '@vue/test-utils';
22
import Upload from '..';
33
import { T, fileToObject, genPercentAdd, getFileItem, removeFileItem } from '../utils';
44
import PropsTypes from '../../_util/vue-types';
5-
import { UploadListProps } from '../interface';
5+
import { uploadListProps } from '../interface';
66
import { setup, teardown } from './mock';
77

8-
UploadListProps.items = PropsTypes.any;
8+
uploadListProps.items = PropsTypes.any;
99

1010
describe('Upload', () => {
1111
beforeEach(() => setup());

components/upload/__tests__/uploadlist.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import * as Vue from 'vue';
33
import Upload from '..';
44
import { errorRequest, successRequest } from './requests';
55
import PropsTypes from '../../_util/vue-types';
6-
import { UploadListProps } from '../interface';
6+
import { uploadListProps } from '../interface';
77
import { sleep } from '../../../tests/utils';
88
import { h } from 'vue';
99

10-
UploadListProps.items = PropsTypes.any;
10+
uploadListProps.items = PropsTypes.any;
1111

1212
const delay = timeout => new Promise(resolve => setTimeout(resolve, timeout));
1313
const fileList = [

components/upload/demo/avatar.vue

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,7 @@ Click to upload user's avatar, and validate size and format of picture with `bef
4242
import { PlusOutlined, LoadingOutlined } from '@ant-design/icons-vue';
4343
import { message } from 'ant-design-vue';
4444
import { defineComponent, ref } from 'vue';
45-
46-
interface FileItem {
47-
uid: string;
48-
name?: string;
49-
status?: string;
50-
response?: string;
51-
url?: string;
52-
type?: string;
53-
size: number;
54-
originFileObj: any;
55-
}
56-
57-
interface FileInfo {
58-
file: FileItem;
59-
fileList: FileItem[];
60-
}
45+
import type { UploadChangeParam, UploadProps } from 'ant-design-vue';
6146
6247
function getBase64(img: Blob, callback: (base64Url: string) => void) {
6348
const reader = new FileReader();
@@ -74,7 +59,7 @@ export default defineComponent({
7459
const loading = ref<boolean>(false);
7560
const imageUrl = ref<string>('');
7661
77-
const handleChange = (info: FileInfo) => {
62+
const handleChange = (info: UploadChangeParam) => {
7863
if (info.file.status === 'uploading') {
7964
loading.value = true;
8065
return;
@@ -92,7 +77,7 @@ export default defineComponent({
9277
}
9378
};
9479
95-
const beforeUpload = (file: FileItem) => {
80+
const beforeUpload = (file: UploadProps['fileList'][number]) => {
9681
const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png';
9782
if (!isJpgOrPng) {
9883
message.error('You can only upload JPG file!');

components/upload/demo/basic.vue

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,14 @@ Classic mode. File selection dialog pops up when upload button is clicked.
3434
import { message } from 'ant-design-vue';
3535
import { UploadOutlined } from '@ant-design/icons-vue';
3636
import { defineComponent, ref } from 'vue';
37-
38-
interface FileItem {
39-
uid: string;
40-
name?: string;
41-
status?: string;
42-
response?: string;
43-
url?: string;
44-
}
45-
46-
interface FileInfo {
47-
file: FileItem;
48-
fileList: FileItem[];
49-
}
37+
import type { UploadChangeParam } from 'ant-design-vue';
5038
5139
export default defineComponent({
5240
components: {
5341
UploadOutlined,
5442
},
5543
setup() {
56-
const handleChange = (info: FileInfo) => {
44+
const handleChange = (info: UploadChangeParam) => {
5745
if (info.file.status !== 'uploading') {
5846
console.log(info.file, info.fileList);
5947
}

components/upload/demo/defaultFileList.vue

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,14 @@ Use `defaultFileList` for uploaded files when page init.
2626
<script lang="ts">
2727
import { UploadOutlined } from '@ant-design/icons-vue';
2828
import { defineComponent, ref } from 'vue';
29-
30-
interface FileItem {
31-
uid: string;
32-
name?: string;
33-
status?: string;
34-
response?: string;
35-
url?: string;
36-
}
37-
interface FileInfo {
38-
file: FileItem;
39-
fileList: FileItem[];
40-
}
29+
import type { UploadChangeParam, UploadProps } from 'ant-design-vue';
4130
4231
export default defineComponent({
4332
components: {
4433
UploadOutlined,
4534
},
4635
setup() {
47-
const fileList = ref<FileItem[]>([
36+
const fileList = ref<UploadProps['fileList']>([
4837
{
4938
uid: '1',
5039
name: 'xxx.png',
@@ -67,7 +56,7 @@ export default defineComponent({
6756
},
6857
]);
6958
70-
const handleChange = ({ file, fileList }: FileInfo) => {
59+
const handleChange = ({ file, fileList }: UploadChangeParam) => {
7160
if (file.status !== 'uploading') {
7261
console.log(file, fileList);
7362
}

components/upload/demo/drag.vue

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,14 @@ We can upload serveral files at once in modern browsers by giving the input the
4141
import { InboxOutlined } from '@ant-design/icons-vue';
4242
import { message } from 'ant-design-vue';
4343
import { defineComponent, ref } from 'vue';
44-
45-
interface FileItem {
46-
uid: string;
47-
name?: string;
48-
status?: string;
49-
response?: string;
50-
url?: string;
51-
}
52-
53-
interface FileInfo {
54-
file: FileItem;
55-
fileList: FileItem[];
56-
}
44+
import type { UploadChangeParam } from 'ant-design-vue';
5745
5846
export default defineComponent({
5947
components: {
6048
InboxOutlined,
6149
},
6250
setup() {
63-
const handleChange = (info: FileInfo) => {
51+
const handleChange = (info: UploadChangeParam) => {
6452
const status = info.file.status;
6553
if (status !== 'uploading') {
6654
console.log(info.file, info.fileList);

0 commit comments

Comments
 (0)