mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-05 05:28:20 +08:00
Merge branch 'joesonw-uploadList#1' into develop-1.0.0
This commit is contained in:
commit
8420909c75
@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
order: 5
|
order: 5
|
||||||
hidden: 5
|
hidden: true
|
||||||
title: 多文件选择
|
title: 多文件选择
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@ -6,9 +6,22 @@ title: 图片卡片样式
|
|||||||
上传文件为图片,可展示本地缩略图。
|
上传文件为图片,可展示本地缩略图。
|
||||||
|
|
||||||
````jsx
|
````jsx
|
||||||
import { Upload, Icon } from 'antd';
|
import { Upload, Icon, Modal } from 'antd';
|
||||||
|
|
||||||
const props = {
|
const ImageUploadList = React.createClass({
|
||||||
|
getInitialState() {
|
||||||
|
return {
|
||||||
|
priviewVisible: false,
|
||||||
|
priviewImage: '',
|
||||||
|
};
|
||||||
|
},
|
||||||
|
handleCancel() {
|
||||||
|
this.setState({
|
||||||
|
priviewVisible: false,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
render() {
|
||||||
|
const props = {
|
||||||
action: '/upload.do',
|
action: '/upload.do',
|
||||||
listType: 'picture-card',
|
listType: 'picture-card',
|
||||||
defaultFileList: [{
|
defaultFileList: [{
|
||||||
@ -17,11 +30,16 @@ const props = {
|
|||||||
status: 'done',
|
status: 'done',
|
||||||
url: 'https://os.alipayobjects.com/rmsportal/NDbkJhpzmLxtPhB.png',
|
url: 'https://os.alipayobjects.com/rmsportal/NDbkJhpzmLxtPhB.png',
|
||||||
thumbUrl: 'https://os.alipayobjects.com/rmsportal/NDbkJhpzmLxtPhB.png',
|
thumbUrl: 'https://os.alipayobjects.com/rmsportal/NDbkJhpzmLxtPhB.png',
|
||||||
}]
|
}],
|
||||||
};
|
onPreview: (file) => {
|
||||||
|
this.setState({
|
||||||
ReactDOM.render(
|
priviewImage: file.url,
|
||||||
<div className="clearfix">
|
priviewVisible: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return (
|
||||||
|
<div className="clearfix">
|
||||||
<Upload {...props}>
|
<Upload {...props}>
|
||||||
<Icon type="plus" />
|
<Icon type="plus" />
|
||||||
<div className="ant-upload-text">上传照片</div>
|
<div className="ant-upload-text">上传照片</div>
|
||||||
@ -30,8 +48,15 @@ ReactDOM.render(
|
|||||||
<img src="https://os.alipayobjects.com/rmsportal/NDbkJhpzmLxtPhB.png" />
|
<img src="https://os.alipayobjects.com/rmsportal/NDbkJhpzmLxtPhB.png" />
|
||||||
<span>示例</span>
|
<span>示例</span>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
<Modal visible={this.state.priviewVisible} footer={null} onCancel={this.handleCancel}>
|
||||||
, mountNode);
|
<img src={this.state.priviewImage} />
|
||||||
|
</Modal>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ReactDOM.render(<ImageUploadList />, mountNode);
|
||||||
````
|
````
|
||||||
|
|
||||||
````css
|
````css
|
||||||
|
@ -188,12 +188,22 @@ export default class Upload extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handlePreview = (file) => {
|
||||||
|
if ('onPreview' in this.props) {
|
||||||
|
this.props.onPreview(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
handleManualRemove = (file) => {
|
handleManualRemove = (file) => {
|
||||||
/*eslint-disable */
|
/*eslint-disable */
|
||||||
file.status = 'removed';
|
file.status = 'removed';
|
||||||
/*eslint-enable */
|
/*eslint-enable */
|
||||||
|
if ('onRemove' in this.props) {
|
||||||
|
this.props.onRemove(file);
|
||||||
|
} else {
|
||||||
this.handleRemove(file);
|
this.handleRemove(file);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onChange = (info) => {
|
onChange = (info) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
@ -235,6 +245,7 @@ export default class Upload extends React.Component {
|
|||||||
uploadList = (
|
uploadList = (
|
||||||
<UploadList listType={this.props.listType}
|
<UploadList listType={this.props.listType}
|
||||||
items={this.state.fileList}
|
items={this.state.fileList}
|
||||||
|
onPreview={this.handlePreview}
|
||||||
onRemove={this.handleManualRemove} />
|
onRemove={this.handleManualRemove} />
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -29,8 +29,8 @@ english: Upload
|
|||||||
| beforeUpload | 可选参数, 上传文件之前的钩子,参数为上传的文件,若返回 `false` 或者 Promise 则停止上传。**注意:该方法不支持老 IE**。 | Function | 无 |
|
| beforeUpload | 可选参数, 上传文件之前的钩子,参数为上传的文件,若返回 `false` 或者 Promise 则停止上传。**注意:该方法不支持老 IE**。 | Function | 无 |
|
||||||
| onChange | 可选参数, 上传文件改变时的状态,详见 onChange | Function | 无 |
|
| onChange | 可选参数, 上传文件改变时的状态,详见 onChange | Function | 无 |
|
||||||
| listType | 上传列表的内建样式,支持两种基本样式 `text` or `picture` | String | 'text'|
|
| listType | 上传列表的内建样式,支持两种基本样式 `text` or `picture` | String | 'text'|
|
||||||
| className | 自定义类名 | String | 无 |
|
| onPreview | 点击文件链接时的回调 | Function(file) | 无 |
|
||||||
|
| onRemove | 点击移除文件时的回调 | Function(file) | 无 |
|
||||||
|
|
||||||
### onChange
|
### onChange
|
||||||
|
|
||||||
|
@ -24,10 +24,15 @@ export default class UploadList extends React.Component {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
handleClose(file) {
|
handleClose = (file) => {
|
||||||
this.props.onRemove(file);
|
this.props.onRemove(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handlePreview = (file, e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
return this.props.onPreview(file);
|
||||||
|
}
|
||||||
|
|
||||||
componentDidUpdate() {
|
componentDidUpdate() {
|
||||||
if (this.props.listType !== 'picture' && this.props.listType !== 'picture-card') {
|
if (this.props.listType !== 'picture' && this.props.listType !== 'picture-card') {
|
||||||
return;
|
return;
|
||||||
@ -66,6 +71,7 @@ export default class UploadList extends React.Component {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
icon = (<a className={`${prefixCls}-list-item-thumbnail`}
|
icon = (<a className={`${prefixCls}-list-item-thumbnail`}
|
||||||
|
onClick={(e) => this.handlePreview(file, e)}
|
||||||
href={file.url}
|
href={file.url}
|
||||||
target="_blank"><img src={file.thumbUrl || file.url} alt={file.name} /></a>
|
target="_blank"><img src={file.thumbUrl || file.url} alt={file.name} /></a>
|
||||||
);
|
);
|
||||||
@ -88,13 +94,13 @@ export default class UploadList extends React.Component {
|
|||||||
<div className={`${prefixCls}-list-item-info`}>
|
<div className={`${prefixCls}-list-item-info`}>
|
||||||
{icon}
|
{icon}
|
||||||
{file.url
|
{file.url
|
||||||
? <a href={file.url} target="_blank" className={`${prefixCls}-list-item-name`}>{file.name}</a>
|
? <a onClick={(e) => this.handlePreview(file, e)} href={file.url} target="_blank" className={`${prefixCls}-list-item-name`}>{file.name}</a>
|
||||||
: <span className={`${prefixCls}-list-item-name`}>{file.name}</span>}
|
: <span className={`${prefixCls}-list-item-name`}>{file.name}</span>}
|
||||||
{
|
{
|
||||||
this.props.listType === 'picture-card' && file.status !== 'uploading'
|
this.props.listType === 'picture-card' && file.status !== 'uploading'
|
||||||
? (
|
? (
|
||||||
<span>
|
<span>
|
||||||
<a href={file.url} target="_blank" style={{ pointerEvents: file.url ? '' : 'none' }}><Icon type="eye-o" /></a>
|
<a onClick={(e) => this.handlePreview(file, e)} href={file.url} target="_blank" style={{ pointerEvents: file.url ? '' : 'none' }}><Icon type="eye-o" /></a>
|
||||||
<Icon type="delete" onClick={() => this.handleClose(file)} />
|
<Icon type="delete" onClick={() => this.handleClose(file)} />
|
||||||
</span>
|
</span>
|
||||||
) : <Icon type="cross" onClick={() => this.handleClose(file)} />
|
) : <Icon type="cross" onClick={() => this.handleClose(file)} />
|
||||||
|
Loading…
Reference in New Issue
Block a user