import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { is, fromJS } from 'immutable'
|
import { Icon, Modal, Button } from 'antd'
|
|
import Utils, { FuncUtils } from '@/utils/utils.js'
|
import zhCN from '@/locales/zh-CN/model.js'
|
import enUS from '@/locales/en-US/model.js'
|
|
import SettingForm from './settingform'
|
import CreateFunc from '@/templates/zshare/createfunc'
|
import CreateInterface from '@/templates/zshare/createinterface'
|
|
import './index.scss'
|
|
class SettingComponent extends Component {
|
static propTpyes = {
|
mainsearch: PropTypes.any, // 主表的搜索条件,当子表设置接收主表条件时有效
|
MenuID: PropTypes.string, // 菜单ID
|
config: PropTypes.object, // 菜单配置信息
|
updatesetting: PropTypes.func
|
}
|
|
state = {
|
dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
|
menu: null, // 菜单信息
|
search: null, // 搜索条件,包括主表搜索
|
formlist: null, // 表单信息
|
visible: false, // 模态框控制
|
loading: false // 设置信息验证保存中
|
}
|
|
/**
|
* @description 全局设置触发
|
*/
|
changeSetting = () => {
|
const { MenuID, config, mainsearch } = this.props
|
let menu = { MenuID: MenuID, MenuName: config.MenuName || config.tabName || '', MenuNo: config.MenuNo || config.tabNo || '' }
|
|
let _search = fromJS(config.search).toJS()
|
|
if (mainsearch) { // 综合主页搜索及子表搜索条件
|
_search = [...mainsearch, ..._search]
|
}
|
|
this.setState({
|
visible: true,
|
search: _search,
|
menu: menu
|
})
|
}
|
|
/**
|
* @description 保存页面配置信息
|
*/
|
settingSave = () => {
|
const { config } = this.props
|
|
this.setState({
|
loading: true
|
})
|
this.settingRef.handleConfirm().then(setting => {
|
let res = this.resetSetting(setting)
|
this.setState({
|
visible: false,
|
loading: false
|
})
|
res.actionfixed = res.actionfixed === 'true'
|
res.columnfixed = res.columnfixed === 'true'
|
|
this.props.updatesetting({...config, setting: res})
|
}, () => {
|
this.setState({
|
loading: false
|
})
|
})
|
}
|
|
/**
|
* @description 创建表格存储过程
|
*/
|
tableCreatFunc = () => {
|
const { config } = this.props
|
const { menu } = this.state
|
|
this.settingRef.handleConfirm('func').then(setting => {
|
let res = this.resetSetting(setting)
|
let _config = {...config, setting: res}
|
let newLText = Utils.formatOptions(FuncUtils.getTableFunc(setting, menu, _config)) // 创建存储过程sql
|
let DelText = Utils.formatOptions(FuncUtils.dropfunc(setting.innerFunc)) // 删除存储过程sql
|
|
this.refs.funcCreatComponent.exec(setting.innerFunc, newLText, DelText).then(result => {
|
if (result === 'success') {
|
this.props.updatesetting(_config)
|
}
|
})
|
})
|
}
|
|
/**
|
* @description 创建表格接口(读出)
|
*/
|
tableCreatInterface = () => {
|
const { config } = this.props
|
const { menu } = this.state
|
|
this.settingRef.handleConfirm('interface').then(setting => {
|
let res = this.resetSetting(setting)
|
let _config = {...config, setting: res}
|
let _menu = {
|
type: config.Template === 'CommonTable' ? 'main' : 'subtable',
|
MenuID: menu.MenuID,
|
menuName: menu.MenuName,
|
menuNo: menu.MenuNo
|
}
|
|
this.refs.tableCreatInterface.triggerOutInterface(_menu, _config)
|
})
|
}
|
|
resetSetting = (s) => {
|
let setting = fromJS(s).toJS()
|
let maxScript = 0
|
|
if (window.GLOB.funcs && window.GLOB.funcs.length > 0) {
|
window.GLOB.funcs.forEach(m => {
|
let reg = new RegExp('\\$ex@' + m.func_code + '@ex\\$', 'ig')
|
setting.scripts.forEach(item => {
|
item.sql = item.sql.replace(reg, `/*$ex@${m.func_code}-begin*/\n${m.key_sql}\n/*@ex$-end*/`)
|
|
if (item.status === 'false') return
|
|
if (/exec\s/ig.test(item.sql)) {
|
maxScript = 100
|
} else if (item.sql.length > maxScript) {
|
maxScript = item.sql.length
|
}
|
})
|
setting.preScripts.forEach(item => {
|
item.sql = item.sql.replace(reg, `/*$ex@${m.func_code}-begin*/\n${m.key_sql}\n/*@ex$-end*/`)
|
})
|
setting.cbScripts.forEach(item => {
|
item.sql = item.sql.replace(reg, `/*$ex@${m.func_code}-begin*/\n${m.key_sql}\n/*@ex$-end*/`)
|
})
|
if (setting.dataresource) {
|
setting.dataresource = setting.dataresource.replace(reg, `/*$ex@${m.func_code}-begin*/\n${m.key_sql}\n/*@ex$-end*/`)
|
}
|
})
|
}
|
|
setting.maxScript = maxScript
|
|
return setting
|
}
|
|
shouldComponentUpdate (nextProps, nextState) {
|
return !is(fromJS(this.state), fromJS(nextState))
|
}
|
|
/**
|
* @description 组件销毁,清除state更新
|
*/
|
componentWillUnmount () {
|
this.setState = () => {
|
return
|
}
|
}
|
|
render() {
|
const { config } = this.props
|
const { dict, visible, search, menu } = this.state
|
|
return (
|
<div className="model-menu-setting">
|
<Icon type="setting" onClick={this.changeSetting} />
|
{/* 设置全局配置及列表数据源 */}
|
<Modal
|
wrapClassName="model-table-setting-verify-modal"
|
title={dict['model.edit']}
|
visible={visible}
|
width={900}
|
maskClosable={false}
|
onCancel={() => { this.setState({ visible: false, loading: false })}}
|
footer={[
|
<CreateInterface key="interface" loading={this.state.interloading} dict={dict} ref="tableCreatInterface" trigger={this.tableCreatInterface}/>,
|
<CreateFunc key="create" dict={dict} ref="funcCreatComponent" trigger={this.tableCreatFunc}/>,
|
<Button key="cancel" onClick={() => { this.setState({ visible: false, loading: false }) }}>{this.state.dict['model.cancel']}</Button>,
|
<Button key="confirm" type="primary" loading={this.state.loading} onClick={this.settingSave}>{this.state.dict['model.confirm']}</Button>
|
]}
|
destroyOnClose
|
>
|
<SettingForm
|
dict={dict}
|
menu={menu}
|
config={config}
|
search={search}
|
wrappedComponentRef={(inst) => this.settingRef = inst}
|
/>
|
</Modal>
|
</div>
|
)
|
}
|
}
|
|
export default SettingComponent
|