From fcc8c261667c95d019887cf22ef30daf468060d1 Mon Sep 17 00:00:00 2001 From: afc163 Date: Mon, 14 Sep 2015 00:28:39 +0800 Subject: [PATCH] Add error status for upload file item --- components/upload/demo/basic.md | 2 +- components/upload/demo/multiple.md | 2 +- components/upload/index.jsx | 8 ++++++-- components/upload/index.md | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/components/upload/demo/basic.md b/components/upload/demo/basic.md index 1dc0290efc..12a1bc888a 100644 --- a/components/upload/demo/basic.md +++ b/components/upload/demo/basic.md @@ -18,7 +18,7 @@ var props = { } if (info.file.status === 'done') { message.success(info.file.name + ' 上传成功。'); - } else if (info.file.error) { + } else if (info.file.status === 'error') { message.error(info.file.name + ' 上传失败。'); } } diff --git a/components/upload/demo/multiple.md b/components/upload/demo/multiple.md index 60af122c6c..e3edb684ad 100644 --- a/components/upload/demo/multiple.md +++ b/components/upload/demo/multiple.md @@ -19,7 +19,7 @@ var props = { } if (info.file.status === 'done') { message.success(info.file.name + ' 上传成功。'); - } else if (info.file.error) { + } else if (info.file.status === 'error') { message.error(info.file.name + ' 上传失败。'); } } diff --git a/components/upload/index.jsx b/components/upload/index.jsx index 07606dac6f..9cacc70932 100644 --- a/components/upload/index.jsx +++ b/components/upload/index.jsx @@ -31,7 +31,6 @@ const AntUpload = React.createClass({ }); }, removeFile(file) { - file.status = 'removed'; let fileList = this.state.fileList.concat(); let targetItem = getFileItem(file, fileList); let index = fileList.indexOf(targetItem); @@ -68,6 +67,7 @@ const AntUpload = React.createClass({ onError(error, response, file) { file.error = error; file.response = response; + file.status = 'error'; this.handleRemove(file); }, handleRemove(file) { @@ -79,6 +79,10 @@ const AntUpload = React.createClass({ }); } }, + handleManualRemove(file) { + file.status = 'removed'; + this.handleRemove(file); + }, onChange(info) { // 1. 有设置外部属性时不改变 fileList // 2. 上传中状态(info.event)不改变 fileList @@ -134,7 +138,7 @@ const AntUpload = React.createClass({ + onRemove={this.handleManualRemove} /> ); } diff --git a/components/upload/index.md b/components/upload/index.md index 4d5fc18874..601e5d05ae 100644 --- a/components/upload/index.md +++ b/components/upload/index.md @@ -45,7 +45,7 @@ { uid: 'uid', // 文件唯一标识,建议设置为负数,防止和内部产生的 id 冲突 name: 'xx.png' // 文件名 - status: 'done', // 状态:uploading done + status: 'done', // 状态有:uploading done error removed response: '{"status":"success"}' // 服务端响应内容 } ```