king
2022-10-17 e8edfdadb561cd83bf6e1c3e00d55b8cc2aee6d5
src/templates/sharecomponent/treesettingcomponent/index.jsx
@@ -1,16 +1,10 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { fromJS } from 'immutable'
import { Icon, Modal, Button, notification } from 'antd'
import Utils from '@/utils/utils.js'
import zhCN from '@/locales/zh-CN/model.js'
import enUS from '@/locales/en-US/model.js'
import { getTreeSettingForm } from '@/templates/zshare/formconfig'
import { Modal } from 'antd'
import { SettingOutlined } from '@ant-design/icons'
import SettingForm from './settingform'
import CreateFunc from '@/templates/zshare/createfunc'
import CreateInterface from '@/templates/zshare/createinterface'
import MKEmitter from '@/utils/events.js'
import './index.scss'
@@ -18,15 +12,11 @@
  static propTpyes = {
    MenuID: PropTypes.string,        // 菜单ID
    config: PropTypes.object,        // 菜单配置信息
    permFuncField: PropTypes.array,  // 存储过程可用开头字段
    menuformRef: PropTypes.any,      // 菜单基本信息表单
    updatesetting: PropTypes.func
  }
  state = {
    dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    menu: null,          // 菜单信息
    formlist: null,      // 表单信息
    visible: false,      // 模态框控制
    loading: false       // 设置信息验证保存中
  }
@@ -35,21 +25,14 @@
   * @description 全局设置触发
   */
  changeSetting = () => {
    const { menuformRef, MenuID, config, permFuncField } = this.props
    let menu = {MenuID: MenuID}
    if (menuformRef) {
      menu = {MenuID: MenuID, MenuName: menuformRef.props.form.getFieldValue('MenuName') || '', MenuNo: menuformRef.props.form.getFieldValue('MenuNo') || ''}
    }
    let _config = fromJS(config).toJS()
    const { MenuID, config } = this.props
    let menu = {MenuID: MenuID, MenuName: config.MenuName, MenuNo: config.MenuNo}
    this.setState({
      visible: true,
      formlist: getTreeSettingForm(config.setting, permFuncField, MenuID),
      menu: menu,
      config: _config
      menu: menu
    })
    MKEmitter.emit('modalStatus', '数据源')
  }
  /**
@@ -62,74 +45,36 @@
      loading: true
    })
    this.settingRef.handleConfirm().then(res => {
      if (window.GLOB.funcs && window.GLOB.funcs.length > 0) {
        window.GLOB.funcs.forEach(m => {
          let reg = new RegExp('\\$ex@' + m.func_code + '@ex\\$', 'ig')
          res.scripts.forEach(item => {
            item.sql = item.sql.replace(reg, `/*$ex@${m.func_code}-begin*/\n${m.key_sql}\n/*@ex$-end*/`)
          })
          if (res.dataresource) {
            res.dataresource = res.dataresource.replace(reg, `/*$ex@${m.func_code}-begin*/\n${m.key_sql}\n/*@ex$-end*/`)
          }
        })
      }
      this.setState({
        visible: false,
        loading: false
      })
      res.show = config.setting.show || 'true'
      res.advanceType = config.setting.advanceType || 'modal'
      res.advanceWidth = config.setting.advanceWidth || 1000
      res.drawerPlacement = config.setting.drawerPlacement || 'right'
      res.searchRatio = config.setting.searchRatio || 6
      res.searchLwidth = config.setting.searchLwidth !== undefined ? config.setting.searchLwidth : 33.3
      this.props.updatesetting({...config, setting: res})
      MKEmitter.emit('modalStatus', false)
    }, () => {
      this.setState({
        loading: false
      })
    })
  }
  /**
   * @description 创建表格存储过程
   */
  tableCreatFunc = () => {
    const { config } = this.props
    const { menu } = this.state
    this.settingRef.handleConfirm().then(setting => {
      if (!(setting.interType === 'inner') || !setting.innerFunc) {
        notification.warning({
          top: 92,
          message: '接口类型为-内部,且存在内部函数时,才可以创建存储过程!',
          duration: 5
        })
        return
      }
      let _config = {...config, setting: setting}
      let newLText = Utils.formatOptions(Utils.getTableFunc(setting, menu, _config)) // 创建存储过程sql
      let DelText = Utils.formatOptions(Utils.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().then(setting => {
      if (setting.interType !== 'inner' || setting.innerFunc) {
        notification.warning({
          top: 92,
          message: '接口类型为-内部,且不存在内部函数时,才可以创建接口!',
          duration: 5
        })
        return
      }
      let _config = {...config, setting: setting}
      let _menu = {
        type: 'main',
        MenuID: menu.MenuID,
        menuName: menu.MenuName,
        menuNo: menu.MenuNo
      }
      this.refs.tableCreatInterface.triggerOutInterface(_menu, _config)
    })
  }
@@ -143,33 +88,27 @@
  }
  render() {
    const { dict, visible, config } = this.state
    const { config } = this.props
    const { visible, loading } = this.state
    return (
      <div className="model-tree-menu-setting">
        <Icon type="setting" onClick={this.changeSetting} />
        <SettingOutlined onClick={this.changeSetting} />
        {/* 设置全局配置及列表数据源 */}
        <Modal
          wrapClassName="model-tree-setting-verify-modal"
          title={dict['model.edit']}
          wrapClassName="mk-pop-modal"
          visible={visible}
          width={900}
          width={'75vw'}
          maskClosable={false}
          onCancel={() => { this.setState({ visible: false })}}
          footer={[
            <CreateInterface key="interface" 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 }) }}>{this.state.dict['header.cancel']}</Button>,
            <Button key="confirm" type="primary" loading={this.state.loading} onClick={this.settingSave}>{this.state.dict['model.confirm']}</Button>
          ]}
          onCancel={() => { MKEmitter.emit('modalStatus', false); this.setState({ visible: false })}}
          confirmLoading={loading}
          onOk={this.settingSave}
          destroyOnClose
        >
          <SettingForm
            dict={dict}
            config={config}
            menu={this.state.menu}
            inputSubmit={this.settingSave}
            formlist={this.state.formlist}
            wrappedComponentRef={(inst) => this.settingRef = inst}
          />
        </Modal>