import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import {connect} from 'react-redux'
|
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,
|
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.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="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>
|
)
|
}
|
}
|
|
const mapStateToProps = (state) => {
|
return {
|
menu: state.customMenu
|
}
|
}
|
|
const mapDispatchToProps = () => {
|
return {}
|
}
|
|
export default connect(mapStateToProps, mapDispatchToProps)(DataSource)
|