king
2020-09-26 ab60d53b67f802878662aaa5a5b52580cca421b8
src/menu/datasource/verifycard/settingform/index.jsx
@@ -1,6 +1,6 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { Form, Row, Col, Input, Radio, Tooltip, Icon, notification, Select, InputNumber } from 'antd'
import { Form, Row, Col, Input, Radio, Tooltip, Icon, notification, Select, InputNumber, Cascader } from 'antd'
import { formRule } from '@/utils/option.js'
import Utils from '@/utils/utils.js'
@@ -13,37 +13,81 @@
    menu: PropTypes.any,          // 菜单配置信息
    config: PropTypes.object,     // 组件配置
    setting: PropTypes.object,    // 数据源配置
    modules: PropTypes.array,     // 列设置
    columns: PropTypes.array,     // 列设置
    scripts: PropTypes.array,     // 自定义脚本
  }
  state = {
    interType: this.props.setting.interType || 'system',
    supModule: '',
    modules: []
  }
  UNSAFE_componentWillMount () {
    const { menu, setting, config } = this.props
    let supModule = setting.supModule || ''
    let modules = []
    const { menu, config } = this.props
    menu.components.forEach(item => {
      if (!item.switchable || !item.setting || !item.setting.name || item.uuid === config.uuid) return
      modules.push({
        value: item.uuid,
        text: item.setting.name
      })
    })
    if (supModule && supModule !== 'empty') {
      if (modules.filter(item => item.value === supModule).length === 0) {
        supModule = ''
      }
    let modules = this.getModules(menu.components, config.uuid)
    if (!modules) {
      modules = []
    }
    this.setState({supModule, modules})
    modules.unshift({
      value: 'empty',
      label: '无'
    })
    this.setState({modules})
  }
  getModules = (components, selfId) => {
    let modules = components.map(item => {
      if (item.uuid === selfId) {
        return {
          children: null
        }
      } else if (item.switchable) {
        return {
          value: item.uuid,
          label: item.name
        }
      } else if (item.type === 'tabs') {
        let _item = {
          value: item.uuid,
          label: item.name,
          children: item.subtabs.map(f_tab => {
            let subItem = {
              value: f_tab.uuid,
              label: f_tab.label,
              children: this.getModules(f_tab.components, selfId)
            }
            if (!subItem.children || subItem.children.length === 0) {
              return {children: null}
            }
            return subItem
          })
        }
        _item.children = _item.children.filter(t => t.children !== null)
        if (_item.children.length === 0) {
          return {children: null}
        }
        return _item
      } else {
        return {
          children: null
        }
      }
    })
    modules = modules.filter(mod => mod.children !== null)
    if (modules.length === 0) {
      return null
    }
    return modules
  }
  handleConfirm = () => {
@@ -129,7 +173,7 @@
  render() {
    const { setting, menu, columns, config } = this.props
    const { getFieldDecorator } = this.props.form
    const { interType, supModule, modules } = this.state
    const { interType, modules } = this.state
    const formItemLayout = {
      labelCol: {
@@ -310,7 +354,7 @@
                </Tooltip>
              }>
                {getFieldDecorator('supModule', {
                  initialValue: supModule,
                  initialValue: setting.supModule || [],
                  rules: [
                    {
                      required: true,
@@ -318,14 +362,7 @@
                    }
                  ]
                })(
                  <Select>
                    <Select.Option key="empty" value="empty"> 无 </Select.Option>
                    {modules.map((option, i) =>
                      <Select.Option key={i} value={option.value}>
                        {option.text}
                      </Select.Option>
                    )}
                  </Select>
                  <Cascader options={modules} expandTrigger="hover" placeholder="" />
                )}
              </Form.Item>
            </Col>