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
|