king
2022-10-25 5891206952e2ff63e87aed2f47df5324b019d32e
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
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Modal } from 'antd'
import { SettingOutlined } from '@ant-design/icons'
 
import VerifyCard from './verifycard'
import './index.scss'
 
class DataSource extends Component {
  static propTpyes = {
    config: PropTypes.any,
    MenuID: PropTypes.string,
    updateConfig: PropTypes.func
  }
 
  state = {
    sourcelist: [],
    visible: false,
    loading: false,
    setting: null
  }
 
  UNSAFE_componentWillMount () {
    const { config } = this.props
 
    this.setState({setting: fromJS(config.setting).toJS()})
  }
 
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
  }
 
  editDataSource = () => {
    this.setState({
      visible: true
    })
  }
 
  verifySubmit = () => {
    const { config } = this.props
 
    this.setState({loading: true})
    this.verifyRef.submitDataSource().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.setting.dataresource) {
            res.setting.dataresource = res.setting.dataresource.replace(reg, `/*$ex@${m.func_code}-begin*/\n${m.key_sql}\n/*@ex$-end*/`)
          }
        })
      }
 
      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.setState({loading: false, visible: false})
      this.props.updateConfig({...config, ...res})
    }, () => {
      this.setState({loading: false})
    })
  }
 
  render () {
    const { config } = this.props
    const { visible, loading } = this.state
 
    return (
      <div className="model-datasource">
        <SettingOutlined onClick={() => this.editDataSource()} />
        <Modal
          wrapClassName="mk-pop-modal"
          visible={visible}
          width={'75vw'}
          maskClosable={false}
          okText="提交"
          onOk={this.verifySubmit}
          confirmLoading={loading}
          onCancel={() => { this.setState({ visible: false }) }}
          destroyOnClose
        >
          <VerifyCard
            config={config}
            menuId={this.props.config.uuid}
            searches={config.search}
            wrappedComponentRef={(inst) => this.verifyRef = inst}
          />
        </Modal>
      </div>
    )
  }
}
 
export default DataSource