king
2024-02-19 1e4a7720c748bc0206b02b30f4a2e0b3dafb54f3
src/templates/zshare/customscript/index.jsx
@@ -7,6 +7,7 @@
import Utils from '@/utils/utils.js'
import Api from '@/api'
import { checkSQL, getSearchFields } from '@/utils/utils-custom.js'
import CodeMirror from '@/templates/zshare/codemirror'
import asyncComponent from '@/utils/asyncComponent'
import MKEmitter from '@/utils/events.js'
@@ -92,26 +93,9 @@
  UNSAFE_componentWillMount() {
    const { searches, scripts, urlFields } = this.props
    let _usefulFields = []
    searches.forEach(item => {
      if (!item.field) return
      if (item.type === 'group') {
        _usefulFields.push(item.field)
        _usefulFields.push(item.datefield)
        _usefulFields.push(item.datefield + '1')
      } else if (['dateweek', 'datemonth', 'daterange'].includes(item.type)) {
        _usefulFields.push(item.field)
        _usefulFields.push(item.field + '1')
      } else if (_usefulFields.includes(item.field)) {
        _usefulFields.push(item.field + '1')
      } else {
        _usefulFields.push(item.field.replace(/,/ig, ', '))
      }
    })
    this.setState({
      urlFields: urlFields ? urlFields.join(', ') : '',
      usefulFields: _usefulFields.join(', '),
      usefulFields: getSearchFields(searches),
      scripts: fromJS(scripts).toJS()
    })
  }
@@ -129,20 +113,21 @@
    }
    let _scriptSql = `Select distinct func+Remark as funcname,longparam, s.Sort from  s_custom_script s inner join (select OpenID from sapp where ID=@Appkey@) p on s.openid = case when s.appkey='' then s.openid else p.OpenID end order by s.Sort`
    _scriptSql = Utils.formatOptions(_scriptSql)
    _scriptSql = Utils.formatOptions(_scriptSql, 'x')
    let _sParam = {
      func: 'sPC_Get_SelectedList',
      LText: _scriptSql,
      obj_name: 'data',
      arr_field: 'funcname,longparam'
      arr_field: 'funcname,longparam',
      exec_type: 'x'
    }
    
    _sParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
    _sParam.secretkey = Utils.encrypt(_sParam.LText, _sParam.timestamp)
    _sParam.secretkey = Utils.encrypt('', _sParam.timestamp)
    _sParam.open_key = Utils.encryptOpenKey(_sParam.secretkey, _sParam.timestamp) // 云端数据验证
    
    Api.getSystemConfig(_sParam).then(res => {
    Api.getCloudConfig(_sParam).then(res => {
      if (res.status) {
        let _scripts = res.data.map(item => {
          let _item = {
@@ -197,51 +182,13 @@
      return
    }
    let pass = checkSQL(_sql, 'customscript')
    if (!pass) return
    let values = {
      uuid: editItem && editItem.uuid ? editItem.uuid : Utils.getuuid(),
      sql: _sql
    }
    let _quot = values.sql.match(/'{1}/g)
    let _lparen = values.sql.match(/\({1}/g)
    let _rparen = values.sql.match(/\){1}/g)
    _quot = _quot ? _quot.length : 0
    _lparen = _lparen ? _lparen.length : 0
    _rparen = _rparen ? _rparen.length : 0
    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 error = Utils.verifySql(values.sql, 'customscript')
    if (error) {
      notification.warning({
        top: 92,
        message: 'sql中不可使用' + error,
        duration: 5
      })
      return
    }
    let _scripts = fromJS(scripts).toJS()
@@ -422,7 +369,7 @@
              <Form.Item label={'sql'}>
                {getFieldDecorator('sql', {
                  initialValue: ''
                })(<CodeMirror />)}
                })(<CodeMirror/>)}
              </Form.Item>
            </Col>
          </Row>