Skip to content

Commit 21bca58

Browse files
committed
refactor: upload to ts
1 parent 0d5d223 commit 21bca58

File tree

6 files changed

+45
-35
lines changed

6 files changed

+45
-35
lines changed
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import { defineComponent } from 'vue';
12
import { getOptionProps, getSlot } from '../_util/props-util';
23
import Upload from './Upload';
34
import { UploadProps } from './interface';
45

5-
export default {
6+
export default defineComponent({
67
name: 'AUploadDragger',
78
inheritAttrs: false,
89
props: UploadProps,
@@ -14,8 +15,8 @@ export default {
1415
...restProps,
1516
...restAttrs,
1617
type: 'drag',
17-
style: { ...style, height },
18-
};
18+
style: { ...(style as any), height },
19+
} as any;
1920
return <Upload {...draggerProps}>{getSlot(this)}</Upload>;
2021
},
21-
};
22+
});

components/upload/Upload.jsx renamed to components/upload/Upload.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,19 @@ import uniqBy from 'lodash-es/uniqBy';
33
import findIndex from 'lodash-es/findIndex';
44
import VcUpload from '../vc-upload';
55
import BaseMixin from '../_util/BaseMixin';
6-
import { getOptionProps, initDefaultProps, hasProp, getSlot } from '../_util/props-util';
6+
import { getOptionProps, hasProp, getSlot } from '../_util/props-util';
7+
import initDefaultProps from '../_util/props-util/initDefaultProps';
78
import LocaleReceiver from '../locale-provider/LocaleReceiver';
89
import defaultLocale from '../locale-provider/default';
910
import { defaultConfigProvider } from '../config-provider';
1011
import Dragger from './Dragger';
1112
import UploadList from './UploadList';
1213
import { UploadProps } from './interface';
1314
import { T, fileToObject, genPercentAdd, getFileItem, removeFileItem } from './utils';
14-
import { inject } from 'vue';
15+
import { defineComponent, inject } from 'vue';
1516
import { getDataAndAria } from '../vc-tree/src/util';
1617

17-
export { UploadProps };
18-
19-
export default {
18+
export default defineComponent({
2019
name: 'AUpload',
2120
mixins: [BaseMixin],
2221
inheritAttrs: false,
@@ -35,12 +34,13 @@ export default {
3534
}),
3635
setup() {
3736
return {
37+
upload: null,
38+
progressTimer: null,
3839
configProvider: inject('configProvider', defaultConfigProvider),
3940
};
4041
},
4142
// recentUploadStatus: boolean | PromiseLike<any>;
4243
data() {
43-
this.progressTimer = null;
4444
return {
4545
sFileList: this.fileList || this.defaultFileList || [],
4646
dragState: 'drop',
@@ -159,7 +159,7 @@ export default {
159159
},
160160
handleManualRemove(file) {
161161
if (this.$refs.uploadRef) {
162-
this.$refs.uploadRef.abort(file);
162+
(this.$refs.uploadRef as any).abort(file);
163163
}
164164
this.handleRemove(file);
165165
},
@@ -275,7 +275,7 @@ export default {
275275
if (type === 'drag') {
276276
const dragCls = classNames(prefixCls, {
277277
[`${prefixCls}-drag`]: true,
278-
[`${prefixCls}-drag-uploading`]: fileList.some(file => file.status === 'uploading'),
278+
[`${prefixCls}-drag-uploading`]: fileList.some((file: any) => file.status === 'uploading'),
279279
[`${prefixCls}-drag-hover`]: dragState === 'dragover',
280280
[`${prefixCls}-disabled`]: disabled,
281281
});
@@ -330,4 +330,4 @@ export default {
330330
</span>
331331
);
332332
},
333-
};
333+
});

components/upload/UploadList.jsx renamed to components/upload/UploadList.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { inject, Transition, TransitionGroup } from 'vue';
1+
import { defineComponent, inject, Transition, TransitionGroup, CSSProperties } from 'vue';
22
import BaseMixin from '../_util/BaseMixin';
33
import { getOptionProps, initDefaultProps } from '../_util/props-util';
44
import getTransitionProps from '../_util/getTransitionProps';
@@ -17,7 +17,7 @@ import classNames from '../_util/classNames';
1717
import { UploadListProps } from './interface';
1818
import getTransitionGroupProps from '../_util/getTransitionGroupProps';
1919

20-
export default {
20+
export default defineComponent({
2121
name: 'AUploadList',
2222
mixins: [BaseMixin],
2323
props: initDefaultProps(UploadListProps, {
@@ -206,7 +206,7 @@ export default {
206206
</span>,
207207
downloadOrDelete,
208208
];
209-
const style =
209+
const style: CSSProperties | undefined =
210210
file.url || file.thumbUrl
211211
? undefined
212212
: {
@@ -266,11 +266,14 @@ export default {
266266
[`${prefixCls}-list-${listType}`]: true,
267267
});
268268
const animationDirection = listType === 'picture-card' ? 'animate-inline' : 'animate';
269-
const transitionGroupProps = getTransitionGroupProps(`${prefixCls}-${animationDirection}`);
269+
const transitionGroupProps = {
270+
...getTransitionGroupProps(`${prefixCls}-${animationDirection}`),
271+
class: listClassNames,
272+
};
270273
return (
271-
<TransitionGroup {...transitionGroupProps} tag="div" class={listClassNames}>
274+
<TransitionGroup {...transitionGroupProps} tag="div">
272275
{list}
273276
</TransitionGroup>
274277
);
275278
},
276-
};
279+
});
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { App } from 'vue';
12
import Upload from './Upload';
23
import Dragger from './Dragger';
34

@@ -6,10 +7,12 @@ export { UploadProps, UploadListProps, UploadChangeParam } from './interface';
67
Upload.Dragger = Dragger;
78

89
/* istanbul ignore next */
9-
Upload.install = function(app) {
10+
Upload.install = function(app: App) {
1011
app.component(Upload.name, Upload);
1112
app.component(Dragger.name, Dragger);
1213
return app;
1314
};
1415

15-
export default Upload;
16+
export default Upload as typeof Upload & {
17+
readonly Dragger: typeof Dragger;
18+
};

components/upload/interface.jsx renamed to components/upload/interface.tsx

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1+
import { tuple } from '../_util/type';
12
import PropsTypes from '../_util/vue-types';
23

3-
export const UploadFileStatus = PropsTypes.oneOf([
4-
'error',
5-
'success',
6-
'done',
7-
'uploading',
8-
'removed',
9-
]);
4+
export const UploadFileStatus = PropsTypes.oneOf(
5+
tuple('error', 'success', 'done', 'uploading', 'removed'),
6+
);
107

11-
// export const HttpRequestHeader {
12-
// [key: string]: string;
13-
// }
8+
export interface HttpRequestHeader {
9+
[key: string]: string;
10+
}
11+
12+
export interface VcFile extends File {
13+
uid: string;
14+
readonly lastModifiedDate: Date;
15+
readonly webkitRelativePath: string;
16+
}
1417

1518
// export const UploadFile = PropsTypes.shape({
1619
// uid: PropsTypes.oneOfType([
@@ -60,20 +63,20 @@ export const UploadLocale = PropsTypes.shape({
6063
}).loose;
6164

6265
export const UploadProps = {
63-
type: PropsTypes.oneOf(['drag', 'select']),
66+
type: PropsTypes.oneOf(tuple('drag', 'select')),
6467
name: PropsTypes.string,
6568
defaultFileList: PropsTypes.arrayOf(PropsTypes.custom(UploadFile)),
6669
fileList: PropsTypes.arrayOf(PropsTypes.custom(UploadFile)),
6770
action: PropsTypes.oneOfType([PropsTypes.string, PropsTypes.func]),
6871
directory: PropsTypes.looseBool,
6972
data: PropsTypes.oneOfType([PropsTypes.object, PropsTypes.func]),
70-
method: PropsTypes.oneOf(['POST', 'PUT', 'post', 'put']),
73+
method: PropsTypes.oneOf(tuple('POST', 'PUT', 'post', 'put')),
7174
headers: PropsTypes.object,
7275
showUploadList: PropsTypes.oneOfType([PropsTypes.looseBool, ShowUploadListInterface]),
7376
multiple: PropsTypes.looseBool,
7477
accept: PropsTypes.string,
7578
beforeUpload: PropsTypes.func,
76-
listType: PropsTypes.oneOf(['text', 'picture', 'picture-card']),
79+
listType: PropsTypes.oneOf(tuple('text', 'picture', 'picture-card')),
7780
// className: PropsTypes.string,
7881
remove: PropsTypes.func,
7982
supportServerRender: PropsTypes.looseBool,
@@ -101,7 +104,7 @@ export const UploadState = {
101104
};
102105

103106
export const UploadListProps = {
104-
listType: PropsTypes.oneOf(['text', 'picture', 'picture-card']),
107+
listType: PropsTypes.oneOf(tuple('text', 'picture', 'picture-card')),
105108
// items: PropsTypes.arrayOf(UploadFile),
106109
items: PropsTypes.arrayOf(PropsTypes.custom(UploadFile)),
107110
// items: PropsTypes.any,
File renamed without changes.

0 commit comments

Comments
 (0)