diff --git a/components/upload/demo/drag-simple.md b/components/upload/demo/drag-simple.md
index 5f4e36adc3..27003ab633 100644
--- a/components/upload/demo/drag-simple.md
+++ b/components/upload/demo/drag-simple.md
@@ -12,6 +12,7 @@ const Dragger = Upload.Dragger;
const props = {
name: 'file',
+ showUploadList: false,
action: '/upload.do'
};
@@ -26,6 +27,5 @@ ReactDOM.render(
diff --git a/components/upload/demo/drag.md b/components/upload/demo/drag.md
index 34eb582151..4862b7039b 100644
--- a/components/upload/demo/drag.md
+++ b/components/upload/demo/drag.md
@@ -12,6 +12,7 @@ const Dragger = Upload.Dragger;
const props = {
name: 'file',
+ showUploadList: false,
action: '/upload.do'
};
@@ -26,9 +27,3 @@ ReactDOM.render(
document.getElementById('components-upload-demo-drag')
);
````
-
-
diff --git a/components/upload/demo/multiple.md b/components/upload/demo/multiple.md
index 600afbef48..a76ec7696b 100644
--- a/components/upload/demo/multiple.md
+++ b/components/upload/demo/multiple.md
@@ -32,4 +32,3 @@ ReactDOM.render(
, document.getElementById('components-upload-demo-multiple'));
````
-
diff --git a/components/upload/index.jsx b/components/upload/index.jsx
index 52edc5e121..f2fdc878fb 100644
--- a/components/upload/index.jsx
+++ b/components/upload/index.jsx
@@ -19,7 +19,30 @@ function fileToObject(file) {
type: file.type,
uid: file.uid,
response: file.response,
- error: file.error
+ error: file.error,
+ percent: 0
+ };
+}
+
+/**
+ * 生成Progress percent: 0.1 -> 0.98
+ * - for ie
+ */
+function genPercentAdd() {
+ let k = 0.1;
+ const i = 0.01;
+ const end = 0.98;
+ return function(start) {
+ if (start >= end) {
+ return start;
+ } else {
+ start += k;
+ k = k - i;
+ if (k < 0.001) {
+ k = 0.001;
+ }
+ }
+ return start * 100;
};
}
@@ -48,6 +71,20 @@ const AntUpload = React.createClass({
file: targetItem,
fileList: nextFileList
});
+ // fix ie progress
+ if (!window.FormData) {
+ this.autoUpdateProgress(0, targetItem);
+ }
+ },
+ autoUpdateProgress(percent, file) {
+ const getPercent = genPercentAdd();
+ let curPercent = 0;
+ this.progressTimer = setInterval(() => {
+ curPercent = getPercent(curPercent);
+ this.onProgress({
+ percent: curPercent
+ }, file);
+ }, 200);
},
removeFile(file) {
let fileList = this.state.fileList;
@@ -60,6 +97,7 @@ const AntUpload = React.createClass({
return null;
},
onSuccess(response, file) {
+ this.clearProgressTimer();
// 服务器端需要返回标准 json 字符串
// 否则视为失败
try {
@@ -85,15 +123,16 @@ const AntUpload = React.createClass({
onProgress(e, file) {
let fileList = this.state.fileList;
let targetItem = getFileItem(file, fileList);
- if (targetItem) {
- this.onChange({
- event: e,
- file: file,
- fileList: this.state.fileList
- });
- }
+ if (!targetItem) return;
+ targetItem.percent = e.percent;
+ this.onChange({
+ event: e,
+ file: file,
+ fileList: this.state.fileList
+ });
},
onError(error, response, file) {
+ this.clearProgressTimer();
let fileList = this.state.fileList;
let targetItem = getFileItem(file, fileList);
targetItem.error = error;
@@ -115,13 +154,9 @@ const AntUpload = React.createClass({
this.handleRemove(file);
},
onChange(info) {
- // 1. 有设置外部属性时不改变 fileList
- // 2. 上传中状态(info.event)不改变 fileList
- if (!('fileList' in this.props) && !info.event) {
- this.setState({
- fileList: info.fileList
- });
- }
+ this.setState({
+ fileList: info.fileList
+ });
this.props.onChange(info);
},
getDefaultProps() {
@@ -133,6 +168,7 @@ const AntUpload = React.createClass({
data: {},
accept: '',
onChange: noop,
+ showUploadList: true
};
},
componentWillReceiveProps(nextProps) {
@@ -142,6 +178,9 @@ const AntUpload = React.createClass({
});
}
},
+ clearProgressTimer() {
+ clearInterval(this.progressTimer);
+ },
render() {
let type = this.props.type || 'select';
let props = assign({}, this.props, {
@@ -150,14 +189,29 @@ const AntUpload = React.createClass({
onProgress: this.onProgress,
onSuccess: this.onSuccess,
});
+ let uploadList;
+ if (this.props.showUploadList) {
+ uploadList =