mh-sms-web/src/components/FormModal.js
2024-01-22 09:18:38 +08:00

134 lines
3.5 KiB
JavaScript

import React from 'react'
import { connect } from 'dva'
import { Modal, Form, message } from 'antd'
import FormPage from './FormPage'
import { permissionUtils, getCustomParams } from "../utils/common"
class FormModal extends React.Component {
constructor (props) {
super(props)
this.state = {
visible: false,
loading: false,
formData: {}
}
};
doShowModel = () => {
let isReturn = false
const click = this.props.click
if (typeof click === 'function') {
isReturn = click(true)
}
//未启用
if (this.state.formData.ENABLE_STATUS === 1) {
message.error('当前表单' + this.state.formData.CODE + '已失效,请联系管理员')
isReturn = true
}
if (isReturn)
return
//权限控制
if (!this.state.formData.IS_IGNORE_PERMISSION && !permissionUtils(this.props.login).checkForm(this.state.formData.ID)) {
message.error('您无浏览表单' + this.state.formData.CODE + '的权限,请联系管理员')
isReturn = true
}
if (isReturn)
return
this.setState({
visible: true
}, () => {
const data = this.props.data
this.props.dispatch({
type: 'editPage/save',
payload: {
[data ? data.reloadKey : '']: true
},
})
})
}
showModal = (e) => { // 显示弹窗
e.stopPropagation()
if (!this.state.formData.ID) {
this.fetch(() => {
this.doShowModel()
})
return
}
this.doShowModel()
}
handleCancel = () => { // 退出弹窗
this.props.form.resetFields()
this.setState({
visible: false
})
const click = this.props.click
if (typeof click === 'function') {
click(false)
}
}
fetch = (onComplete) => {
const { formCode, dispatch } = this.props
const orgId = this.props.login.OrgId
const OJson = { 'Key': formCode, 'orgid': orgId }
dispatch({
type: 'app/getFormByRedis',
payload: OJson,
onComplete: (ret) => {
if (ret) {
this.setState({
formData: ret
}, () => {
if (onComplete) {
onComplete()
}
})
}
}
})
}
render () {
let custParams = getCustomParams(this.props.customParams)
const tmpData = {
formCode: this.props.formCode,
data: {
...this.props.data,
close: this.handleCancel,
...custParams,
customParams: this.props.customParams,
formParam: this.props.formParam,
onCancel: this.handleCancel
},
id: this.props.id,
onSave: this.props.onSave,
parentId: this.props.parentId,
copySrcId: this.props.copySrcId,
onCancel: this.handleCancel,
isAddH: this.props.isAddH,
onRegDestroyCacheDataFunc: this.onRegDestroyCacheDataFunc,
}
return (
<div style={{ display: 'inline-block' }}>
<span onClick={this.showModal}>{this.props.children}</span>
<Modal
visible={this.state.visible}
title={this.props.data && this.props.data.isShow ? ('表单[' + this.props.formCode + ']') : ("表单[" + this.props.formCode + "]")}
maskClosable={false}
onCancel={this.handleCancel}
footer={null}
destroyOnClose={this.props.destroyOnClose}
className='antd-modal-fullscreen'
>
<FormPage {...tmpData} />
</Modal>
</div>
)
}
}
export default connect(({ app, loading, login }) => ({ app, loading, login }))(Form.create()(FormModal))