提交 03cc7cbf 编写于 作者: A afc163

Change variable name

上级 fbad793d
# 拖拽上传
- order: 2
- order: 3
样式简单一些。
......
# 拖拽上传
- order: 1
- order: 2
可以把文件拖入指定区域,完成上传,同样支持点击上传。
......
# 文件列表限制
- order: 3
- order: 1
`limit` 属性控制文件列表数的上限。如设为 1 时,表示只能上传一个文件,新文件会顶掉旧文件。
......
......@@ -13,50 +13,50 @@ function noop() {
const AntUpload = React.createClass({
getInitialState() {
return {
downloadList: []
fileList: []
};
},
onStart(file) {
let nextDownloadList = this.state.downloadList;
nextDownloadList.push({
let nextFileList = this.state.fileList;
nextFileList.push({
index: fileIndex++,
uid: file.uid || '',
filename: file.name,
file: file,
status: 'downloading'
status: 'uploading'
});
if (nextDownloadList.length === this.props.limit + 1) {
nextDownloadList = nextDownloadList.slice(1);
if (nextFileList.length === this.props.limit + 1) {
nextFileList = nextFileList.slice(1);
}
this.setState({
downloadList: nextDownloadList
fileList: nextFileList
});
this.props.onStart(file);
},
removeFile(file){
var downloadList = this.state.downloadList.concat();
let targetItem = getFileItem(file, downloadList);
var index = downloadList.indexOf(targetItem);
var fileList = this.state.fileList.concat();
let targetItem = getFileItem(file, fileList);
var index = fileList.indexOf(targetItem);
if (index !== -1) {
downloadList.splice(index, 1);
fileList.splice(index, 1);
}
this.setState({
downloadList: downloadList
fileList: fileList
});
},
onSuccess(ret, file) {
var res = this.props.onSuccess(ret, file);
if (res !== false) {
var downloadList = this.state.downloadList.concat();
var fileList = this.state.fileList.concat();
Message.success(file.name + '上传完成');
let targetItem = getFileItem(file, downloadList);
let targetItem = getFileItem(file, fileList);
targetItem.status = 'done';
// 解析出文件上传后的远程地址
if (typeof this.props.urlResolver === 'function') {
targetItem.url = this.props.urlResolver(ret);
}
this.setState({
downloadList: downloadList
fileList: fileList
});
} else {
this.removeFile(file);
......@@ -121,7 +121,7 @@ const AntUpload = React.createClass({
{this.props.children}
</Upload>
</div>
<UploadList items={this.state.downloadList}
<UploadList items={this.state.fileList}
onRemove={this.onRemove}
limit={props.limit} />
</div>
......
......@@ -33,8 +33,7 @@ export default React.createClass({
this.props.onRemove(file.file);
},
render() {
let items = this.state.items;
let downloadItem = (file) => {
let list = this.state.items.map((file) => {
let statusIcon = file.status === 'done' ? <i className={'anticon anticon-check ' + prefixCls + '-success-icon'}></i> :
<i className="anticon anticon-loading"></i>;
let filename = file.url ? <a className={prefixCls + '-item-name'} href={file.url} _target="_blank">{file.filename}</a> :
......@@ -47,10 +46,10 @@ export default React.createClass({
onClick={this.handleClose.bind(this, file)}></i>
</div>
);
};
});
return (<div className={prefixCls + '-list'}>
<Animate transitionName={prefixCls + '-margin-top'}>
{items.map(downloadItem)}
{list}
</Animate>
</div>);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册