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

Change variable name

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