1
1
import classNames from 'classnames' ;
2
2
import uniqBy from 'lodash/uniqBy' ;
3
3
import findIndex from 'lodash/findIndex' ;
4
- import pick from 'lodash/pick' ;
5
4
import VcUpload from '../vc-upload' ;
6
5
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' ;
8
7
import LocaleReceiver from '../locale-provider/LocaleReceiver' ;
9
8
import defaultLocale from '../locale-provider/default' ;
10
9
import { ConfigConsumerProps } from '../config-provider' ;
11
10
import Dragger from './Dragger' ;
12
11
import UploadList from './UploadList' ;
13
12
import { UploadProps } from './interface' ;
14
13
import { T , fileToObject , genPercentAdd , getFileItem , removeFileItem } from './utils' ;
14
+ import { inject } from 'vue' ;
15
15
16
16
export { UploadProps } ;
17
17
@@ -32,8 +32,10 @@ export default {
32
32
disabled : false ,
33
33
supportServerRender : true ,
34
34
} ) ,
35
- inject : {
36
- configProvider : { default : ( ) => ConfigConsumerProps } ,
35
+ setup ( ) {
36
+ return {
37
+ configProvider : inject ( 'configProvider' , ConfigConsumerProps ) ,
38
+ } ;
37
39
} ,
38
40
// recentUploadStatus: boolean | PromiseLike<any>;
39
41
data ( ) {
@@ -217,20 +219,18 @@ export default {
217
219
} = getOptionProps ( this ) ;
218
220
const { showRemoveIcon, showPreviewIcon, showDownloadIcon } = showUploadList ;
219
221
const { sFileList : fileList } = this . $data ;
222
+ const { onDownload, onPreview } = this . $attrs ;
220
223
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,
234
234
} ;
235
235
return < UploadList { ...uploadListProps } /> ;
236
236
} ,
@@ -248,31 +248,27 @@ export default {
248
248
const prefixCls = getPrefixCls ( 'upload' , customizePrefixCls ) ;
249
249
250
250
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 ,
263
259
ref : 'uploadRef' ,
264
- attrs : this . $attrs ,
260
+ ... this . $attrs ,
265
261
} ;
266
262
267
263
const uploadList = showUploadList ? (
268
264
< LocaleReceiver
269
265
componentName = "Upload"
270
266
defaultLocale = { defaultLocale . Upload }
271
- scopedSlots = { { default : this . renderUploadList } }
267
+ children = { this . renderUploadList }
272
268
/>
273
269
) : null ;
274
270
275
- const children = this . $slots . default ;
271
+ const children = getSlot ( this ) ;
276
272
277
273
if ( type === 'drag' ) {
278
274
const dragCls = classNames ( prefixCls , {
0 commit comments