11import classNames from 'classnames' ;
22import uniqBy from 'lodash/uniqBy' ;
33import findIndex from 'lodash/findIndex' ;
4+ import pick from 'lodash/pick' ;
45import VcUpload from '../vc-upload' ;
56import BaseMixin from '../_util/BaseMixin' ;
67import { getOptionProps , initDefaultProps , hasProp , getListeners } from '../_util/props-util' ;
@@ -66,25 +67,12 @@ export default {
6667 fileList : nextFileList ,
6768 } ) ;
6869 // fix ie progress
69- if ( ! window . FormData ) {
70+ if ( ! window . File || process . env . TEST_IE ) {
7071 this . autoUpdateProgress ( 0 , targetItem ) ;
7172 }
7273 } ,
73- autoUpdateProgress ( _ , file ) {
74- const getPercent = genPercentAdd ( ) ;
75- let curPercent = 0 ;
76- this . clearProgressTimer ( ) ;
77- this . progressTimer = setInterval ( ( ) => {
78- curPercent = getPercent ( curPercent ) ;
79- this . onProgress (
80- {
81- percent : curPercent * 100 ,
82- } ,
83- file ,
84- ) ;
85- } , 200 ) ;
86- } ,
87- onSuccess ( response , file ) {
74+
75+ onSuccess ( response , file , xhr ) {
8876 this . clearProgressTimer ( ) ;
8977 try {
9078 if ( typeof response === 'string' ) {
@@ -101,6 +89,7 @@ export default {
10189 }
10290 targetItem . status = 'done' ;
10391 targetItem . response = response ;
92+ targetItem . xhr = xhr ;
10493 this . onChange ( {
10594 file : { ...targetItem } ,
10695 fileList,
@@ -140,19 +129,24 @@ export default {
140129 this . $emit ( 'reject' , fileList ) ;
141130 } ,
142131 handleRemove ( file ) {
143- const { remove } = this ;
144- const { status } = file ;
145- file . status = 'removed' ; // eslint-disable-line
132+ const { remove : onRemove } = this ;
133+ const { sFileList : fileList } = this . $data ;
146134
147- Promise . resolve ( typeof remove === 'function' ? remove ( file ) : remove ) . then ( ret => {
135+ Promise . resolve ( typeof onRemove === 'function' ? onRemove ( file ) : onRemove ) . then ( ret => {
148136 // Prevent removing file
149137 if ( ret === false ) {
150- file . status = status ;
151138 return ;
152139 }
153140
154- const removedFileList = removeFileItem ( file , this . sFileList ) ;
141+ const removedFileList = removeFileItem ( file , fileList ) ;
142+
155143 if ( removedFileList ) {
144+ file . status = 'removed' ; // eslint-disable-line
145+
146+ if ( this . upload ) {
147+ this . upload . abort ( file ) ;
148+ }
149+
156150 this . onChange ( {
157151 file,
158152 fileList : removedFileList ,
@@ -178,14 +172,16 @@ export default {
178172 } ) ;
179173 } ,
180174 reBeforeUpload ( file , fileList ) {
181- if ( ! this . beforeUpload ) {
175+ const { beforeUpload } = this . $props ;
176+ const { sFileList : stateFileList } = this . $data ;
177+ if ( ! beforeUpload ) {
182178 return true ;
183179 }
184- const result = this . beforeUpload ( file , fileList ) ;
180+ const result = beforeUpload ( file , fileList ) ;
185181 if ( result === false ) {
186182 this . onChange ( {
187183 file,
188- fileList : uniqBy ( this . sFileList . concat ( fileList . map ( fileToObject ) ) , item => item . uid ) ,
184+ fileList : uniqBy ( stateFileList . concat ( fileList . map ( fileToObject ) ) , item => item . uid ) ,
189185 } ) ;
190186 return false ;
191187 }
@@ -197,25 +193,45 @@ export default {
197193 clearProgressTimer ( ) {
198194 clearInterval ( this . progressTimer ) ;
199195 } ,
196+ autoUpdateProgress ( _ , file ) {
197+ const getPercent = genPercentAdd ( ) ;
198+ let curPercent = 0 ;
199+ this . clearProgressTimer ( ) ;
200+ this . progressTimer = setInterval ( ( ) => {
201+ curPercent = getPercent ( curPercent ) ;
202+ this . onProgress (
203+ {
204+ percent : curPercent * 100 ,
205+ } ,
206+ file ,
207+ ) ;
208+ } , 200 ) ;
209+ } ,
200210 renderUploadList ( locale ) {
201- const { showUploadList = { } , listType } = getOptionProps ( this ) ;
202- const { showRemoveIcon, showPreviewIcon } = showUploadList ;
211+ const {
212+ showUploadList = { } ,
213+ listType,
214+ previewFile,
215+ disabled,
216+ locale : propLocale ,
217+ } = getOptionProps ( this ) ;
218+ const { showRemoveIcon, showPreviewIcon, showDownloadIcon } = showUploadList ;
219+ const { sFileList : fileList } = this . $data ;
203220 const uploadListProps = {
204221 props : {
205222 listType,
206- items : this . sFileList ,
207- showRemoveIcon,
223+ items : fileList ,
224+ previewFile,
225+ showRemoveIcon : ! disabled && showRemoveIcon ,
208226 showPreviewIcon,
209- locale : { ...locale , ...this . $props . locale } ,
227+ showDownloadIcon,
228+ locale : { ...locale , ...propLocale } ,
210229 } ,
211230 on : {
212231 remove : this . handleManualRemove ,
232+ ...pick ( getListeners ( this ) , [ 'download' , 'preview' ] ) , // 如果没有配置该事件,不要传递, uploadlist 会有相应逻辑
213233 } ,
214234 } ;
215- const listeners = getListeners ( this ) ;
216- if ( listeners . preview ) {
217- uploadListProps . on . preview = listeners . preview ;
218- }
219235 return < UploadList { ...uploadListProps } /> ;
220236 } ,
221237 } ,
@@ -227,7 +243,7 @@ export default {
227243 type,
228244 disabled,
229245 } = getOptionProps ( this ) ;
230-
246+ const { sFileList : fileList , dragState } = this . $data ;
231247 const getPrefixCls = this . configProvider . getPrefixCls ;
232248 const prefixCls = getPrefixCls ( 'upload' , customizePrefixCls ) ;
233249
@@ -261,8 +277,8 @@ export default {
261277 if ( type === 'drag' ) {
262278 const dragCls = classNames ( prefixCls , {
263279 [ `${ prefixCls } -drag` ] : true ,
264- [ `${ prefixCls } -drag-uploading` ] : this . sFileList . some ( file => file . status === 'uploading' ) ,
265- [ `${ prefixCls } -drag-hover` ] : this . dragState === 'dragover' ,
280+ [ `${ prefixCls } -drag-uploading` ] : fileList . some ( file => file . status === 'uploading' ) ,
281+ [ `${ prefixCls } -drag-hover` ] : dragState === 'dragover' ,
266282 [ `${ prefixCls } -disabled` ] : disabled ,
267283 } ) ;
268284 return (
@@ -290,7 +306,7 @@ export default {
290306
291307 // Remove id to avoid open by label when trigger is hidden
292308 // https://github.com/ant-design/ant-design/issues/14298
293- if ( ! children ) {
309+ if ( ! children || disabled ) {
294310 delete vcUploadProps . props . id ;
295311 }
296312
@@ -302,7 +318,7 @@ export default {
302318
303319 if ( listType === 'picture-card' ) {
304320 return (
305- < span >
321+ < span class = { ` ${ prefixCls } -picture-card-wrapper` } >
306322 { uploadList }
307323 { uploadButton }
308324 </ span >
0 commit comments