From 61bd8abab0859430b55b0768553626c36e65a4d1 Mon Sep 17 00:00:00 2001 From: yiminghe Date: Thu, 27 Aug 2015 15:45:38 +0800 Subject: [PATCH] add onRemove for upload --- components/upload/index.jsx | 56 ++++++++++++++++---------------- components/upload/uploadList.jsx | 4 ++- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/components/upload/index.jsx b/components/upload/index.jsx index b84f8e74a3..f889eae715 100644 --- a/components/upload/index.jsx +++ b/components/upload/index.jsx @@ -13,30 +13,38 @@ const AntUpload = React.createClass({ downloadList: [] }; }, - handleStart(file) { + onStart(file) { let nextDownloadList = this.state.downloadList; nextDownloadList.push({ index: fileIndex++, uid: file.uid || '', filename: file.name, + file: file, status: 'downloading' }); this.setState({ downloadList: nextDownloadList }); + this.props.onStart(file); }, - handleSuccess(ret, file) { + onSuccess(ret, file) { Message.success(file.name + '上传完成'); let targetItem = getFileItem(file, this.state.downloadList); targetItem.status = 'done'; this.setState({ downloadList: this.state.downloadList }); + this.props.onSuccess(ret, file); }, - handleProgress() { + onProgress(e, file) { + this.props.onProgress(e, file); }, - handleError() { + onError(err, responce, file) { Message.error('上传失败'); + this.props.onError(err, responce, file); + }, + onRemove(file){ + this.props.onRemove(file); }, getDefaultProps() { return { @@ -47,32 +55,24 @@ const AntUpload = React.createClass({ data: {}, accept: '', uploadTip: '', - start: function() {}, - error: function() {}, - success: function() {}, - progress: function() {} + onStart() { + }, + onError() { + }, + onSuccess() { + }, + onProgress() { + } }; }, render() { let type = this.props.type || 'select'; - let props = assign({}, this.props); - - props.onStart = (file) => { - this.handleStart(file); - props.start.call(this, file); - }; - props.onSuccess = (ret, file) => { - this.handleSuccess(ret, file); - props.success.call(this, ret, file); - }; - props.onProgress = (step) => { - this.handleProgress(step); - props.progress.call(this, step); - }; - props.onError = (err, responce, file) => { - this.handleError(err); - props.error.call(this, err, responce, file); - }; + let props = assign({}, this.props, { + onStart: this.onStart, + onError: this.onError, + onProgress: this.onProgress, + onSuccess: this.onSuccess, + }); if (type === 'drag') { return (
@@ -91,7 +91,7 @@ const AntUpload = React.createClass({ {this.props.children}
- + ); } @@ -100,7 +100,7 @@ const AntUpload = React.createClass({ AntUpload.Dragger = React.createClass({ render() { - return ; + return ; } }); diff --git a/components/upload/uploadList.jsx b/components/upload/uploadList.jsx index f8946906cc..55af5f482a 100644 --- a/components/upload/uploadList.jsx +++ b/components/upload/uploadList.jsx @@ -30,11 +30,13 @@ export default React.createClass({ this.setState({ items: items }); + this.props.onRemove(file.file); }, render() { let items = this.state.items; let downloadItem = (file) => { - let statusIcon = file.status === 'done' ? : ; + let statusIcon = file.status === 'done' ? : + ; return (
{statusIcon}