king
2022-10-17 e8edfdadb561cd83bf6e1c3e00d55b8cc2aee6d5
src/templates/formtabconfig/settingform/index.jsx
@@ -1,22 +1,25 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { Form, Row, Col, Input, Radio, Select, Tooltip, Icon, notification, InputNumber } from 'antd'
import { Form, Row, Col, Input, Radio, Select, Tooltip, notification, InputNumber } from 'antd'
import { QuestionCircleOutlined } from '@ant-design/icons'
import { formRule } from '@/utils/option.js'
import Utils from '@/utils/utils.js'
import './index.scss'
const { TextArea } = Input
class SettingForm extends Component {
  static propTpyes = {
    dict: PropTypes.object, // 字典项
    menu: PropTypes.object,
    config: PropTypes.object,
    usefulFields: PropTypes.array
    inputSubmit: PropTypes.any     // 回车提交事件
  }
  state = {
    interType: (this.props.config.setting && this.props.config.setting.interType) || 'inner',
    columns: null,
    usefulFields: [],
    interReadonly: false,
  }
@@ -41,12 +44,23 @@
          return true
        }
      })
    } catch {
    } catch (e) {
      notification.warning({
        top: 92,
        message: '菜单信息错误!',
        duration: 10
        duration: 5
      })
    }
    let usefulFields = sessionStorage.getItem('permFuncField')
    if (usefulFields) {
      try {
        usefulFields = JSON.parse(usefulFields)
      } catch (e) {
        usefulFields = []
      }
    } else {
      usefulFields = []
    }
    this.setState({
@@ -54,7 +68,8 @@
      setting: _setting,
      interType: _setting.interType || 'inner',
      interReadonly: _setting.sysInterface === 'true',
      datatype: _setting.datatype || 'maintable'
      datatype: _setting.datatype || 'maintable',
      usefulFields
    })
  }
@@ -63,6 +78,17 @@
    return new Promise((resolve, reject) => {
      this.props.form.validateFieldsAndScroll((err, values) => {
        if (!err) {
          let error = Utils.verifySql(values.dataresource)
          if (error) {
            notification.warning({
              top: 92,
              message: '数据源中不可使用' + error,
              duration: 5
            })
            return
          }
          resolve(values)
        } else {
          reject(err)
@@ -74,7 +100,7 @@
  onSysChange = (e) => {
    if (e.target.value === 'true') {
      this.props.form.setFieldsValue({
        interface: window.GLOB.mainSystemApi || window.GLOB.subSystemApi
        interface: window.GLOB.mainSystemApi || ''
      })
      this.setState({
        interReadonly: true
@@ -95,7 +121,7 @@
      let _type = this.props.form.getFieldValue('sysInterface')
      if (_type === 'true') {
        this.props.form.setFieldsValue({
          interface: window.GLOB.mainSystemApi || window.GLOB.subSystemApi
          interface: window.GLOB.mainSystemApi || ''
        })
        this.setState({
          interReadonly: true
@@ -119,7 +145,7 @@
      let _type = this.props.form.getFieldValue('sysInterface')
      if (_type === 'true') {
        this.props.form.setFieldsValue({
          interface: window.GLOB.mainSystemApi || window.GLOB.subSystemApi
          interface: window.GLOB.mainSystemApi || ''
        })
        this.setState({
          interReadonly: true
@@ -132,10 +158,18 @@
    })
  }
  handleSubmit = (e) => {
    e.preventDefault()
    if (this.props.inputSubmit) {
      this.props.inputSubmit()
    }
  }
  render() {
    const { dict, usefulFields, menu } = this.props
    const { menu } = this.props
    const { getFieldDecorator } = this.props.form
    const { interType, setting, datatype } = this.state
    const { interType, setting, datatype, usefulFields } = this.state
    const formItemLayout = {
      labelCol: {
@@ -161,14 +195,14 @@
                rules: [
                  {
                    required: true,
                    message: dict['form.required.input'] + '表名!'
                    message: '请输入表名!'
                  },
                  {
                    max: formRule.input.max,
                    message: formRule.input.message
                    max: 50,
                    message: '表名最长为50个字符!'
                  }
                ]
              })(<Input placeholder="" autoComplete="off" />)}
              })(<Input placeholder="" autoComplete="off" onPressEnter={this.handleSubmit} />)}
            </Form.Item>
          </Col>
          <Col span={12}>
@@ -180,18 +214,19 @@
                  <Select.Option value="1">1列</Select.Option>
                  <Select.Option value="2">2列</Select.Option>
                  <Select.Option value="3">3列</Select.Option>
                  <Select.Option value="4">4列</Select.Option>
                </Select>
              )}
            </Form.Item>
          </Col>
          <Col span={12}>
            <Form.Item label={dict['header.menu.datasource']}>
            <Form.Item label="数据来源">
              {getFieldDecorator('datatype', {
                initialValue: setting.datatype || 'query'
              })(
                <Radio.Group onChange={this.sourceChange}>
                  <Radio value="maintable">{dict['header.menu.maintable']}</Radio>
                  <Radio value="query">{dict['header.menu.query']}</Radio>
                  <Radio value="maintable">主表</Radio>
                  <Radio value="query">查询</Radio>
                </Radio.Group>
              )}
            </Form.Item>
@@ -204,51 +239,51 @@
            </Form.Item>
          </Col>
          {datatype === 'query' ? <Col span={12}>
            <Form.Item label={dict['header.form.intertype']}>
            <Form.Item label="接口类型">
              {getFieldDecorator('interType', {
                initialValue: interType
              })(
                <Radio.Group onChange={this.onChange}>
                  <Radio value="inner">{dict['header.form.interface.inner']}</Radio>
                  <Radio value="outer">{dict['header.form.interface.outer']}</Radio>
                  <Radio value="inner">内部</Radio>
                  <Radio value="outer">外部</Radio>
                </Radio.Group>
              )}
            </Form.Item>
          </Col> : null}
          {datatype === 'query' && interType === 'outer' ? <Col span={12}>
            <Form.Item label={dict['header.form.sysInterface']}>
            <Form.Item label="系统接口">
              {getFieldDecorator('sysInterface', {
                initialValue: setting.sysInterface || 'false'
              })(
                <Radio.Group onChange={this.onSysChange}>
                  <Radio value="true">{dict['header.form.true']}</Radio>
                  <Radio value="false">{dict['header.form.false']}</Radio>
                  <Radio value="true">是</Radio>
                  <Radio value="false">否</Radio>
                </Radio.Group>
              )}
            </Form.Item>
          </Col> : null}
          {datatype === 'query' && interType === 'outer' ? <Col span={12}>
            <Form.Item label={dict['header.form.interface']}>
            <Form.Item label="接口地址">
              {getFieldDecorator('interface', {
                initialValue: setting.sysInterface === 'true' ? (window.GLOB.mainSystemApi || window.GLOB.subSystemApi) : (setting.interface || ''),
                initialValue: setting.sysInterface === 'true' ? (window.GLOB.mainSystemApi || '') : (setting.interface || ''),
                rules: [
                  {
                    required: true,
                    message: dict['form.required.input'] + dict['header.form.interface'] + '!'
                    message: '请输入接口地址!'
                  },
                  {
                    max: formRule.input.max,
                    message: formRule.input.message
                  }
                ]
              })(<Input placeholder="" autoComplete="off" disabled={this.state.interReadonly} />)}
              })(<Input placeholder="" autoComplete="off" disabled={this.state.interReadonly} onPressEnter={this.handleSubmit} />)}
            </Form.Item>
          </Col> : null}
          {datatype === 'query' && interType !== 'outer' ? <Col span={12}>
            <Form.Item label={
              <Tooltip placement="topLeft" overlayClassName="middle" title={`可自定义数据处理函数,函数名称需以${usefulFields.join(', ')}等字符开始;未设置时会调用系统函数,使用系统函数需完善数据源。`}>
                <Icon type="question-circle" />
                {dict['header.form.innerFunc']}
                <QuestionCircleOutlined className="mk-form-tip" />
                内部函数
              </Tooltip>
            }>
              {getFieldDecorator('innerFunc', {
@@ -262,14 +297,14 @@
                    message: formRule.func.maxMessage
                  }
                ]
              })(<Input placeholder="" autoComplete="off" />)}
              })(<Input placeholder="" autoComplete="off" onPressEnter={this.handleSubmit} />)}
            </Form.Item>
          </Col> : null}
          {datatype === 'query' && interType !== 'outer' ? <Col span={24}>
            <Form.Item help={'数据ID:' + menu.MenuID} label={
              <Tooltip placement="topLeft" title="使用系统函数时,需填写数据源,自定义函数时,可忽略。">
                <Icon type="question-circle" />
                {'数据源'}
                <QuestionCircleOutlined className="mk-form-tip" />
                数据源
              </Tooltip>
            } className="textarea">
              {getFieldDecorator('dataresource', {
@@ -278,7 +313,7 @@
            </Form.Item>
          </Col> : null}
          {datatype === 'query' && interType === 'outer' ? <Col span={12}>
            <Form.Item label={dict['header.form.outerFunc']}>
            <Form.Item label="外部函数">
              {getFieldDecorator('outerFunc', {
                initialValue: setting.outerFunc || '',
                rules: [
@@ -290,7 +325,7 @@
                    message: formRule.func.maxMessage
                  }
                ]
              })(<Input placeholder="" autoComplete="off" />)}
              })(<Input placeholder="" autoComplete="off" onPressEnter={this.handleSubmit} />)}
            </Form.Item>
          </Col> : null}
          <Col span={12}>
@@ -303,7 +338,7 @@
          <Col span={12}>
            <Form.Item label="初始化">
              {getFieldDecorator('onload', {
                initialValue: setting.onload || 'false'
                initialValue: setting.onload || 'true'
              })(
                <Select>
                  <Select.Option value="true">加载数据</Select.Option>