king
2022-02-09 d59f518f466274b2caeb2e01c10c92deafe7c93b
src/templates/sharecomponent/settingcalcomponent/verifycard/index.jsx
@@ -1,7 +1,8 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { fromJS } from 'immutable'
import { Form, Tabs, Table, Popconfirm, Icon, notification, Modal, Spin } from 'antd'
import { Form, Tabs, Table, Popconfirm, notification, Modal, Spin } from 'antd'
import { EditOutlined, DeleteOutlined } from '@ant-design/icons'
import moment from 'moment'
import Api from '@/api'
@@ -9,20 +10,18 @@
import asyncComponent from '@/utils/asyncComponent'
import ColForm from './columnform'
import CustomScript from '@/templates/zshare/customscript'
import SettingForm from './settingform'
import SettingUtils from './utils'
import './index.scss'
const { TabPane } = Tabs
const CustomScript = asyncComponent(() => import('@/templates/zshare/customscript'))
const FieldsComponent = asyncComponent(() => import('@/templates/sharecomponent/fieldscomponent'))
class VerifyCard extends Component {
  static propTpyes = {
    dict: PropTypes.object,          // 字典项
    tableFields: PropTypes.any,      // 数据源信息
    permFuncField: PropTypes.any,    // 数据源信息
    config: PropTypes.object,        // 数据源信息
    menuId: PropTypes.string,        // 菜单Id
    searches: PropTypes.array,       // 搜索条件
@@ -57,13 +56,13 @@
        dataIndex: 'operation',
        render: (text, record) =>
          (<div>
            <span className="operation-btn" title={this.props.dict['model.edit']} onClick={() => this.handleEdit(record)} style={{color: '#1890ff'}}><Icon type="edit" /></span>
            <span className="operation-btn" title={this.props.dict['model.edit']} onClick={() => this.handleEdit(record)} style={{color: '#1890ff'}}><EditOutlined /></span>
            <Popconfirm
              overlayClassName="popover-confirm"
              title={this.props.dict['model.query.delete']}
              onConfirm={() => this.deleteColumn(record)
            }>
              <span className="operation-btn" style={{color: '#ff4d4f'}}><Icon type="delete" /></span>
              <span className="operation-btn" style={{color: '#ff4d4f'}}><DeleteOutlined /></span>
            </Popconfirm>
          </div>)
      }
@@ -73,10 +72,25 @@
  UNSAFE_componentWillMount() {
    const { config } = this.props
    let _setting = fromJS(config.setting).toJS()
    let _scripts = fromJS(config.scripts).toJS()
    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: fromJS(config.setting).toJS(),
      setting: _setting,
      columns: fromJS(config.columns).toJS(),
      scripts: fromJS(config.scripts).toJS()
      scripts: _scripts
    })
  }
@@ -177,7 +191,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
      }
@@ -225,7 +239,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
        }
@@ -245,7 +259,7 @@
  }
  sqlverify = (resolve, reject, type, testScripts) => {
    const { searches } = this.props
    const { searches, config } = this.props
    const { columns, setting, scripts } = this.state
    if (setting.interType !== 'system') { // 不使用系统接口时,不需要sql验证
@@ -279,11 +293,12 @@
    } else if (setting.execute !== 'false' || _scripts.length > 0) {
      let param = {
        func: 's_debug_sql',
        LText: SettingUtils.getDebugSql(setting, _scripts, columns, searches)
        exec_type: 'y',
        LText: SettingUtils.getDebugSql(setting, _scripts, columns, Utils.getRegOptions(searches), config.calendar, config.urlFields)
      }
      param.LText = Utils.formatOptions(param.LText)
      param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
      param.secretkey = Utils.encrypt(param.LText, param.timestamp)
      param.secretkey = Utils.encrypt('', param.timestamp)
      
      Api.getLocalConfig(param).then(result => {
        if (result.status) {
@@ -328,6 +343,7 @@
  }
  render() {
    const { config } = this.props
    const { columns, setting, scripts, colColumns, activeKey, loading } = this.state
    return (
@@ -338,7 +354,6 @@
            <SettingForm
              menuId={this.props.menuId}
              dict={this.props.dict}
              permFuncField={this.props.permFuncField}
              columns={columns}
              setting={setting}
              scripts={scripts}
@@ -352,9 +367,8 @@
              wrappedComponentRef={(inst) => this.contrastForm = inst}
            />
            <FieldsComponent
              config={{...this.props.config, columns}}
              config={{...config, columns}}
              type="fields"
              tableFields={this.props.tableFields}
              updatefield={this.updatefields}
            />
            <Table
@@ -376,6 +390,7 @@
              dict={this.props.dict}
              setting={setting}
              scripts={scripts}
              urlFields={config.urlFields}
              defaultSql={this.state.defaultsql}
              searches={this.props.searches}
              scriptsChange={this.scriptsChange}