2016-03-31 09:40:55 +08:00
|
|
|
---
|
|
|
|
order: 1
|
|
|
|
title: 异步关闭
|
|
|
|
---
|
2015-06-12 17:11:32 +08:00
|
|
|
|
2015-10-27 19:57:18 +08:00
|
|
|
点击确定后异步关闭对话框,例如提交表单。
|
2015-06-12 17:11:32 +08:00
|
|
|
|
|
|
|
````jsx
|
2015-10-28 20:55:49 +08:00
|
|
|
import { Modal, Button } from 'antd';
|
2015-10-08 15:13:04 +08:00
|
|
|
|
2015-10-28 20:55:49 +08:00
|
|
|
const Test = React.createClass({
|
2015-06-12 17:11:32 +08:00
|
|
|
getInitialState() {
|
|
|
|
return {
|
2015-06-12 23:31:44 +08:00
|
|
|
ModalText: '对话框的内容',
|
2015-06-14 13:20:35 +08:00
|
|
|
visible: false
|
2015-06-12 17:11:32 +08:00
|
|
|
};
|
|
|
|
},
|
2015-08-18 12:26:19 +08:00
|
|
|
showModal() {
|
2015-06-12 23:31:44 +08:00
|
|
|
this.setState({
|
2015-08-18 12:26:19 +08:00
|
|
|
visible: true
|
2015-06-12 23:31:44 +08:00
|
|
|
});
|
2015-06-12 17:11:32 +08:00
|
|
|
},
|
|
|
|
handleOk() {
|
|
|
|
this.setState({
|
2015-10-27 19:57:18 +08:00
|
|
|
ModalText: '对话框将在两秒后关闭',
|
|
|
|
confirmLoading: true
|
2015-06-12 17:11:32 +08:00
|
|
|
});
|
2015-08-25 17:08:43 +08:00
|
|
|
setTimeout(() => {
|
2015-06-12 23:31:44 +08:00
|
|
|
this.setState({
|
2015-10-27 19:57:18 +08:00
|
|
|
visible: false,
|
|
|
|
confirmLoading: false
|
2015-06-12 23:31:44 +08:00
|
|
|
});
|
2015-08-25 17:08:43 +08:00
|
|
|
}, 2000);
|
2015-06-12 17:11:32 +08:00
|
|
|
},
|
|
|
|
handleCancel() {
|
|
|
|
console.log('点击了取消');
|
2015-09-08 12:38:21 +08:00
|
|
|
this.setState({
|
|
|
|
visible: false
|
|
|
|
});
|
2015-06-12 17:11:32 +08:00
|
|
|
},
|
|
|
|
render() {
|
2016-01-07 16:29:12 +08:00
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<Button type="primary" onClick={this.showModal}>显示对话框</Button>
|
|
|
|
<Modal title="对话框标题"
|
2016-01-08 14:41:05 +08:00
|
|
|
visible={this.state.visible}
|
|
|
|
onOk={this.handleOk}
|
|
|
|
confirmLoading={this.state.confirmLoading}
|
|
|
|
onCancel={this.handleCancel}>
|
2016-01-07 16:29:12 +08:00
|
|
|
<p>{this.state.ModalText}</p>
|
|
|
|
</Modal>
|
|
|
|
</div>
|
|
|
|
);
|
2015-06-12 17:11:32 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-02-22 10:52:30 +08:00
|
|
|
ReactDOM.render(<Test />, mountNode);
|
2015-06-12 17:11:32 +08:00
|
|
|
````
|