mh_jy_safe_web/src/components/common/ShowModal.js

88 lines
2.3 KiB
JavaScript

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 (
<div style={{ display: "inline-block" }}>
<span onClick={this.handleClick}>{this.props.children}</span>
<Modal
title={this.props.title === "新增" ? this.props.title + "-" + ((this.props.login != null && this.props.login.currActivatedMenu != null) ? this.props.login.currActivatedMenu.NAME : '') + ((this.props.login != null && this.props.login.currActivatedMenu != null && this.props.login.currActivatedMenu.Nav_MenuForm != null) ? ("[" + this.props.login.currActivatedMenu?.Nav_MenuForm?.CODE + "]") : '') : this.props.title}
visible={this.state.visible}
onCancel={this.handleCloseModal}
maskClosable={false}
footer={null}
className='antd-modal-fullscreen'
>
{this.showContent()}
</Modal>
</div>
);
}
}
export default connect()(ShowModal);