king
2024-08-20 58826d6f4eab9f8c9acf9fa8696f60039c645cfe
src/templates/sharecomponent/treesettingcomponent/settingform/index.jsx
@@ -2,23 +2,20 @@
import PropTypes from 'prop-types'
import { fromJS } from 'immutable'
import { Form, notification, Modal, Spin, Tabs } from 'antd'
import moment from 'moment'
import Api from '@/api'
import Utils from '@/utils/utils.js'
import SettingUtils from './utils.jsx'
import DataSource from './datasource'
import CustomScript from '@/templates/zshare/customscript'
import asyncComponent from '@/utils/asyncComponent'
import './index.scss'
const { TabPane } = Tabs
const CustomScript = asyncComponent(() => import('@/templates/zshare/customscript'))
class SettingForm extends Component {
  static propTpyes = {
    dict: PropTypes.object,         // 字典项
    menu: PropTypes.object,         // 菜单信息
    config: PropTypes.object,       // 页面配置信息
    permFuncField: PropTypes.array, // 存储过程可用字段
    inputSubmit: PropTypes.any      // 回车提交事件
  }
@@ -34,6 +31,18 @@
    let _setting = fromJS(config.setting).toJS()
    let _scripts = _setting.scripts || []
    // if (window.GLOB.funcs && window.GLOB.funcs.length > 0) {
    //   window.GLOB.funcs.forEach(m => {
    //     let reg = new RegExp(`\\/\\*\\$ex@${m.func_code}-begin\\*\\/[\\s\\S]+\\/\\*@ex\\$-end\\*\\/`, 'ig')
    //     _scripts.forEach(item => {
    //       item.sql = item.sql.replace(reg, `$ex@${m.func_code}@ex$`)
    //     })
    //     if (_setting.dataresource) {
    //       _setting.dataresource = _setting.dataresource.replace(reg, `$ex@${m.func_code}@ex$`)
    //     }
    //   })
    // }
    this.setState({
      setting: _setting,
@@ -74,7 +83,7 @@
        let _loading = false
        if (this.scriptsForm && this.scriptsForm.state.editItem) {
          _loading = true
        } else if (this.scriptsForm && this.scriptsForm.props.form.getFieldValue('sql')) {
        } else if (this.scriptsForm && this.scriptsForm.props.form.getFieldValue('sql') && !/^\s+$/.test(this.scriptsForm.props.form.getFieldValue('sql'))) {
          _loading = true
        }
  
@@ -123,16 +132,10 @@
    } else if (type === 'scripts' && _scripts.length === 0) {
      _resolve()
    } else { // type 为 submit 、 verify ,以及其他需要验证的场景
      let param = {
        func: 's_debug_sql',
        LText: SettingUtils.getDebugSql(setting, _scripts)
      }
      param.LText = Utils.formatOptions(param.LText)
      param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
      param.secretkey = Utils.encrypt(param.LText, param.timestamp)
      let sql = SettingUtils.getDebugSql(setting, _scripts)
      
      Api.getLocalConfig(param).then(result => {
        if (result.status) {
      Api.sDebug(sql).then(result => {
        if (result.status || result.ErrCode === '-2') {
          _resolve()
        } else {
          _reject()
@@ -181,6 +184,7 @@
            })
          }, () => {             // 验证失败
            this.setState({
              activeKey: val,
              loading: false
            })
          }, activeKey)
@@ -190,17 +194,16 @@
      let _loading = false
      if (this.scriptsForm && this.scriptsForm.state.editItem) {
        _loading = true
      } else if (this.scriptsForm && this.scriptsForm.props.form.getFieldValue('sql')) {
      } else if (this.scriptsForm && this.scriptsForm.props.form.getFieldValue('sql') && !/^\s+$/.test(this.scriptsForm.props.form.getFieldValue('sql'))) {
        _loading = true
      }
      if (_loading) {
        notification.warning({
          top: 92,
          message: '存在未保存脚本,请点击确定保存,或点击取消放弃修改!',
          message: '存在未保存脚本!',
          duration: 5
        })
        return
      }
      this.setState({loading: true})
      this.sqlverify(() => { // 验证成功
@@ -210,6 +213,7 @@
        })
      }, () => {             // 验证失败
        this.setState({
          activeKey: val,
          loading: false
        })
      }, activeKey)
@@ -233,22 +237,24 @@
    const { activeKey, setting, loading, scripts } = this.state
    return (
      <div className="model-tree-setting-form-box" id="model-setting-form-body">
      <div className="model-tree-setting-form-box">
        {loading && <Spin size="large" />}
        <Tabs activeKey={activeKey} className="verify-card-box" onChange={this.changeTab}>
        <Tabs activeKey={activeKey} onChange={this.changeTab}>
          <TabPane tab="数据源" key="setting">
            <DataSource
              menu={menu}
              dict={this.props.dict}
              setting={setting}
              permFuncField={this.props.permFuncField}
              inputSubmit={this.props.inputSubmit}
              wrappedComponentRef={(inst) => this.settingForm = inst}
            />
          </TabPane>
          <TabPane tab="自定义脚本" key="scripts">
          <TabPane tab={
            <span>
              自定义脚本
              {scripts.length ? <span className="count-tip">{scripts.length}</span> : null}
            </span>
          } key="scripts" id="mk-setting-scripts">
            <CustomScript
              dict={this.props.dict}
              setting={setting}
              scripts={scripts}
              defaultSql={this.state.defaultsql}