king
2020-06-19 cd42d41344f0f780e0c0ac0a3625aeb78160f9dd
src/templates/sharecomponent/settingcomponent/settingform/customscript/index.jsx
@@ -1,9 +1,10 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { Form, Row, Col, Input, Button, notification, Modal, Select, Radio } from 'antd'
import { Form, Row, Col, Input, Button, notification, Modal, Select } from 'antd'
import moment from 'moment'
import Utils from '@/utils/utils.js'
import SettingUtils from '../utils.jsx'
import Api from '@/api'
import './index.scss'
@@ -15,8 +16,10 @@
    dict: PropTypes.object,         // 字典项
    setting: PropTypes.object,      // 设置
    searches: PropTypes.array,      // 搜索条件
    swhere: PropTypes.string,       // where条件
    arr_field: PropTypes.string,    // 列字段
    regoptions: PropTypes.array,    // 正则替换
    systemScripts: PropTypes.array, // 系统脚本
    customScripts: PropTypes.array, // 自定义脚本
    scriptsChange: PropTypes.func   // 表单
  }
@@ -58,8 +61,7 @@
    })
    this.props.form.setFieldsValue({
      sql: record.sql,
      initsql: record.initsql || 'false'
      sql: record.sql
    })
  }
@@ -73,8 +75,8 @@
  }
  handleConfirm = () => {
    const { searches, setting } = this.props
    const { setting, arr_field, regoptions, swhere } = this.props
    // 表单提交时检查输入值是否正确
    this.props.form.validateFieldsAndScroll((err, values) => {
      if (!err) {
@@ -122,54 +124,37 @@
          return
        }
        let tail = `
          aaa:
        `
        let _initsql = ''
        this.props.customScripts.forEach(script => {
          if (this.state.editItem && this.state.editItem.uuid === script.uuid) return
          if (script.status === 'false' || script.initsql !== 'true') return
          _initsql += `
        let _customScript = ''
        setting.scripts && setting.scripts.forEach(script => {
          if (this.state.editItem && this.state.editItem.uuid === script.uuid) {
            _customScript += `
            ${values.sql}
            `
          } else if (script.status !== 'false') {
            _customScript += `
            ${script.sql}
            `
        })
        let param = {
          func: 's_debug_sql',
          LText: _initsql + values.sql + tail
        }
        param.LText = param.LText.replace(/@\$|\$@/ig, '')
        let allSearch = Utils.initMainSearch(searches)
        allSearch = Utils.getAllSearchOptions(allSearch)
        let regoptions = allSearch.map(item => {
          return {
            reg: new RegExp('@' + item.key + '@', 'ig'),
            value: `'${item.value}'`
          }
        })
        regoptions.push({
          reg: new RegExp('@orderBy@', 'ig'),
          value: setting.order
        })
        if (setting.laypage !== 'false') {
          regoptions.push({
            reg: new RegExp('@pageSize@', 'ig'),
            value: 10
          }, {
            reg: new RegExp('@pageIndex@', 'ig'),
            value: 1
          })
        if (!this.state.editItem) {
          _customScript += `
            ${values.sql}
            `
        }
        regoptions.forEach(item => {
          param.LText = param.LText.replace(item.reg, item.value)
        })
        if (_customScript) {
          _customScript = `declare @ErrorCode nvarchar(50),@retmsg nvarchar(4000) select @ErrorCode='',@retmsg =''
            ${_customScript}
          `
        }
        let _setting = {...setting, customScript: _customScript}
        let param = {
          func: 's_debug_sql',
          LText: SettingUtils.getDebugSql(_setting, arr_field, regoptions, swhere)
        }
        param.LText = Utils.formatOptions(param.LText)
        param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
@@ -249,18 +234,6 @@
          <Col span={24} className="sqlfield">
            <Form.Item label={'可用字段'}>
              id, bid, loginuid, sessionuid, userid, appkey, {type === 'main' ? 'out_id, ' : '' }time_id, orderBy{setting.laypage !== 'false' ? ', pageSize, pageIndex': ''}{usefulFields ? ', ' + usefulFields : ''}
            </Form.Item>
          </Col>
          <Col span={8} style={{whiteSpace: 'nowrap'}}>
            <Form.Item style={{marginBottom: 0}} label="初始化sql">
              {getFieldDecorator('initsql', {
                initialValue: 'false'
              })(
                <Radio.Group>
                  <Radio value="true">是</Radio>
                  <Radio value="false">否</Radio>
                </Radio.Group>
              )}
            </Form.Item>
          </Col>
          <Col span={10}>