king
2023-08-27 d340a56429b12c3c893762730638631e147e047c
src/templates/sharecomponent/settingcomponent/index.jsx
@@ -4,15 +4,9 @@
import { Modal, Button } from 'antd'
import { SettingOutlined } from '@ant-design/icons'
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'
// import './index.scss'
class SettingComponent extends Component {
  static propTpyes = {
@@ -23,12 +17,13 @@
  }
  state = {
    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    menu: null,          // 菜单信息
    search: null,        // 搜索条件,包括主表搜索
    formlist: null,      // 表单信息
    visible: false,      // 模态框控制
    loading: false       // 设置信息验证保存中
    loading: false,      // 设置信息验证保存中
    record: null
  }
  /**
@@ -61,13 +56,11 @@
      loading: true
    })
    this.settingRef.handleConfirm().then(setting => {
      let res = this.resetSetting(setting)
      let res = this.resetSetting(setting, config.setting)
      this.setState({
        visible: false,
        loading: false
      })
      res.actionfixed = res.actionfixed === 'true'
      res.columnfixed = res.columnfixed === 'true'
      this.props.updatesetting({...config, setting: res})
    }, () => {
@@ -77,51 +70,38 @@
    })
  }
  /**
   * @description 创建表格存储过程
   */
  tableCreatFunc = () => {
    const { config } = this.props
    const { menu } = this.state
  // /**
  //  * @description 创建表格接口(读出)
  //  */
  // tableCreatInterface = () => {
  //   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.settingRef.handleConfirm('loading').then(setting => {
  //     let res = this.resetSetting(setting, config.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.funcCreatComponent.exec(setting.innerFunc, newLText, DelText).then(result => {
        if (result === 'success') {
          this.props.updatesetting(_config)
        }
      })
    })
  }
  //     this.refs.tableCreatInterface.triggerOutInterface(_menu, _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) => {
  resetSetting = (s, ori) => {
    let setting = fromJS(s).toJS()
    let maxScript = 0
    setting.show = ori.show || 'true'
    setting.advanceType = ori.advanceType || 'modal'
    setting.advanceWidth = ori.advanceWidth || 1000
    setting.drawerPlacement = ori.drawerPlacement || 'right'
    setting.searchRatio = ori.searchRatio || 6
    setting.searchLwidth = ori.searchLwidth !== undefined ? ori.searchLwidth : 33.3
    setting.resetContrl = ori.resetContrl || 'init'
    if (window.GLOB.funcs && window.GLOB.funcs.length > 0) {
      window.GLOB.funcs.forEach(m => {
@@ -147,6 +127,16 @@
          setting.dataresource = setting.dataresource.replace(reg, `/*$ex@${m.func_code}-begin*/\n${m.key_sql}\n/*@ex$-end*/`)
        }
      })
    } else {
      setting.scripts.forEach(item => {
        if (item.status === 'false') return
        if (/exec\s/ig.test(item.sql)) {
          maxScript = 1000
        } else if (item.sql.length > maxScript) {
          maxScript = item.sql.length
        }
      })
    }
    setting.maxScript = maxScript
@@ -169,36 +159,33 @@
  render() {
    const { config } = this.props
    const { dict, visible, search, menu } = this.state
    const { visible, search, menu } = this.state
    return (
      <div className="model-menu-setting">
        <SettingOutlined onClick={this.changeSetting} />
      <>
        <SettingOutlined style={{position: 'absolute', fontSize: '18px', right: '7px', top: '5px', padding: '10px', zIndex: 1}} onClick={this.changeSetting} />
        {/* 设置全局配置及列表数据源 */}
        <Modal
          wrapClassName="model-table-setting-verify-modal"
          title={dict['model.edit']}
          wrapClassName="mk-pop-modal"
          visible={visible}
          width={900}
          width={'75vw'}
          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>
            <Button key="cancel" onClick={() => { this.setState({ visible: false, loading: false }) }}>取消</Button>,
            <Button key="confirm" type="primary" loading={this.state.loading} onClick={this.settingSave}>确定</Button>
          ]}
          destroyOnClose
        >
          <SettingForm
            dict={dict}
            menu={menu}
            config={config}
            search={search}
            updRecord={() => {}}
            wrappedComponentRef={(inst) => this.settingRef = inst}
          />
        </Modal>
      </div>
      </>
    )
  }
}