king
2021-01-24 d36c27e80e668b3bc1dcd687a18a2f2d125b32db
src/templates/sharecomponent/settingcomponent/settingform/index.jsx
@@ -7,11 +7,13 @@
import Api from '@/api'
import Utils from '@/utils/utils.js'
import SettingUtils from './utils.jsx'
import CustomScript from '@/templates/zshare/customscript'
import asyncComponent from '@/utils/asyncComponent'
import DataSource from './datasource'
import './index.scss'
const { TabPane } = Tabs
const CustomScript = asyncComponent(() => import('@/templates/zshare/customscript'))
const SimpleScript = asyncComponent(() => import('./simplescript'))
class SettingForm extends Component {
  static propTpyes = {
@@ -37,6 +39,8 @@
    let _setting = fromJS(config.setting).toJS()
    let _scripts = _setting.scripts || []
    let _preScripts = _setting.preScripts || []
    let _cbScripts = _setting.cbScripts || []
    _setting.default = _setting.default || 'true'            // 默认sql
    _setting.sysInterface = _setting.sysInterface || 'false' // 是否为系统接口
@@ -82,7 +86,9 @@
      arr_field: arr_field.join(','),
      regoptions: Utils.getRegOptions(search), // 搜索条件,正则替换
      columns: columns,
      scripts: _scripts
      scripts: _scripts,
      preScripts: _preScripts,
      cbScripts: _cbScripts
    })
  }
@@ -143,6 +149,24 @@
  handleConfirm = (trigger) => {
    const { activeKey, setting, scripts } = this.state
    let _loading = false
    if (this.scriptsForm && this.scriptsForm.props.form.getFieldValue('sql')) {
      _loading = true
    } else if (this.preScriptsForm && this.preScriptsForm.props.form.getFieldValue('sql')) {
      _loading = true
    } else if (this.cbScriptsForm && this.cbScriptsForm.props.form.getFieldValue('sql')) {
      _loading = true
    }
    if (_loading) {
      notification.warning({
        top: 92,
        message: '存在未保存脚本,请点击确定保存,或点击取消放弃修改!',
        duration: 5
      })
      return
    }
    if (trigger) {
      this.setState({loading: true})
    }
@@ -199,25 +223,10 @@
      })
    } else {
      return new Promise((resolve, reject) => {
        let _loading = false
        if (this.scriptsForm && this.scriptsForm.state.editItem) {
          _loading = true
        } else if (this.scriptsForm && this.scriptsForm.props.form.getFieldValue('sql')) {
          _loading = true
        }
        if (trigger === 'func' && setting.interType !== 'inner') {
          notification.warning({
            top: 92,
            message: '使用内部接口,才可以创建存储过程!',
            duration: 5
          })
          this.setState({loading: false})
          reject()
        } else if (_loading) {
          notification.warning({
            top: 92,
            message: '存在未保存脚本,请点击确定保存,或点击取消放弃修改!',
            duration: 5
          })
          this.setState({loading: false})
@@ -289,6 +298,24 @@
  changeTab = (val) => {
    const { activeKey, search, arr_field } = this.state
    let _loading = false
    if (this.scriptsForm && this.scriptsForm.props.form.getFieldValue('sql')) {
      _loading = true
    } else if (this.preScriptsForm && this.preScriptsForm.props.form.getFieldValue('sql')) {
      _loading = true
    } else if (this.cbScriptsForm && this.cbScriptsForm.props.form.getFieldValue('sql')) {
      _loading = true
    }
    if (_loading) {
      notification.warning({
        top: 92,
        message: '存在未保存脚本,请点击确定保存,或点击取消放弃修改!',
        duration: 5
      })
      return
    }
    if (activeKey === 'setting') {
      let _defaultSql = ''
      this.settingForm.handleConfirm().then(res => {
@@ -330,22 +357,6 @@
        })
      })
    } else if (activeKey === 'scripts') {
      let _loading = false
      if (this.scriptsForm && this.scriptsForm.state.editItem) {
        _loading = true
      } else if (this.scriptsForm && this.scriptsForm.props.form.getFieldValue('sql')) {
        _loading = true
      }
      if (_loading) {
        notification.warning({
          top: 92,
          message: '存在未保存脚本,请点击确定保存,或点击取消放弃修改!',
          duration: 5
        })
        return
      }
      this.setState({loading: true})
      this.sqlverify(() => { // 验证成功
        this.setState({
@@ -372,10 +383,20 @@
  scriptsUpdate = (scripts) => {
    this.setState({scripts})
  }
  // 前置脚本更新
  preScriptsUpdate = (preScripts) => {
    this.setState({preScripts})
  }
  // 后置脚本更新
  cbScriptsUpdate = (cbScripts) => {
    this.setState({cbScripts})
  }
  render() {
    const { config, menu, dict } = this.props
    const { loading, activeKey, setting, defaultSql, columns, scripts } = this.state
    const { loading, activeKey, setting, defaultSql, columns, scripts, preScripts, cbScripts } = this.state
    return (
      <div className="model-table-setting-form-box" id="model-setting-form-body">
@@ -404,11 +425,43 @@
              scripts={scripts}
              defaultSql={defaultSql}
              searches={this.props.search}
              scriptsChange={this.scriptsChange}
              scriptsUpdate={this.scriptsUpdate}
              wrappedComponentRef={(inst) => this.scriptsForm = inst}
            />
          </TabPane>
          <TabPane tab={
            <span>
              前置脚本
              {preScripts.length ? <span className="count-tip">{preScripts.length}</span> : null}
            </span>
          } key="prescripts">
            <SimpleScript
              dict={dict}
              setting={setting}
              scripts={preScripts}
              defaultSql={defaultSql}
              searches={this.props.search}
              scriptsChange={this.scriptsChange}
              scriptsUpdate={this.preScriptsUpdate}
              wrappedComponentRef={(inst) => this.preScriptsForm = inst}
            />
          </TabPane>
          <TabPane tab={
            <span>
              回调脚本
              {cbScripts.length ? <span className="count-tip">{cbScripts.length}</span> : null}
            </span>
          } key="cbscripts">
            <SimpleScript
              dict={dict}
              setting={setting}
              scripts={cbScripts}
              searches={this.props.search}
              scriptsChange={this.scriptsChange}
              scriptsUpdate={this.scriptsUpdate}
              wrappedComponentRef={(inst) => this.cbScriptsForm = inst}
            />
          </TabPane>
        </Tabs>
      </div>
    )