2015-07-23 22:23:11 +08:00
|
|
|
import React from 'react';
|
|
|
|
import Dialog from 'rc-dialog';
|
2015-06-11 16:35:36 +08:00
|
|
|
function noop() {
|
|
|
|
}
|
2015-06-10 22:02:13 +08:00
|
|
|
|
2015-07-23 22:23:11 +08:00
|
|
|
export default React.createClass({
|
2015-06-12 17:11:32 +08:00
|
|
|
getInitialState() {
|
|
|
|
return {
|
2015-07-22 17:32:22 +08:00
|
|
|
visible: false,
|
|
|
|
confirmLoading: false
|
2015-06-12 17:11:32 +08:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2015-06-10 22:02:13 +08:00
|
|
|
handleCancel() {
|
2015-06-25 15:29:56 +08:00
|
|
|
var d = this.refs.d;
|
|
|
|
d.requestClose();
|
2015-06-10 22:02:13 +08:00
|
|
|
},
|
|
|
|
|
2015-06-11 16:35:36 +08:00
|
|
|
getDefaultProps() {
|
2015-06-10 22:02:13 +08:00
|
|
|
return {
|
2015-06-12 12:01:02 +08:00
|
|
|
prefixCls: 'ant-modal',
|
2015-06-11 16:35:36 +08:00
|
|
|
onOk: noop,
|
2015-06-12 23:46:04 +08:00
|
|
|
onCancel: noop
|
2015-06-10 22:02:13 +08:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2015-07-22 17:32:22 +08:00
|
|
|
handleOk() {
|
2015-06-12 17:11:32 +08:00
|
|
|
this.setState({
|
2015-07-22 17:32:22 +08:00
|
|
|
confirmLoading: true
|
2015-06-12 17:11:32 +08:00
|
|
|
});
|
2015-07-29 15:29:29 +08:00
|
|
|
if (typeof this.props.onOk === 'function') {
|
2015-07-22 17:32:22 +08:00
|
|
|
this.props.onOk();
|
|
|
|
}
|
2015-06-12 17:11:32 +08:00
|
|
|
},
|
|
|
|
|
2015-07-22 17:32:22 +08:00
|
|
|
componentWillReceiveProps(nextProps) {
|
|
|
|
if ('visible' in nextProps) {
|
|
|
|
// 隐藏后去除按钮 loading 效果
|
|
|
|
if (!nextProps.visible) {
|
|
|
|
this.setState({
|
|
|
|
confirmLoading: false
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2015-06-10 22:02:13 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
render() {
|
2015-07-22 17:32:22 +08:00
|
|
|
var loadingIcon = this.state.confirmLoading ?
|
|
|
|
<i className="anticon anticon-loading"></i> : '';
|
2015-06-10 22:02:13 +08:00
|
|
|
var props = this.props;
|
2015-06-12 17:37:39 +08:00
|
|
|
var footer = props.footer || [
|
2015-07-22 17:32:22 +08:00
|
|
|
<button key="cancel" type="button" className="ant-btn ant-btn-lg" onClick={this.handleCancel}>取 消</button>,
|
|
|
|
<button key="confirm" type="button" className="ant-btn ant-btn-primary ant-btn-lg" onClick={this.handleOk}>
|
|
|
|
确 定 {loadingIcon}
|
|
|
|
</button>
|
|
|
|
];
|
|
|
|
return <Dialog transitionName="zoom" onBeforeClose={props.onCancel} visible={this.state.visible} maskAnimation="fade" width="500" footer={footer} {...props} ref="d" />;
|
2015-06-10 17:59:32 +08:00
|
|
|
}
|
2015-06-10 22:02:13 +08:00
|
|
|
});
|