king
2025-05-13 1a176e4bdba485301385caac1a29102e598d25cc
src/menu/datasource/verifycard/settingform/index.jsx
@@ -1,12 +1,12 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { fromJS } from 'immutable'
import { Form, Row, Col, Input, Radio, Tooltip, notification, Select, InputNumber, Cascader } from 'antd'
import { QuestionCircleOutlined } from '@ant-design/icons'
import { Form, Row, Col, Input, Radio, Tooltip, notification, Select, InputNumber, Cascader, Modal, Button } from 'antd'
import { QuestionCircleOutlined, PlusOutlined } from '@ant-design/icons'
import { formRule } from '@/utils/option.js'
import Utils from '@/utils/utils.js'
import MenuUtils from '@/utils/utils-custom.js'
import { checkSQL } from '@/utils/utils-custom.js'
import CodeMirror from '@/templates/zshare/codemirror'
import KeyInterface from '@/components/keyInterface'
import './index.scss'
@@ -16,6 +16,8 @@
class SettingForm extends Component {
  static propTpyes = {
    updateStatus: PropTypes.func,
    updateColumns: PropTypes.func,
    addProcess: PropTypes.func,
    config: PropTypes.object,     // 组件配置
    setting: PropTypes.object,    // 数据源配置
    columns: PropTypes.array,     // 列设置
@@ -27,25 +29,33 @@
    modules: [],
    innerRules: [],
    innertip: '',
    MenuType: '',
    ismain: false
    MenuType: sessionStorage.getItem('MenuType') || '',
    ismain: false,
    visible: false
  }
  UNSAFE_componentWillMount () {
    const { config, setting } = this.props
    let menu = window.GLOB.customMenu
    let MenuType = ''
    if (menu.parentId === 'BillPrintTemp') {
      MenuType = 'billPrint'
    }
    let modules = MenuUtils.getSupModules(menu.components, config.uuid, menu.interfaces)
    let modules = []
    let ismain = false
    if (menu.Template === 'BaseTable') {
      ismain = config.name === '主表'
    }
    if (config.type === 'interface') {
      menu.components.forEach(item => {
        if (item.type === 'module' && item.subtype === 'account') {
          modules.push({
            value: item.uuid,
            label: item.name
          })
        }
      })
    } else {
      modules = MenuUtils.getSupModules(menu.components, config.uuid, menu.interfaces)
    }
    modules.unshift({
@@ -90,7 +100,7 @@
      }
    }
    this.setState({modules, innerRules, innertip, setting: _setting, ismain, MenuType})
    this.setState({modules, innerRules, innertip, setting: _setting, ismain})
  }
  handleConfirm = () => {
@@ -108,59 +118,15 @@
          if (values.interType === 'system' && values.onload === 'false') {
            values.sync = 'false'
          }
          if (values.interType === 'system' && values.database === 'sso') {
            values.sync = 'false'
          }
          // 数据源前端验证
          if (values.interType === 'system' && values.execute !== '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
              })
              reject()
              return
            } else if (/,,/ig.test(values.dataresource)) {
              notification.warning({
                top: 92,
                message: '数据源中,不可出现连续的英文逗号(,,)',
                duration: 5
              })
              reject()
              return
            }
            let error = Utils.verifySql(values.dataresource)
            if (error) {
              notification.warning({
                top: 92,
                message: '数据源中不可使用' + error,
                duration: 5
              })
            if (!pass) {
              reject()
              return
            }
@@ -186,10 +152,62 @@
    this.props.updateStatus(setting)
  }
  addProcess = () => {
    this.setState({visible: true})
  }
  execAddProcess = (type) => {
    let _sql = this.props.form.getFieldValue('dataresource')
    let tableName = this.props.form.getFieldValue('tableName') || '表名'
    if (type === 'flowstart') {
      _sql = _sql + `\n/* select a.*, w.remark as remark_w, w.statusname  as statusname_w,w.status as status_w,w.works_flow_param,w.works_flow_detail_id,w.modifydate as modifydate_w  from (select * from ${tableName} where status=0 and deleted=0 $@ and createuserid=@userid@ @$) a
    inner join (select * from  s_my_works_flow  where works_flow_code=@works_flow_code@ and status=0 and deleted=0) w on a.id=w.works_flow_id */`
    } else if (type === 'flowcheck') {
      _sql = _sql + `\n/* select a.*, w.remark as remark_w, w.statusname  as statusname_w,w.status as status_w,w.works_flow_param,w.works_flow_detail_id,w.modifydate as modifydate_w
    from (select * from ${tableName} where status=0 and deleted=0 ) a
    inner join (select * from  s_my_works_flow  where works_flow_code=@works_flow_code@ and status>0 and status<888 and deleted=0) w
    on a.id=w.works_flow_id
    $@ inner join (select works_flow_id  from s_my_works_flow_role where userid=@userid@ and  works_flow_code=@works_flow_code@ and deleted=0 ) r
    on r.works_flow_id=w.works_flow_id @$ */`
    }
    this.props.form.setFieldsValue({
      dataresource: _sql
    })
    this.setState({visible: false})
    this.props.addProcess()
  }
  addSql = () => {
    let tableName = this.props.form.getFieldValue('tableName')
    if (!tableName) {
      notification.warning({
        top: 92,
        message: '请添加表名。',
        duration: 5
      })
      return
    }
    let _sql = this.props.form.getFieldValue('dataresource')
    if (/^\s*$/.test(_sql)) {
      this.props.form.setFieldsValue({
        dataresource: `select * from ${tableName} where deleted=0`
      })
    }
    this.props.updateColumns(tableName)
  }
  render() {
    const { columns, config } = this.props
    const { columns, config, hasMainSearch } = this.props
    const { getFieldDecorator } = this.props.form
    const { setting, modules, innerRules, innertip, MenuType } = this.state
    const { setting, modules, innerRules, innertip, MenuType, visible } = this.state
    const formItemLayout = {
      labelCol: {
@@ -216,7 +234,7 @@
                      message: '请输入数据源名称!'
                    }
                  ]
                })(<Input placeholder={''} autoComplete="off" />)}
                })(<Input placeholder="" autoComplete="off" />)}
              </Form.Item>
            </Col> : null}
            <Col span={8}>
@@ -237,7 +255,11 @@
                      message: '表名只可使用字母、数字以及_'
                    }
                  ]
                })(<Input placeholder={''} autoComplete="off" />)}
                })(
                  setting.interType === 'system' && ((columns.length === 0 && config.subtype !== 'basetable') || !setting.dataresource) ?
                  <Input placeholder="" autoComplete="off" addonAfter={<PlusOutlined onClick={this.addSql} />}/> :
                  <Input placeholder="" autoComplete="off"/>
                  )}
              </Form.Item>
            </Col>
            <Col span={8}>
@@ -258,7 +280,7 @@
                </Radio.Group>)}
              </Form.Item>
            </Col>
            {setting.interType === 'outer' ? <Col span={8}>
            {setting.interType === 'outer' ? <Col span={8} className="compact">
              <Form.Item label={
                <Tooltip placement="topLeft" title="业务系统指同一sso下的其他业务系统,外部系统指不同sso下的其他业务系统。">
                  <QuestionCircleOutlined className="mk-form-tip" />
@@ -278,6 +300,7 @@
                  <Radio value="false">业务</Radio>
                  <Radio value="true">单点</Radio>
                  <Radio value="external">外部</Radio>
                  <Radio value="custom">自定义</Radio>
                </Radio.Group>)}
              </Form.Item>
            </Col> : null}
@@ -326,7 +349,7 @@
                })(<KeyInterface type="develop"/>)}
              </Form.Item>
            </Col> : null}
            {setting.interType === 'outer' && setting.sysInterface === 'false' ? <Col className="outer-interface" span={24}>
            {setting.interType === 'outer' && (setting.sysInterface === 'false' || setting.sysInterface === 'custom') ? <Col className="outer-interface" span={24}>
              <Form.Item label={<Tooltip placement="topLeft" title="正式系统接口地址,为空时使用接口地址。">
                  <QuestionCircleOutlined className="mk-form-tip" />
                  正式地址
@@ -348,6 +371,18 @@
                })(<KeyInterface type="product"/>)}
              </Form.Item>
            </Col> : null}
            {setting.interType === 'outer' && setting.sysInterface === 'custom' ? <Col span={24} className="data-source" style={{paddingLeft: '7px'}}>
              <Form.Item labelCol={{xs: { span: 24 }, sm: { span: 2 }}} wrapperCol={ {xs: { span: 24 }, sm: { span: 22 }} } label={
                <Tooltip placement="topLeft" title="外部接口入参及出参的自定义处理。">
                  <QuestionCircleOutlined className="mk-form-tip" />
                  自定义脚本
                </Tooltip>
              }>
                {getFieldDecorator('js_script', {
                  initialValue: setting.js_script || ''
                })(<CodeMirror mode="text/javascript" theme="cobalt" />)}
              </Form.Item>
            </Col> : null}
            {setting.interType === 'outer' ? <Col span={8}>
              <Form.Item label="外部函数">
                {getFieldDecorator('outerFunc', {
@@ -356,6 +391,7 @@
              </Form.Item>
            </Col> : null}
            {setting.interType === 'system' ? <Col span={24} className="data-source" style={{paddingLeft: '7px'}}>
              {window.GLOB.process && !['invoice', 'invTable'].includes(config.subtype) ? <span className="process-btn" onClick={this.addProcess}>工作流</span> : null}
              <Form.Item labelCol={{xs: { span: 24 }, sm: { span: 2 }}} wrapperCol={ {xs: { span: 24 }, sm: { span: 22 }} } label={
                <Tooltip placement="topLeft" title={`使用系统函数时,需填写数据源。注:数据权限替换符 $@ -> /* 或 ''、 @$ -> */ 或 ''。`}>
                  <QuestionCircleOutlined className="mk-form-tip" />
@@ -389,21 +425,21 @@
                </Radio.Group>)}
              </Form.Item>
            </Col> : null}
            <Col span={8}>
            {!['invTable'].includes(config.subtype) ? <Col span={8}>
              <Form.Item label="主键">
                {getFieldDecorator('primaryKey', {
                  initialValue: setting.primaryKey || ''
                })(
                  <Select>
                  <Select showSearch filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}>
                    {columns.map((option, i) =>
                      <Select.Option key={i} value={option.field}>
                        {option.label}
                        {`${option.label}(${option.field})`}
                      </Select.Option>
                    )}
                  </Select>
                )}
              </Form.Item>
            </Col>
            </Col> : null}
            {/* 数组数据,需设置排序规则 */}
            {config.format === 'array' ? <Col span={8}>
              <Form.Item label={
@@ -418,6 +454,10 @@
                    {
                      required: true,
                      message: '请输入默认排序!'
                    },
                    {
                      pattern: /^[^'+]+$/,
                      message: '排序中不可使用\'与+'
                    }
                  ]
                })(<Input placeholder={'ID asc, UID desc'} autoComplete="off" />)}
@@ -434,7 +474,7 @@
                </Radio.Group>)}
              </Form.Item>
            </Col> : null}
            {!['navbar', 'balcony', 'menubar'].includes(config.type) && (!config.wrap || config.wrap.supType !== 'multi') && MenuType !== 'billPrint' ? <Col span={8}>
            {!['balcony', 'menubar', 'commonbar', 'tabbar', 'invTable'].includes(config.subtype) && (!config.wrap || config.wrap.supType !== 'multi') && MenuType !== 'billPrint' ? <Col span={8}>
              <Form.Item label={
                <Tooltip placement="topLeft" title={'该组件如果受其他组件控制,请选项相应的组件,没有时选“无”。'}>
                  <QuestionCircleOutlined className="mk-form-tip" />
@@ -467,12 +507,7 @@
              </Form.Item>
            </Col> : null}
            {config.pageable && setting.laypage !== 'false' ? <Col span={8}>
              <Form.Item label={
                <Tooltip placement="topLeft" title="选择分页时有效。">
                  <QuestionCircleOutlined className="mk-form-tip" />
                  每页数量
                </Tooltip>
              }>
              <Form.Item label="每页数量">
                {getFieldDecorator('pageSize', {
                  initialValue: setting.pageSize || 10,
                  rules: [
@@ -484,16 +519,43 @@
                })(<InputNumber min={1} max={500} precision={0} />)}
              </Form.Item>
            </Col> : null}
            {/* 1、不分页且不存在上级模块 */}
            {!['navbar', 'interface', 'calendar'].includes(config.type) && !['editable', 'basetable', 'dualdatacard'].includes(config.subtype) && (!config.pageable || (config.pageable && setting.laypage === 'false')) && (setting.supModule.length === 0 || setting.supModule[0] === 'empty') && setting.interType === 'system' && setting.onload !== 'false' ? <Col span={8}>
            {setting.interType === 'inner' ? <Col span={8}>
              <Form.Item label={
                <Tooltip placement="topLeft" title={'初始化加载时,是否与其他组件一同加载数据,注:如菜单未使用后端缓存,则查询语句大于8000字符时无效。'}>
                <Tooltip placement="topLeft" title="当选择“是”时,内部函数的传参会增加 username 与 fullname。">
                  <QuestionCircleOutlined className="mk-form-tip" />
                  记录用户
                </Tooltip>
              }>
                {getFieldDecorator('recordUser', {
                  initialValue: setting.recordUser || 'false'
                })(
                <Radio.Group onChange={(e) => {this.onOptionChange(e.target.value, 'recordUser')}}>
                  <Radio value="false">否</Radio>
                  <Radio value="true">是</Radio>
                </Radio.Group>)}
              </Form.Item>
            </Col> : null}
            {setting.interType === 'system' ? <Col span={8}>
              <Form.Item label="数据库">
                {getFieldDecorator('database', {
                  initialValue: setting.database || 'local'
                })(
                <Radio.Group>
                  <Radio value="local">本地</Radio>
                  <Radio value="sso">单点</Radio>
                </Radio.Group>)}
              </Form.Item>
            </Col> : null}
            {/* 1、不分页且不存在上级模块 */}
            {!['navbar', 'interface', 'calendar'].includes(config.type) && !['editable', 'basetable', 'dualdatacard', 'invoice', 'invTable'].includes(config.subtype) && (!config.pageable || (config.pageable && setting.laypage === 'false')) && (setting.supModule.length === 0 || setting.supModule[0] === 'empty') && setting.interType === 'system' && setting.onload !== 'false' ? <Col span={8}>
              <Form.Item label={
                <Tooltip placement="topLeft" title={'初始化加载时,是否与其他组件一同加载数据。'}>
                  <QuestionCircleOutlined className="mk-form-tip" />
                  同步查询
                </Tooltip>
              }>
                {getFieldDecorator('sync', {
                  initialValue: setting.sync || 'true'
                  initialValue: setting.sync || 'false'
                })(
                  <Radio.Group>
                    <Radio value="true">是</Radio>
@@ -502,9 +564,9 @@
                )}
              </Form.Item>
            </Col> : null}
            {!['navbar', 'balcony', 'menubar', 'interface'].includes(config.type) && !['basetable'].includes(config.subtype) ? <Col span={8}>
            {!['navbar', 'balcony', 'menubar'].includes(config.type) && !['basetable', 'invoice', 'invTable'].includes(config.subtype) ? <Col span={8}>
              <Form.Item label={
                <Tooltip placement="topLeft" title={'优先使用同级的搜索条件组件,同级搜索不存在时,依次向上选取,与当前组件的搜索条件一同用作数据过滤(当前组件的搜索条件优先)。'}>
                <Tooltip placement="topLeft" title={config.type === 'interface' ? '单独搜索组件可作为公共数据源的搜索条件。' : '优先使用同级的搜索条件组件,同级搜索不存在时,依次向上选取,与当前组件的搜索条件一同用作数据过滤(当前组件的搜索条件优先)。'}>
                  <QuestionCircleOutlined className="mk-form-tip" />
                  外部搜索
                </Tooltip>
@@ -513,7 +575,7 @@
                  initialValue: setting.useMSearch || 'true'
                })(
                  <Radio.Group onChange={(e) => {this.onOptionChange(e.target.value, 'useMSearch')}}>
                    <Radio value="true">使用</Radio>
                    <Radio value="true">使用{!hasMainSearch ? <Tooltip placement="top" title="无可使用的外部搜索条件"><span className="mk-dot"></span></Tooltip> : null}</Radio>
                    <Radio value="false">不使用</Radio>
                  </Radio.Group>
                )}
@@ -544,6 +606,23 @@
                  <Radio.Group onChange={(e) => {this.onOptionChange(e.target.value, 'onload')}}>
                    <Radio value="true">加载</Radio>
                    <Radio value="false">不加载</Radio>
                  </Radio.Group>
                )}
              </Form.Item>
            </Col> : null}
            {setting.interType === 'system' ? <Col span={8}>
              <Form.Item label={
                <Tooltip placement="topLeft" title="使用后端sql脚本时有效。">
                  <QuestionCircleOutlined className="mk-form-tip" />
                  事务
                </Tooltip>
              }>
                {getFieldDecorator('transact', {
                  initialValue: setting.transact || 'false'
                })(
                  <Radio.Group onChange={(e) => {this.onOptionChange(e.target.value, 'transact')}}>
                    <Radio value="true">启用</Radio>
                    <Radio value="false">禁用</Radio>
                  </Radio.Group>
                )}
              </Form.Item>
@@ -600,7 +679,7 @@
            </Col> : null}
            {config.subtype === 'dualdatacard' ? <Col span={8}>
              <Form.Item label={
                <Tooltip placement="topLeft" title="子表在主表中的数据集名称。">
                <Tooltip placement="topLeft" title="子表在主表中的数据集名称,使用 sub_data_string 时数据以 JSON 字符串形式返回(字段集中需添加 sub_data_string 字段);当主表字段存在 sub_data_string 且值不为空时,优先使用主表的 sub_data_string。">
                  <QuestionCircleOutlined className="mk-form-tip" />
                  子表字段
                </Tooltip>
@@ -610,7 +689,7 @@
                  rules: [
                    {
                      required: true,
                      message: '请输入默认排序!'
                      message: '请输入子表字段!'
                    }
                  ]
                })(<Input placeholder={''} autoComplete="off" />)}
@@ -621,10 +700,10 @@
                {getFieldDecorator('subKey', {
                  initialValue: setting.subKey || ''
                })(
                  <Select>
                  <Select showSearch filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}>
                    {this.props.subColumns.map((option, i) =>
                      <Select.Option key={i} value={option.field}>
                        {option.label}
                        {`${option.label}(${option.field})`}
                      </Select.Option>
                    )}
                  </Select>
@@ -636,18 +715,43 @@
                {getFieldDecorator('subBID', {
                  initialValue: setting.subBID || ''
                })(
                  <Select>
                  <Select showSearch filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}>
                    {this.props.subColumns.map((option, i) =>
                      <Select.Option key={i} value={option.field}>
                        {option.label}
                        {`${option.label}(${option.field})`}
                      </Select.Option>
                    )}
                  </Select>
                )}
              </Form.Item>
            </Col> : null}
            {setting.onload !== 'false' ? <Col span={8}>
              <Form.Item label={
                <Tooltip placement="topLeft" title="可延迟初始化数据的加载时间,单位毫秒(ms)。">
                  <QuestionCircleOutlined className="mk-form-tip" />
                  延时加载
                </Tooltip>
              }>
                {getFieldDecorator('delay', {
                  initialValue: setting.delay,
                })(<InputNumber min={0} max={60000} precision={0} />)}
              </Form.Item>
            </Col> : null}
          </Row>
        </Form>
        <Modal
          wrapClassName="mk-flow-type"
          visible={visible}
          width={400}
          onCancel={() => this.setState({visible: false})}
          footer={[
            <Button key="cancel" className="mk-green" onClick={() => this.execAddProcess('flowstart')}>发起</Button>,
            <Button key="confirm" className="mk-primary" onClick={() => this.execAddProcess('flowcheck')}>审批</Button>
          ]}
          destroyOnClose
        >
          请选择工作流类型。
        </Modal>
      </div>
    )
  }