king
2020-09-04 b987be8dd8b6bc1fa01810daa1e1a60e58a3c921
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
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Icon, Modal } from 'antd'
 
import zhCN from '@/locales/zh-CN/model.js'
import enUS from '@/locales/en-US/model.js'
import VerifyCard from './verifycard'
import './index.scss'
 
class DataSource extends Component {
  static propTpyes = {
    config: PropTypes.any,
    menu: PropTypes.object,
    updateConfig: PropTypes.func
  }
 
  state = {
    dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    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 => {
 
      this.setState({loading: false, visible: false})
      this.props.updateConfig({...config, ...res})
    }, () => {
      this.setState({loading: false})
    })
  }
 
  render () {
    const { config, menu } = this.props
    const { visible, dict, loading } = this.state
 
    return (
      <div className="model-datasource">
        <Icon type="setting" onClick={() => this.editDataSource()} />
        <Modal
          wrapClassName="model-datasource-verify-modal popview-modal"
          title={'数据源配置'}
          visible={visible}
          width={'75vw'}
          maskClosable={false}
          style={{minWidth: '900px', maxWidth: '1200px'}}
          okText={dict['model.submit']}
          onOk={this.verifySubmit}
          confirmLoading={loading}
          onCancel={() => { this.setState({ visible: false }) }}
          destroyOnClose
        >
          <VerifyCard
            dict={dict}
            menu={menu}
            config={config}
            wrappedComponentRef={(inst) => this.verifyRef = inst}
          />
        </Modal>
      </div>
    )
  }
}
 
export default DataSource