import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { is, fromJS } from 'immutable'
|
import { Modal, Button, notification } from 'antd'
|
|
import SettingForm from './settingform'
|
import './index.scss'
|
|
class BaseScript extends Component {
|
static propTpyes = {
|
config: PropTypes.object,
|
updateConfig: PropTypes.func
|
}
|
|
state = {
|
visible: false,
|
baseSql: null
|
}
|
|
shouldComponentUpdate (nextProps, nextState) {
|
return !is(fromJS(this.state), fromJS(nextState))
|
}
|
|
trigger = () => {
|
const { config } = this.props
|
|
this.setState({
|
baseSql: config.baseSql || {enable: true, sql: ''},
|
visible: true
|
})
|
}
|
|
submit = () => {
|
let config = fromJS(this.props.config).toJS()
|
|
this.settingRef.handleConfirm().then(res => {
|
if (res.enable && (!res.sql || /^\s+$/ig.test(res.sql))) {
|
notification.warning({
|
top: 92,
|
message: '启用基础SQL时,请完善sql语句。',
|
duration: 5
|
})
|
return
|
}
|
|
config.baseSql = res
|
this.props.updateConfig(config)
|
this.setState({ visible: false })
|
})
|
}
|
|
render() {
|
const { visible, baseSql } = this.state
|
|
return (
|
<div style={{display: 'inline-block'}}>
|
<Button className="mk-border-danger" icon="database" onClick={this.trigger}>基础SQL</Button>
|
<Modal
|
title="基础SQL"
|
wrapClassName="base-script-modal"
|
visible={visible}
|
width={800}
|
maskClosable={false}
|
onOk={this.submit}
|
onCancel={() => { this.setState({ visible: false })}}
|
destroyOnClose
|
>
|
<SettingForm baseSql={baseSql} wrappedComponentRef={(inst) => this.settingRef = inst}/>
|
</Modal>
|
</div>
|
)
|
}
|
}
|
|
export default BaseScript
|