king
2024-09-15 dbc911dbb044895f98a49ef69ef5a5800a4aba3e
src/templates/sharecomponent/treesettingcomponent/settingform/datasource/index.jsx
@@ -2,11 +2,9 @@
import PropTypes from 'prop-types'
import { Form, Row, Col, Input, Radio, Tooltip, notification, InputNumber } from 'antd'
import { QuestionCircleOutlined } from '@ant-design/icons'
import moment from 'moment'
import Api from '@/api'
import { formRule } from '@/utils/option.js'
import Utils from '@/utils/utils.js'
import { checkSQL } from '@/utils/utils-custom.js'
import CodeMirror from '@/templates/zshare/codemirror'
// import './index.scss'
@@ -14,7 +12,6 @@
class SettingForm extends Component {
  static propTpyes = {
    dict: PropTypes.object,       // 字典项
    menu: PropTypes.object,       // 菜单信息
    setting: PropTypes.object,    // 数据源配置
    inputSubmit: PropTypes.func   // 触发提交
@@ -62,7 +59,6 @@
  }
  handleConfirm = () => {
    const { setting } = this.props
    // 表单提交时检查输入值是否正确
    return new Promise((resolve, reject) => {
      this.props.form.validateFieldsAndScroll((err, values) => {
@@ -77,69 +73,12 @@
            reject()
            return
          } else if (values.interType === 'system' && values.default !== 'false' && values.dataresource) {
            let _quot = values.dataresource.match(/'{1}/g)
            let _lparen = values.dataresource.match(/\({1}/g)
            let _rparen = values.dataresource.match(/\){1}/g)
            let pass = checkSQL(values.dataresource)
            _quot = _quot ? _quot.length : 0
            _lparen = _lparen ? _lparen.length : 0
            _rparen = _rparen ? _rparen.length : 0
            if (_quot % 2 !== 0) {
              notification.warning({
                top: 92,
                message: '数据源中\'必须成对出现',
                duration: 5
              })
              reject()
              return
            } else if (_lparen !== _rparen) {
              notification.warning({
                top: 92,
                message: '数据源中()必须成对出现',
                duration: 5
              })
              reject()
              return
            } else if (/--/ig.test(values.dataresource)) {
              notification.warning({
                top: 92,
                message: '数据源中,不可出现字符 -- ,注释请用 /*内容*/',
                duration: 5
              })
            if (!pass) {
              reject()
              return
            }
            let error = Utils.verifySql(values.dataresource)
            if (error) {
              notification.warning({
                top: 92,
                message: '数据源中不可使用' + error,
                duration: 5
              })
              reject()
              return
            }
          }
          // 数据源保存
          if (
            values.interType === 'system' && values.default !== 'false' &&
            /[^\s]+\s+[^\s]+/ig.test(values.dataresource) && setting.dataresource !== values.dataresource
          ) {
            let param = {
              func: 's_DataSrc_Save',
              LText: values.dataresource,
              MenuID: this.props.menu.MenuID
            }
            param.LText = Utils.formatOptions(param.LText)
            param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
            param.secretkey = Utils.encrypt(param.LText, param.timestamp)
            Api.genericInterface(param)
          }
          resolve(values)
@@ -175,7 +114,7 @@
  }
  render() {
    const { setting, dict, menu } = this.props
    const { setting, menu } = this.props
    const { getFieldDecorator } = this.props.form
    const { interType, funcRules, funcTooltip } = this.state
@@ -200,7 +139,7 @@
                rules: [
                  {
                    required: true,
                    message: dict['form.required.input'] + '表名!'
                    message: '请输入表名!'
                  },
                  {
                    max: 50,
@@ -217,7 +156,7 @@
                rules: [
                  {
                    required: true,
                    message: dict['form.required.input'] + '标题!'
                    message: '请输入标题!'
                  },
                  {
                    max: formRule.input.max,
@@ -228,13 +167,13 @@
            </Form.Item>
          </Col>
          <Col span={8}>
            <Form.Item label={dict['header.form.intertype']}>
            <Form.Item label="接口类型">
              {getFieldDecorator('interType', {
                initialValue: interType,
                rules: [
                  {
                    required: true,
                    message: dict['form.required.select'] + dict['header.form.intertype'] + '!'
                    message: '请选择接口类型!'
                  }
                ]
              })(
@@ -246,19 +185,24 @@
            </Form.Item>
          </Col>
          {interType === 'outer' ? <Col span={8}>
            <Form.Item label={dict['header.form.sysInterface']}>
            <Form.Item label={
              <Tooltip placement="topLeft" title="单点登录系统">
                <QuestionCircleOutlined className="mk-form-tip" />
                系统接口
              </Tooltip>
            }>
              {getFieldDecorator('sysInterface', {
                initialValue: setting.sysInterface || 'false',
                rules: [
                  {
                    required: true,
                    message: dict['form.required.select'] + dict['header.form.sysInterface'] + '!'
                    message: '请选择系统接口!'
                  },
                ]
              })(
              <Radio.Group onChange={(e) => {this.onRadioChange(e, 'sysInterface')}}>
                <Radio value="true">{dict['model.true']}</Radio>
                <Radio value="false">{dict['model.false']}</Radio>
                <Radio value="true">是</Radio>
                <Radio value="false">否</Radio>
              </Radio.Group>)}
            </Form.Item>
          </Col> : null}
@@ -274,7 +218,7 @@
                rules: [
                  {
                    required: true,
                    message: dict['form.required.input'] + '内部函数!'
                    message: '请输入内部函数!'
                  },
                  {
                    max: formRule.func.max,
@@ -292,7 +236,7 @@
                rules: [
                  {
                    required: true,
                    message: dict['form.required.input'] + '接口地址!'
                    message: '请输入接口地址!'
                  }
                ]
              })(<TextArea rows={2}/>)}
@@ -328,7 +272,7 @@
          </Col> : null}
          <Col span={8}>
            <Form.Item label={
              <Tooltip placement="topLeft" title={'数据值字段。'}>
              <Tooltip placement="topLeft" title="数据值字段。">
                <QuestionCircleOutlined className="mk-form-tip" />
                Value
              </Tooltip>
@@ -338,7 +282,7 @@
                rules: [
                  {
                    required: true,
                    message: dict['form.required.input'] + 'Value!'
                    message: '请输入Value!'
                  },
                  {
                    pattern: formRule.field.pattern,
@@ -363,7 +307,7 @@
                rules: [
                  {
                    required: true,
                    message: dict['form.required.input'] + 'Label!'
                    message: '请输入Label!'
                  },
                  {
                    pattern: formRule.field.pattern,
@@ -378,7 +322,7 @@
          </Col>
          <Col span={8}>
            <Form.Item label={
              <Tooltip placement="topLeft" title={'父级字段。'}>
              <Tooltip placement="topLeft" title="父级字段。">
                <QuestionCircleOutlined className="mk-form-tip" />
                Parent
              </Tooltip>
@@ -388,7 +332,7 @@
                rules: [
                  {
                    required: true,
                    message: dict['form.required.input'] + 'Label!'
                    message: '请输入Label!'
                  },
                  {
                    pattern: formRule.field.pattern,
@@ -408,7 +352,7 @@
                rules: [
                  {
                    required: true,
                    message: dict['form.required.input'] + '排序!'
                    message: '请输入排序!'
                  },
                  {
                    max: formRule.input.max,
@@ -448,7 +392,7 @@
                rules: [
                  {
                    required: true,
                    message: dict['form.required.input'] + '宽度!'
                    message: '请输入宽度!'
                  }
                ]
              })(<InputNumber min={2} max={12} precision={0} />)}