king
2021-09-01 31ec63f0419895876cbaba99637a884a32d33d0d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { Icon, Modal } from 'antd'
 
import zhCN from '@/locales/zh-CN/model.js'
import enUS from '@/locales/en-US/model.js'
import SettingForm from './settingform'
 
import './index.scss'
 
class TreeSettingComponent extends Component {
  static propTpyes = {
    MenuID: PropTypes.string,        // 菜单ID
    config: PropTypes.object,        // 菜单配置信息
    updatesetting: PropTypes.func
  }
 
  state = {
    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    menu: null,          // 菜单信息
    visible: false,      // 模态框控制
    loading: false       // 设置信息验证保存中
  }
 
  /**
   * @description 全局设置触发
   */
  changeSetting = () => {
    const { MenuID, config } = this.props
    let menu = {MenuID: MenuID, MenuName: config.MenuName, MenuNo: config.MenuNo}
 
    this.setState({
      visible: true,
      menu: menu
    })
  }
 
  /**
   * @description 保存页面配置信息
   */
  settingSave = () => {
    const { config } = this.props
 
    this.setState({
      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
      })
 
      this.props.updatesetting({...config, setting: res})
    }, () => {
      this.setState({
        loading: false
      })
    })
  }
 
  /**
   * @description 组件销毁,清除state更新
   */
  componentWillUnmount () {
    this.setState = () => {
      return
    }
  }
 
  render() {
    const { config } = this.props
    const { dict, visible, loading } = this.state
 
    return (
      <div className="model-tree-menu-setting">
        <Icon type="setting" onClick={this.changeSetting} />
        {/* 设置全局配置及列表数据源 */}
        <Modal
          wrapClassName="model-tree-setting-verify-modal"
          title={dict['model.edit']}
          visible={visible}
          width={900}
          maskClosable={false}
          onCancel={() => { this.setState({ visible: false })}}
          confirmLoading={loading}
          onOk={this.settingSave}
          destroyOnClose
        >
          <SettingForm
            dict={dict}
            config={config}
            menu={this.state.menu}
            inputSubmit={this.settingSave}
            wrappedComponentRef={(inst) => this.settingRef = inst}
          />
        </Modal>
      </div>
    )
  }
}
 
export default TreeSettingComponent