king
2024-08-20 58826d6f4eab9f8c9acf9fa8696f60039c645cfe
src/templates/zshare/verifycard/customform/index.jsx
@@ -1,18 +1,17 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { Form, Row, Col, Input, Select, Button, notification, Modal } from 'antd'
import moment from 'moment'
import { Form, Row, Col, Input, Select, Button, notification, Modal, Tooltip } from 'antd'
import Utils from '@/utils/utils.js'
import Api from '@/api'
import { checkSQL } from '@/utils/utils-custom.js'
import CodeMirror from '@/templates/zshare/codemirror'
import './index.scss'
// import './index.scss'
class CustomForm extends Component {
  static propTpyes = {
    dict: PropTypes.object,         // 字典项
    btn: PropTypes.object,          // 按钮
    usefulfields: PropTypes.string, // 可用字段
    formfields: PropTypes.string,
    colfields: PropTypes.string,
    initsql: PropTypes.string,      // 可用字段
    customChange: PropTypes.func    // 表单
  }
@@ -50,79 +49,46 @@
    // 表单提交时检查输入值是否正确
    this.props.form.validateFieldsAndScroll((err, values) => {
      if (!err) {
        if (/^[\s\n]+$/.test(values.sql)) {
          notification.warning({
            top: 92,
            message: '请输入sql!',
            duration: 5
          })
          return
        }
        values.uuid = this.state.editItem ? this.state.editItem.uuid : ''
        values.resultName = values.result === 'false' ? '不存在' : '存在'
        let _quot = values.sql.match(/'{1}/g)
        let _lparen = values.sql.match(/\({1}/g)
        let _rparen = values.sql.match(/\){1}/g)
        let pass = checkSQL(values.sql, 'customscript')
        _quot = _quot ? _quot.length : 0
        _lparen = _lparen ? _lparen.length : 0
        _rparen = _rparen ? _rparen.length : 0
        if (!pass) return
        if (_quot % 2 !== 0) {
          notification.warning({
            top: 92,
            message: 'sql中\'必须成对出现',
            duration: 5
          })
          return
        } else if (_lparen !== _rparen) {
          notification.warning({
            top: 92,
            message: 'sql中()必须成对出现',
            duration: 5
          })
          return
        } else if (/--/ig.test(values.sql)) {
          notification.warning({
            top: 92,
            message: '自定义sql语句中,不可出现字符 -- ,注释请用 /*内容*/',
            duration: 5
          })
          return
        }
        let sql = `${this.props.initsql}
          /* 自定义验证 */
          select @tbid='', @ErrorCode='',@retmsg=''
          select top 1 @tbid='X' from (${values.sql}) a
          If @tbid = ''
          Begin
            select @ErrorCode='${values.errorCode}',@retmsg='${values.errmsg}'
            goto aaa
          end
          aaa: select @ErrorCode as ErrorCode,@retmsg as retmsg`
        let error = Utils.verifySql(values.sql)
        if (error) {
          notification.warning({
            top: 92,
            message: 'sql中不可使用' + error,
            duration: 5
          })
          return
        }
        let param = {
          func: 's_debug_sql',
          exec_type: 'y',
          LText: this.props.initsql + values.sql
        }
        if (window.GLOB.funcs && window.GLOB.funcs.length > 0) {
          window.GLOB.funcs.forEach(item => {
            let reg = new RegExp('\\$ex@' + item.func_code + '@ex\\$', 'ig')
            param.LText = param.LText.replace(reg, `/*$ex@${item.func_code}-begin*/\n${item.key_sql}\n/*@ex$-end*/`)
          })
        }
        // if (window.GLOB.funcs && window.GLOB.funcs.length > 0) {
        //   window.GLOB.funcs.forEach(item => {
        //     let reg = new RegExp('\\$ex@' + item.func_code + '@ex\\$', 'ig')
        //     sql = sql.replace(reg, `/*$ex@${item.func_code}-begin*/\n${item.key_sql}\n/*@ex$-end*/`)
        //   })
        // }
        
        // 数据权限
        param.LText = param.LText.replace(/@\$|\$@/ig, '')
        // 外联数据库替换
        if (window.GLOB.externalDatabase !== null) {
          param.LText = param.LText.replace(/@db@/ig, window.GLOB.externalDatabase)
        }
        param.LText = Utils.formatOptions(param.LText)
        param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
        param.secretkey = Utils.encrypt('', param.timestamp)
        sql = sql.replace(/@\$|\$@/ig, '')
        
        this.setState({loading: true})
        Api.getLocalConfig(param).then(res => {
          if (res.status) {
        Api.sDebug(sql).then(res => {
          if (res.status || res.ErrCode === '-2') {
            this.setState({
              loading: false,
              editItem: null
@@ -146,7 +112,7 @@
  }
  render() {
    const { usefulfields, btn } = this.props
    const { formfields, colfields, btn } = this.props
    const { getFieldDecorator } = this.props.form
    const formItemLayout = {
      labelCol: {
@@ -158,22 +124,27 @@
        sm: { span: 16 }
      }
    }
    return (
      <Form {...formItemLayout} className="verify-form" id="verifycard2">
        <Row gutter={24}>
          {usefulfields ? <Col span={21} className="sqlfield">
          <Col span={21} className="sqlfield">
            <Form.Item label={'可用字段'}>
              {usefulfields}
              <Tooltip mouseLeaveDelay={0.3} mouseEnterDelay={0.3} placement="top" title={'公共值,请按照@xxx@格式使用。'}><span style={{color: '#1890ff'}}>BID, ID, LoginUID, SessionUid, UserID, Appkey, lang, time_id</span></Tooltip>,&nbsp;
              <Tooltip mouseLeaveDelay={0.3} mouseEnterDelay={0.3} placement="top" title={'系统变量,系统会定义变量并赋值。'}><span style={{color: '#fa8c16'}}>UserName, FullName, RoleID, mk_departmentcode, mk_organization, mk_user_type, mk_nation, mk_province, mk_city, mk_district, mk_address, mk_deleted</span></Tooltip>,&nbsp;
              <Tooltip mouseLeaveDelay={0.3} mouseEnterDelay={0.3} placement="top" title={'系统变量,系统会定义变量并在单号生成或创建凭证时使用。'}><span style={{color: '#13c2c2'}}>BillCode, BVoucher, FIBVoucherDate, FiYear, ModularDetailCode</span></Tooltip>
              {formfields ? <Tooltip mouseLeaveDelay={0.3} mouseEnterDelay={0.3} placement="top" title="表单变量,系统会定义变量并赋值。">, <span style={{color: '#8E44AD'}}>{formfields}</span></Tooltip> : ''}
              {colfields ? <Tooltip mouseLeaveDelay={0.3} mouseEnterDelay={0.3} placement="top" title="字段集变量,系统会定义变量并赋值。">, {colfields}</Tooltip> : ''}
            </Form.Item>
          </Col> : null}
          </Col>
          <Col span={21} className="sql">
            <Form.Item label={'sql'}>
            <Form.Item label="sql">
              {getFieldDecorator('sql', {
                initialValue: '',
                rules: [
                  {
                    required: true,
                    message: this.props.dict['form.required.input'] + 'sql!'
                    message: '请输入sql!'
                  }
                ]
              })(<CodeMirror />)}
@@ -183,6 +154,7 @@
            <Button onClick={this.handleConfirm} loading={this.state.loading} className="mk-green">
              保存
            </Button>
            <div></div>
            <Button onClick={this.handleCancel}>
              取消
            </Button>
@@ -197,7 +169,7 @@
                rules: [
                  {
                    required: true,
                    message: this.props.dict['form.required.select'] + '结果处理!'
                    message: '请选择结果处理!'
                  }
                ]
              })(
@@ -209,20 +181,20 @@
            </Form.Item>
          </Col>
          <Col span={7}>
            <Form.Item label={'提示信息'}>
            <Form.Item label="提示信息">
              {getFieldDecorator('errmsg', {
                initialValue: '',
                rules: [
                  {
                    required: true,
                    message: this.props.dict['form.required.input'] + '提示信息!'
                    message: '请输入提示信息!'
                  },
                  {
                    pattern: /^[^']*$/ig,
                    message: '提示信息不允许包含\''
                  }
                ]
              })(<Input placeholder="" autoComplete="off" />)}
              })(<Input placeholder="" autoComplete="off" onPressEnter={this.handleConfirm}/>)}
            </Form.Item>
          </Col>
          <Col span={7}>
@@ -232,7 +204,7 @@
                rules: [
                  {
                    required: true,
                    message: this.props.dict['form.required.select'] + '报错编码!'
                    message: '请选择报错编码!'
                  }
                ]
              })(