From ab60d53b67f802878662aaa5a5b52580cca421b8 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期六, 26 九月 2020 08:52:46 +0800 Subject: [PATCH] 2020-09-26 --- src/menu/datasource/verifycard/settingform/index.jsx | 95 +++++++++++++++++++++++++++++++++-------------- 1 files changed, 66 insertions(+), 29 deletions(-) diff --git a/src/menu/datasource/verifycard/settingform/index.jsx b/src/menu/datasource/verifycard/settingform/index.jsx index e0d1773..ab33160 100644 --- a/src/menu/datasource/verifycard/settingform/index.jsx +++ b/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> -- Gitblit v1.8.0