Skip to content

Commit a325bf2

Browse files
authored
feat: update upload (#2494)
* feat: update upload * chore: cache babel * chore: make run dev faster
1 parent 23358db commit a325bf2

File tree

9 files changed

+88
-184
lines changed

9 files changed

+88
-184
lines changed

components/upload/Upload.jsx

+28-32
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import classNames from 'classnames';
22
import uniqBy from 'lodash/uniqBy';
33
import findIndex from 'lodash/findIndex';
4-
import pick from 'lodash/pick';
54
import VcUpload from '../vc-upload';
65
import BaseMixin from '../_util/BaseMixin';
7-
import { getOptionProps, initDefaultProps, hasProp, getListeners } from '../_util/props-util';
6+
import { getOptionProps, initDefaultProps, hasProp, getSlot } from '../_util/props-util';
87
import LocaleReceiver from '../locale-provider/LocaleReceiver';
98
import defaultLocale from '../locale-provider/default';
109
import { ConfigConsumerProps } from '../config-provider';
1110
import Dragger from './Dragger';
1211
import UploadList from './UploadList';
1312
import { UploadProps } from './interface';
1413
import { T, fileToObject, genPercentAdd, getFileItem, removeFileItem } from './utils';
14+
import { inject } from 'vue';
1515

1616
export { UploadProps };
1717

@@ -32,8 +32,10 @@ export default {
3232
disabled: false,
3333
supportServerRender: true,
3434
}),
35-
inject: {
36-
configProvider: { default: () => ConfigConsumerProps },
35+
setup() {
36+
return {
37+
configProvider: inject('configProvider', ConfigConsumerProps),
38+
};
3739
},
3840
// recentUploadStatus: boolean | PromiseLike<any>;
3941
data() {
@@ -217,20 +219,18 @@ export default {
217219
} = getOptionProps(this);
218220
const { showRemoveIcon, showPreviewIcon, showDownloadIcon } = showUploadList;
219221
const { sFileList: fileList } = this.$data;
222+
const { onDownload, onPreview } = this.$attrs;
220223
const uploadListProps = {
221-
props: {
222-
listType,
223-
items: fileList,
224-
previewFile,
225-
showRemoveIcon: !disabled && showRemoveIcon,
226-
showPreviewIcon,
227-
showDownloadIcon,
228-
locale: { ...locale, ...propLocale },
229-
},
230-
on: {
231-
remove: this.handleManualRemove,
232-
...pick(getListeners(this), ['download', 'preview']), // 如果没有配置该事件,不要传递, uploadlist 会有相应逻辑
233-
},
224+
listType,
225+
items: fileList,
226+
previewFile,
227+
showRemoveIcon: !disabled && showRemoveIcon,
228+
showPreviewIcon,
229+
showDownloadIcon,
230+
locale: { ...locale, ...propLocale },
231+
onRemove: this.handleManualRemove,
232+
onDownload,
233+
onPreview,
234234
};
235235
return <UploadList {...uploadListProps} />;
236236
},
@@ -248,31 +248,27 @@ export default {
248248
const prefixCls = getPrefixCls('upload', customizePrefixCls);
249249

250250
const vcUploadProps = {
251-
props: {
252-
...this.$props,
253-
prefixCls,
254-
beforeUpload: this.reBeforeUpload,
255-
},
256-
on: {
257-
start: this.onStart,
258-
error: this.onError,
259-
progress: this.onProgress,
260-
success: this.onSuccess,
261-
reject: this.onReject,
262-
},
251+
...this.$props,
252+
prefixCls,
253+
beforeUpload: this.reBeforeUpload,
254+
onStart: this.onStart,
255+
onError: this.onError,
256+
onProgress: this.onProgress,
257+
onSuccess: this.onSuccess,
258+
onReject: this.onReject,
263259
ref: 'uploadRef',
264-
attrs: this.$attrs,
260+
...this.$attrs,
265261
};
266262

267263
const uploadList = showUploadList ? (
268264
<LocaleReceiver
269265
componentName="Upload"
270266
defaultLocale={defaultLocale.Upload}
271-
scopedSlots={{ default: this.renderUploadList }}
267+
children={this.renderUploadList}
272268
/>
273269
) : null;
274270

275-
const children = this.$slots.default;
271+
const children = getSlot(this);
276272

277273
if (type === 'drag') {
278274
const dragCls = classNames(prefixCls, {

components/upload/UploadList.jsx

+12-14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { inject, TransitionGroup } from 'vue';
12
import BaseMixin from '../_util/BaseMixin';
23
import { getOptionProps, initDefaultProps, getListeners } from '../_util/props-util';
34
import getTransitionProps from '../_util/getTransitionProps';
@@ -29,8 +30,10 @@ export default {
2930
showPreviewIcon: true,
3031
previewFile: previewImage,
3132
}),
32-
inject: {
33-
configProvider: { default: () => ConfigConsumerProps },
33+
setup() {
34+
return {
35+
configProvider: inject('configProvider', ConfigConsumerProps),
36+
};
3437
},
3538
updated() {
3639
this.$nextTick(() => {
@@ -132,11 +135,9 @@ export default {
132135

133136
if (file.status === 'uploading') {
134137
const progressProps = {
135-
props: {
136-
...progressAttr,
137-
type: 'line',
138-
percent: file.percent,
139-
},
138+
...progressAttr,
139+
type: 'line',
140+
percent: file.percent,
140141
};
141142
// show loading icon if upload progress listener is disabled
142143
const loadingProgress = 'percent' in file ? <Progress {...progressProps} /> : null;
@@ -160,10 +161,7 @@ export default {
160161
) : null;
161162
const downloadIcon =
162163
showDownloadIcon && file.status === 'done' ? (
163-
<DownloadOutlined
164-
title={locale.downloadFile}
165-
onClick={() => this.handleDownload(file)}
166-
/>
164+
<DownloadOutlined title={locale.downloadFile} onClick={() => this.handleDownload(file)} />
167165
) : null;
168166
const downloadOrDelete = listType !== 'picture-card' && (
169167
<span
@@ -250,7 +248,7 @@ export default {
250248
<div class={infoUploadingClass} key={file.uid}>
251249
<div class={`${prefixCls}-list-item-info`}>{iconAndPreview}</div>
252250
{actions}
253-
<transition {...transitionProps}>{progress}</transition>
251+
<Transition {...transitionProps}>{progress}</Transition>
254252
</div>
255253
);
256254
const listContainerNameClass = classNames({
@@ -269,9 +267,9 @@ export default {
269267
const animationDirection = listType === 'picture-card' ? 'animate-inline' : 'animate';
270268
const transitionGroupProps = getTransitionProps(`${prefixCls}-${animationDirection}`);
271269
return (
272-
<transition-group {...transitionGroupProps} tag="div" class={listClassNames}>
270+
<TransitionGroup {...transitionGroupProps} tag="div" class={listClassNames}>
273271
{list}
274-
</transition-group>
272+
</TransitionGroup>
275273
);
276274
},
277275
};

components/vc-progress/src/Circle.js

+8-20
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import Vue from 'vue';
2-
import ref from 'vue-ref';
31
import PropTypes from '../../_util/vue-types';
2+
import antRef from '../../_util/ant-ref';
43
import { initDefaultProps } from '../../_util/props-util';
54
import enhancer from './enhancer';
65
import { propTypes, defaultProps } from './types';
@@ -16,8 +15,6 @@ const circleDefaultProps = {
1615
gapPosition: 'top',
1716
};
1817

19-
Vue.use(ref, { name: 'ant-ref' });
20-
2118
let gradientSeed = 0;
2219

2320
function stripPercentToNumber(percent) {
@@ -74,6 +71,7 @@ function getPathStyles(offset, percent, strokeColor, strokeWidth, gapDegree = 0,
7471

7572
const Circle = {
7673
props: initDefaultProps(circlePropTypes, circleDefaultProps),
74+
directives: { antRef },
7775
created() {
7876
this.paths = {};
7977
this.gradientId = gradientSeed;
@@ -113,25 +111,15 @@ const Circle = {
113111

114112
const pathProps = {
115113
key: index,
116-
attrs: {
117-
d: pathString,
118-
stroke,
119-
'stroke-linecap': strokeLinecap,
120-
'stroke-width': ptg === 0 ? 0 : strokeWidth,
121-
'fill-opacity': '0',
122-
},
114+
d: pathString,
115+
stroke,
116+
'stroke-linecap': strokeLinecap,
117+
'stroke-width': ptg === 0 ? 0 : strokeWidth,
118+
'fill-opacity': '0',
123119
class: `${prefixCls}-circle-path`,
124120
style: pathStyle,
125-
directives: [
126-
{
127-
name: 'ant-ref',
128-
value: c => {
129-
this.paths[index] = c;
130-
},
131-
},
132-
],
133121
};
134-
return <path {...pathProps} />;
122+
return <path v-antRef={c => (this.paths[index] = c)} {...pathProps} />;
135123
});
136124
},
137125
},

components/vc-progress/src/Line.js

+3-13
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
import Vue from 'vue';
2-
import ref from 'vue-ref';
31
import { initDefaultProps } from '../../_util/props-util';
2+
import antRef from '../../_util/ant-ref';
43
import enhancer from './enhancer';
54
import { propTypes, defaultProps } from './types';
65

7-
Vue.use(ref, { name: 'ant-ref' });
8-
96
const Line = {
107
props: initDefaultProps(propTypes, defaultProps),
8+
directives: { antRef },
119
created() {
1210
this.paths = {};
1311
},
@@ -78,17 +76,9 @@ const Line = {
7876
},
7977
class: `${prefixCls}-line-path`,
8078
style: pathStyle,
81-
directives: [
82-
{
83-
name: 'ant-ref',
84-
value: c => {
85-
this.paths[index] = c;
86-
},
87-
},
88-
],
8979
};
9080

91-
return <path {...pathProps} />;
81+
return <path v-antRef={c => (this.paths[index] = c)} {...pathProps} />;
9282
})}
9383
</svg>
9484
);

components/vc-upload/src/AjaxUploader.jsx

+9-14
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import defaultRequest from './request';
66
import getUid from './uid';
77
import attrAccept from './attr-accept';
88
import traverseFileTree from './traverseFileTree';
9-
import { getListeners } from '../../_util/props-util';
9+
import { getListeners, getSlot } from '../../_util/props-util';
1010

1111
const upLoadPropTypes = {
1212
componentTag: PropTypes.string,
@@ -223,20 +223,15 @@ const AjaxUploader = {
223223
const events = disabled
224224
? {}
225225
: {
226-
click: openFileDialogOnClick ? this.onClick : () => {},
227-
keydown: openFileDialogOnClick ? this.onKeyDown : () => {},
228-
drop: this.onFileDrop,
229-
dragover: this.onFileDrop,
226+
onClick: openFileDialogOnClick ? this.onClick : () => {},
227+
onKeydown: openFileDialogOnClick ? this.onKeyDown : () => {},
228+
onDrop: this.onFileDrop,
229+
onDragover: this.onFileDrop,
230230
};
231231
const tagProps = {
232-
on: {
233-
...getListeners(this),
234-
...events,
235-
},
236-
attrs: {
237-
role: 'button',
238-
tabIndex: disabled ? null : '0',
239-
},
232+
...events,
233+
role: 'button',
234+
tabIndex: disabled ? null : '0',
240235
class: cls,
241236
};
242237
return (
@@ -254,7 +249,7 @@ const AjaxUploader = {
254249
multiple={multiple}
255250
onChange={this.onChange}
256251
/>
257-
{this.$slots.default}
252+
{getSlot(this)}
258253
</Tag>
259254
);
260255
},

components/vc-upload/src/IframeUploader.jsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import BaseMixin from '../../_util/BaseMixin';
33
import classNames from 'classnames';
44
import getUid from './uid';
55
import warning from '../../_util/warning';
6+
import { getSlot } from '../../_util/props-util';
67

78
const IFRAME_STYLE = {
89
position: 'absolute',
@@ -268,7 +269,7 @@ const IframeUploader = {
268269
return (
269270
<Tag className={cls} style={{ position: 'relative', zIndex: 0 }}>
270271
<iframe ref="iframeRef" onLoad={this.onLoad} style={iframeStyle} />
271-
{this.$slots.default}
272+
{getSlot(this)}
272273
</Tag>
273274
);
274275
},

0 commit comments

Comments
 (0)