|
|
@ -4,22 +4,26 @@ function noop() { |
|
|
|
} |
|
|
|
|
|
|
|
export default React.createClass({ |
|
|
|
getDefaultProps() { |
|
|
|
return { |
|
|
|
prefixCls: 'ant-modal', |
|
|
|
onOk: noop, |
|
|
|
onCancel: noop |
|
|
|
}; |
|
|
|
}, |
|
|
|
|
|
|
|
getInitialState() { |
|
|
|
return { |
|
|
|
confirmLoading: false |
|
|
|
confirmLoading: false, |
|
|
|
visible: this.props.visible |
|
|
|
}; |
|
|
|
}, |
|
|
|
|
|
|
|
handleCancel() { |
|
|
|
this.props.onCancel(); |
|
|
|
}, |
|
|
|
|
|
|
|
getDefaultProps() { |
|
|
|
return { |
|
|
|
prefixCls: 'ant-modal', |
|
|
|
onOk: noop, |
|
|
|
onCancel: noop |
|
|
|
}; |
|
|
|
this.setState({ |
|
|
|
visible: false |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
handleOk() { |
|
|
@ -31,27 +35,32 @@ export default React.createClass({ |
|
|
|
|
|
|
|
componentWillReceiveProps(nextProps) { |
|
|
|
if ('visible' in nextProps) { |
|
|
|
let newState = { |
|
|
|
visible: nextProps.visible |
|
|
|
}; |
|
|
|
// 隐藏后去除按钮 loading 效果 |
|
|
|
if (!nextProps.visible) { |
|
|
|
this.setState({ |
|
|
|
confirmLoading: false |
|
|
|
}); |
|
|
|
newState.confirmLoading = false; |
|
|
|
} |
|
|
|
this.setState(newState); |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
render() { |
|
|
|
var loadingIcon = this.state.confirmLoading ? |
|
|
|
<i className="anticon anticon-loading"></i> : ''; |
|
|
|
var props = this.props; |
|
|
|
var defaultFooter = [ |
|
|
|
let loadingClass = this.state.confirmLoading ? ' ant-btn-loading' : ''; |
|
|
|
let props = this.props; |
|
|
|
let defaultFooter = [ |
|
|
|
<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 key="confirm" |
|
|
|
type="button" |
|
|
|
className={'ant-btn ant-btn-primary ant-btn-lg' + loadingClass} |
|
|
|
onClick={this.handleOk}> |
|
|
|
确 定 |
|
|
|
</button> |
|
|
|
]; |
|
|
|
var footer = props.footer || defaultFooter; |
|
|
|
return <Dialog transitionName="zoom" onClose={props.onCancel} visible={this.state.visible} |
|
|
|
maskAnimation="fade" width="500" footer={footer} {...props}/>; |
|
|
|
let footer = props.footer || defaultFooter; |
|
|
|
let visible = this.state.visible; |
|
|
|
return <Dialog transitionName="zoom" onClose={this.handleCancel} maskAnimation="fade" |
|
|
|
width="500" footer={footer} {...props} visible={visible} />; |
|
|
|
} |
|
|
|
}); |
|
|
|