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 SettingForm from './settingform'
|
import './index.scss'
|
|
class DataSource extends Component {
|
static propTpyes = {
|
config: PropTypes.any,
|
updateConfig: PropTypes.func
|
}
|
|
state = {
|
dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
|
visible: 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.verifyRef.handleConfirm().then(res => {
|
|
this.setState({
|
setting: res,
|
visible: false
|
})
|
this.props.updateConfig({...config, setting: res})
|
})
|
}
|
|
render () {
|
const { visible, dict, setting } = this.state
|
|
return (
|
<div className="model-menu-setting-wrap">
|
<Icon type="edit" onClick={() => this.editDataSource()} />
|
<Modal
|
wrapClassName="popview-modal"
|
title={'标签页配置'}
|
visible={visible}
|
width={700}
|
maskClosable={false}
|
okText={dict['model.submit']}
|
onOk={this.verifySubmit}
|
onCancel={() => { this.setState({ visible: false }) }}
|
destroyOnClose
|
>
|
<SettingForm
|
dict={dict}
|
setting={setting}
|
inputSubmit={this.verifySubmit}
|
wrappedComponentRef={(inst) => this.verifyRef = inst}
|
/>
|
</Modal>
|
</div>
|
)
|
}
|
}
|
|
export default DataSource
|