refactor: upload to ts
parent
0d5d2234c6
commit
21bca582c6
|
@ -1,8 +1,9 @@
|
||||||
|
import { defineComponent } from 'vue';
|
||||||
import { getOptionProps, getSlot } from '../_util/props-util';
|
import { getOptionProps, getSlot } from '../_util/props-util';
|
||||||
import Upload from './Upload';
|
import Upload from './Upload';
|
||||||
import { UploadProps } from './interface';
|
import { UploadProps } from './interface';
|
||||||
|
|
||||||
export default {
|
export default defineComponent({
|
||||||
name: 'AUploadDragger',
|
name: 'AUploadDragger',
|
||||||
inheritAttrs: false,
|
inheritAttrs: false,
|
||||||
props: UploadProps,
|
props: UploadProps,
|
||||||
|
@ -14,8 +15,8 @@ export default {
|
||||||
...restProps,
|
...restProps,
|
||||||
...restAttrs,
|
...restAttrs,
|
||||||
type: 'drag',
|
type: 'drag',
|
||||||
style: { ...style, height },
|
style: { ...(style as any), height },
|
||||||
};
|
} as any;
|
||||||
return <Upload {...draggerProps}>{getSlot(this)}</Upload>;
|
return <Upload {...draggerProps}>{getSlot(this)}</Upload>;
|
||||||
},
|
},
|
||||||
};
|
});
|
|
@ -3,7 +3,8 @@ import uniqBy from 'lodash-es/uniqBy';
|
||||||
import findIndex from 'lodash-es/findIndex';
|
import findIndex from 'lodash-es/findIndex';
|
||||||
import VcUpload from '../vc-upload';
|
import VcUpload from '../vc-upload';
|
||||||
import BaseMixin from '../_util/BaseMixin';
|
import BaseMixin from '../_util/BaseMixin';
|
||||||
import { getOptionProps, initDefaultProps, hasProp, getSlot } from '../_util/props-util';
|
import { getOptionProps, hasProp, getSlot } from '../_util/props-util';
|
||||||
|
import initDefaultProps from '../_util/props-util/initDefaultProps';
|
||||||
import LocaleReceiver from '../locale-provider/LocaleReceiver';
|
import LocaleReceiver from '../locale-provider/LocaleReceiver';
|
||||||
import defaultLocale from '../locale-provider/default';
|
import defaultLocale from '../locale-provider/default';
|
||||||
import { defaultConfigProvider } from '../config-provider';
|
import { defaultConfigProvider } from '../config-provider';
|
||||||
|
@ -11,12 +12,10 @@ import Dragger from './Dragger';
|
||||||
import UploadList from './UploadList';
|
import UploadList from './UploadList';
|
||||||
import { UploadProps } from './interface';
|
import { UploadProps } from './interface';
|
||||||
import { T, fileToObject, genPercentAdd, getFileItem, removeFileItem } from './utils';
|
import { T, fileToObject, genPercentAdd, getFileItem, removeFileItem } from './utils';
|
||||||
import { inject } from 'vue';
|
import { defineComponent, inject } from 'vue';
|
||||||
import { getDataAndAria } from '../vc-tree/src/util';
|
import { getDataAndAria } from '../vc-tree/src/util';
|
||||||
|
|
||||||
export { UploadProps };
|
export default defineComponent({
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'AUpload',
|
name: 'AUpload',
|
||||||
mixins: [BaseMixin],
|
mixins: [BaseMixin],
|
||||||
inheritAttrs: false,
|
inheritAttrs: false,
|
||||||
|
@ -35,12 +34,13 @@ export default {
|
||||||
}),
|
}),
|
||||||
setup() {
|
setup() {
|
||||||
return {
|
return {
|
||||||
|
upload: null,
|
||||||
|
progressTimer: null,
|
||||||
configProvider: inject('configProvider', defaultConfigProvider),
|
configProvider: inject('configProvider', defaultConfigProvider),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
// recentUploadStatus: boolean | PromiseLike<any>;
|
// recentUploadStatus: boolean | PromiseLike<any>;
|
||||||
data() {
|
data() {
|
||||||
this.progressTimer = null;
|
|
||||||
return {
|
return {
|
||||||
sFileList: this.fileList || this.defaultFileList || [],
|
sFileList: this.fileList || this.defaultFileList || [],
|
||||||
dragState: 'drop',
|
dragState: 'drop',
|
||||||
|
@ -159,7 +159,7 @@ export default {
|
||||||
},
|
},
|
||||||
handleManualRemove(file) {
|
handleManualRemove(file) {
|
||||||
if (this.$refs.uploadRef) {
|
if (this.$refs.uploadRef) {
|
||||||
this.$refs.uploadRef.abort(file);
|
(this.$refs.uploadRef as any).abort(file);
|
||||||
}
|
}
|
||||||
this.handleRemove(file);
|
this.handleRemove(file);
|
||||||
},
|
},
|
||||||
|
@ -275,7 +275,7 @@ export default {
|
||||||
if (type === 'drag') {
|
if (type === 'drag') {
|
||||||
const dragCls = classNames(prefixCls, {
|
const dragCls = classNames(prefixCls, {
|
||||||
[`${prefixCls}-drag`]: true,
|
[`${prefixCls}-drag`]: true,
|
||||||
[`${prefixCls}-drag-uploading`]: fileList.some(file => file.status === 'uploading'),
|
[`${prefixCls}-drag-uploading`]: fileList.some((file: any) => file.status === 'uploading'),
|
||||||
[`${prefixCls}-drag-hover`]: dragState === 'dragover',
|
[`${prefixCls}-drag-hover`]: dragState === 'dragover',
|
||||||
[`${prefixCls}-disabled`]: disabled,
|
[`${prefixCls}-disabled`]: disabled,
|
||||||
});
|
});
|
||||||
|
@ -330,4 +330,4 @@ export default {
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
};
|
});
|
|
@ -1,4 +1,4 @@
|
||||||
import { inject, Transition, TransitionGroup } from 'vue';
|
import { defineComponent, inject, Transition, TransitionGroup, CSSProperties } from 'vue';
|
||||||
import BaseMixin from '../_util/BaseMixin';
|
import BaseMixin from '../_util/BaseMixin';
|
||||||
import { getOptionProps, initDefaultProps } from '../_util/props-util';
|
import { getOptionProps, initDefaultProps } from '../_util/props-util';
|
||||||
import getTransitionProps from '../_util/getTransitionProps';
|
import getTransitionProps from '../_util/getTransitionProps';
|
||||||
|
@ -17,7 +17,7 @@ import classNames from '../_util/classNames';
|
||||||
import { UploadListProps } from './interface';
|
import { UploadListProps } from './interface';
|
||||||
import getTransitionGroupProps from '../_util/getTransitionGroupProps';
|
import getTransitionGroupProps from '../_util/getTransitionGroupProps';
|
||||||
|
|
||||||
export default {
|
export default defineComponent({
|
||||||
name: 'AUploadList',
|
name: 'AUploadList',
|
||||||
mixins: [BaseMixin],
|
mixins: [BaseMixin],
|
||||||
props: initDefaultProps(UploadListProps, {
|
props: initDefaultProps(UploadListProps, {
|
||||||
|
@ -206,7 +206,7 @@ export default {
|
||||||
</span>,
|
</span>,
|
||||||
downloadOrDelete,
|
downloadOrDelete,
|
||||||
];
|
];
|
||||||
const style =
|
const style: CSSProperties | undefined =
|
||||||
file.url || file.thumbUrl
|
file.url || file.thumbUrl
|
||||||
? undefined
|
? undefined
|
||||||
: {
|
: {
|
||||||
|
@ -266,11 +266,14 @@ export default {
|
||||||
[`${prefixCls}-list-${listType}`]: true,
|
[`${prefixCls}-list-${listType}`]: true,
|
||||||
});
|
});
|
||||||
const animationDirection = listType === 'picture-card' ? 'animate-inline' : 'animate';
|
const animationDirection = listType === 'picture-card' ? 'animate-inline' : 'animate';
|
||||||
const transitionGroupProps = getTransitionGroupProps(`${prefixCls}-${animationDirection}`);
|
const transitionGroupProps = {
|
||||||
|
...getTransitionGroupProps(`${prefixCls}-${animationDirection}`),
|
||||||
|
class: listClassNames,
|
||||||
|
};
|
||||||
return (
|
return (
|
||||||
<TransitionGroup {...transitionGroupProps} tag="div" class={listClassNames}>
|
<TransitionGroup {...transitionGroupProps} tag="div">
|
||||||
{list}
|
{list}
|
||||||
</TransitionGroup>
|
</TransitionGroup>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
};
|
});
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { App } from 'vue';
|
||||||
import Upload from './Upload';
|
import Upload from './Upload';
|
||||||
import Dragger from './Dragger';
|
import Dragger from './Dragger';
|
||||||
|
|
||||||
|
@ -6,10 +7,12 @@ export { UploadProps, UploadListProps, UploadChangeParam } from './interface';
|
||||||
Upload.Dragger = Dragger;
|
Upload.Dragger = Dragger;
|
||||||
|
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
Upload.install = function(app) {
|
Upload.install = function(app: App) {
|
||||||
app.component(Upload.name, Upload);
|
app.component(Upload.name, Upload);
|
||||||
app.component(Dragger.name, Dragger);
|
app.component(Dragger.name, Dragger);
|
||||||
return app;
|
return app;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Upload;
|
export default Upload as typeof Upload & {
|
||||||
|
readonly Dragger: typeof Dragger;
|
||||||
|
};
|
|
@ -1,16 +1,19 @@
|
||||||
|
import { tuple } from '../_util/type';
|
||||||
import PropsTypes from '../_util/vue-types';
|
import PropsTypes from '../_util/vue-types';
|
||||||
|
|
||||||
export const UploadFileStatus = PropsTypes.oneOf([
|
export const UploadFileStatus = PropsTypes.oneOf(
|
||||||
'error',
|
tuple('error', 'success', 'done', 'uploading', 'removed'),
|
||||||
'success',
|
);
|
||||||
'done',
|
|
||||||
'uploading',
|
|
||||||
'removed',
|
|
||||||
]);
|
|
||||||
|
|
||||||
// export const HttpRequestHeader {
|
export interface HttpRequestHeader {
|
||||||
// [key: string]: string;
|
[key: string]: string;
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
export interface VcFile extends File {
|
||||||
|
uid: string;
|
||||||
|
readonly lastModifiedDate: Date;
|
||||||
|
readonly webkitRelativePath: string;
|
||||||
|
}
|
||||||
|
|
||||||
// export const UploadFile = PropsTypes.shape({
|
// export const UploadFile = PropsTypes.shape({
|
||||||
// uid: PropsTypes.oneOfType([
|
// uid: PropsTypes.oneOfType([
|
||||||
|
@ -60,20 +63,20 @@ export const UploadLocale = PropsTypes.shape({
|
||||||
}).loose;
|
}).loose;
|
||||||
|
|
||||||
export const UploadProps = {
|
export const UploadProps = {
|
||||||
type: PropsTypes.oneOf(['drag', 'select']),
|
type: PropsTypes.oneOf(tuple('drag', 'select')),
|
||||||
name: PropsTypes.string,
|
name: PropsTypes.string,
|
||||||
defaultFileList: PropsTypes.arrayOf(PropsTypes.custom(UploadFile)),
|
defaultFileList: PropsTypes.arrayOf(PropsTypes.custom(UploadFile)),
|
||||||
fileList: PropsTypes.arrayOf(PropsTypes.custom(UploadFile)),
|
fileList: PropsTypes.arrayOf(PropsTypes.custom(UploadFile)),
|
||||||
action: PropsTypes.oneOfType([PropsTypes.string, PropsTypes.func]),
|
action: PropsTypes.oneOfType([PropsTypes.string, PropsTypes.func]),
|
||||||
directory: PropsTypes.looseBool,
|
directory: PropsTypes.looseBool,
|
||||||
data: PropsTypes.oneOfType([PropsTypes.object, PropsTypes.func]),
|
data: PropsTypes.oneOfType([PropsTypes.object, PropsTypes.func]),
|
||||||
method: PropsTypes.oneOf(['POST', 'PUT', 'post', 'put']),
|
method: PropsTypes.oneOf(tuple('POST', 'PUT', 'post', 'put')),
|
||||||
headers: PropsTypes.object,
|
headers: PropsTypes.object,
|
||||||
showUploadList: PropsTypes.oneOfType([PropsTypes.looseBool, ShowUploadListInterface]),
|
showUploadList: PropsTypes.oneOfType([PropsTypes.looseBool, ShowUploadListInterface]),
|
||||||
multiple: PropsTypes.looseBool,
|
multiple: PropsTypes.looseBool,
|
||||||
accept: PropsTypes.string,
|
accept: PropsTypes.string,
|
||||||
beforeUpload: PropsTypes.func,
|
beforeUpload: PropsTypes.func,
|
||||||
listType: PropsTypes.oneOf(['text', 'picture', 'picture-card']),
|
listType: PropsTypes.oneOf(tuple('text', 'picture', 'picture-card')),
|
||||||
// className: PropsTypes.string,
|
// className: PropsTypes.string,
|
||||||
remove: PropsTypes.func,
|
remove: PropsTypes.func,
|
||||||
supportServerRender: PropsTypes.looseBool,
|
supportServerRender: PropsTypes.looseBool,
|
||||||
|
@ -101,7 +104,7 @@ export const UploadState = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const UploadListProps = {
|
export const UploadListProps = {
|
||||||
listType: PropsTypes.oneOf(['text', 'picture', 'picture-card']),
|
listType: PropsTypes.oneOf(tuple('text', 'picture', 'picture-card')),
|
||||||
// items: PropsTypes.arrayOf(UploadFile),
|
// items: PropsTypes.arrayOf(UploadFile),
|
||||||
items: PropsTypes.arrayOf(PropsTypes.custom(UploadFile)),
|
items: PropsTypes.arrayOf(PropsTypes.custom(UploadFile)),
|
||||||
// items: PropsTypes.any,
|
// items: PropsTypes.any,
|
Loading…
Reference in New Issue