import React from 'react'; import { connect } from 'dva'; import { Modal } from 'antd'; class ShowModal extends React.Component { constructor(props) { super(props); this.state = { visible: false, showData: {}, }; }; componentDidMount() { if (this.props.data) { this.setState({ showData: this.props.data, }); if (this.props.data.regClose) { this.props.data.regClose(this.handleCloseModal); } if (this.props.data.show) { this.props.data.show(this.handleShowModal); } } } handleClick = () => { let obj = null; const click = this.props.data.click; if (typeof click === 'function') { obj = click(); } if (obj && obj.isReturn) return; this.handleShowModal(); } handleShowModal = () => { this.setState({ visible: true }); }; handleCloseModal = () => { let obj = null; const close = this.props.data.close; if (typeof close === 'function') { obj = close(); } if (obj && obj.isReturn) return; this.setState({ visible: false }); }; showContent = () => { let showData = this.props.data; if (showData && showData.content) { if (showData.content?.props?.data) { showData.content.props.data.onCancel = this.handleCloseModal } if (typeof showData.content === 'function') { return showData.content(); } return showData.content; } }; render() { return (
{this.props.children} {this.showContent()}
); } } export default connect()(ShowModal);