king
2020-06-23 c519b4e51fe07bf13a2a7e44abd648b8dc0c083d
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
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Icon, Modal } from 'antd'
 
import Utils from '@/utils/utils.js'
import zhCN from '@/locales/zh-CN/mob.js'
import enUS from '@/locales/en-US/mob.js'
import VerifyCard from './verifycard'
import './index.scss'
 
class DataSource extends Component {
  static propTpyes = {
    config: PropTypes.any,
    updateConfig: PropTypes.func
  }
 
  state = {
    dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    sourcelist: [],
    visible: false,
    source: null
  }
 
  UNSAFE_componentWillReceiveProps(nextProps) {
 
  }
 
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
  }
 
  editDataSource = (item) => {
    if (!item) {
      item = {
        uuid: Utils.getuuid()
      }
    }
 
    this.setState({
      visible: true,
      source: item
    })
  }
 
  closeDataSource = () => {
 
  }
 
  render () {
    const { sourcelist, visible, source, dict } = this.state
 
    return (
      <div className="mob-datasource">
        {sourcelist.map(item => (
          <span className="mob-input-group-wrapper" key={item.uuid}>
            <span className="mob-input-wrapper">
              <span className="mob-input-value">{item.label}</span>
              <span className="mob-input-group-addon">
                <Icon type="setting" onClick={() => this.editDataSource(item)} />
                <Icon type="close" onClick={() => this.closeDataSource(item)} />
              </span>
            </span>
          </span>
        ))}
        <span className="mob-input-group-wrapper">
          <span className="mob-input-wrapper">
            <span className="mob-input-insert" onClick={() => this.editDataSource()}>
              <Icon type="plus" />
            </span>
          </span>
        </span>
        <Modal
          wrapClassName="mob-datasource-verify-modal"
          title={'数据源配置'}
          visible={visible}
          width={'75vw'}
          maskClosable={false}
          style={{minWidth: '900px', maxWidth: '1200px'}}
          okText={dict['mob.submit']}
          onOk={this.verifySubmit}
          onCancel={() => { this.setState({ visible: false }) }}
          destroyOnClose
        >
          <VerifyCard
            card={source}
            dict={dict}
            wrappedComponentRef={(inst) => this.verifyRef = inst}
          />
        </Modal>
      </div>
    )
  }
}
 
export default DataSource