| | |
| | | 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' |
| | |
| | | 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 = () => { |
| | |
| | | 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: { |
| | |
| | | </Tooltip> |
| | | }> |
| | | {getFieldDecorator('supModule', { |
| | | initialValue: supModule, |
| | | initialValue: setting.supModule || [], |
| | | rules: [ |
| | | { |
| | | required: true, |
| | |
| | | } |
| | | ] |
| | | })( |
| | | <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> |