From d3edd6d592db12fbec67e2700d168e07546aed29 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期五, 15 十一月 2019 09:46:00 +0800 Subject: [PATCH] 2019-11-15 --- src/components/sidemenu/comtableconfig/actionform/index.jsx | 170 ++++++++++++++++++++++++++++++++++++-------------------- 1 files changed, 108 insertions(+), 62 deletions(-) diff --git a/src/components/sidemenu/comtableconfig/actionform/index.jsx b/src/components/sidemenu/comtableconfig/actionform/index.jsx index e701bbc..4beb9ba 100644 --- a/src/components/sidemenu/comtableconfig/actionform/index.jsx +++ b/src/components/sidemenu/comtableconfig/actionform/index.jsx @@ -1,6 +1,6 @@ import React, {Component} from 'react' import PropTypes from 'prop-types' -import { Form, Row, Col, Input, Select, Icon } from 'antd' +import { Form, Row, Col, Input, Select, Icon, Radio } from 'antd' import './index.scss' const btnIcons = [{ @@ -60,16 +60,62 @@ } state = { + formlist: null, + openType: null, + interType: null + } + openTypeChange = (key, value) => { + if (key === 'OpenType') { + let _options = null + if (value === 'newpage') { + _options = ['label', 'Ot', 'OpenType', 'pageTemplate', 'icon', 'class'] + } else { + if (this.state.interType === 'outer') { + _options = ['label', 'OpenType', 'intertype', 'interface', 'func', 'callbackFunc', 'Ot', 'icon', 'class'] + } else { + _options = ['label', 'OpenType', 'intertype', 'func', 'Ot', 'icon', 'class'] + } + } + this.setState({ + openType: value, + formlist: this.state.formlist.map(item => { + item.hidden = !_options.includes(item.key) + return item + }) + }) + } + } + + onChange = (e, key) => { + let value = e.target.value + if (key === 'intertype') { + let _options = null + if (value === 'outer') { + _options = ['label', 'OpenType', 'intertype', 'interface', 'func', 'callbackFunc', 'Ot', 'icon', 'class'] + } else { + _options = ['label', 'OpenType', 'intertype', 'func', 'Ot', 'icon', 'class'] + } + this.setState({ + interType: value, + formlist: this.state.formlist.map(item => { + item.hidden = !_options.includes(item.key) + return item + }) + }) + } } getFields() { const { getFieldDecorator } = this.props.form const fields = [] - this.props.formlist.forEach((item, index) => { + console.log(this.state.formlist) + this.state.formlist.forEach((item, index) => { + if (item.hidden) return + if (item.type === 'text') { // 鏂囨湰鎼滅储 fields.push( - <Col span={24} key={index}> + <Col span={12} key={index}> <Form.Item label={item.label}> {getFieldDecorator(item.key, { initialValue: item.initVal || '', @@ -83,9 +129,9 @@ </Form.Item> </Col> ) - } else if (item.type === 'select' && item.key === 'icon') { // 涓嬫媺鎼滅储 + } else if (item.type === 'select') { // 涓嬫媺鎼滅储 fields.push( - <Col span={24} key={index}> + <Col span={12} key={index}> <Form.Item label={item.label}> {getFieldDecorator(item.key, { initialValue: item.initVal || '', @@ -99,70 +145,41 @@ <Select showSearch filterOption={(input, option) => option.props.children[2].toLowerCase().indexOf(input.toLowerCase()) >= 0} - getPopupContainer={() => document.getElementById('winter')} - > - {btnIcons.map(option => - <Select.Option id={option.MenuID} title={option.text} key={option.MenuID} value={option.MenuID}> - <Icon type={option.MenuID} /> {option.text} - </Select.Option> - )} - </Select> - )} - </Form.Item> - </Col> - ) - } else if (item.type === 'select' && item.key === 'class') { // 涓嬫媺鎼滅储 - fields.push( - <Col span={24} key={index}> - <Form.Item label={item.label}> - {getFieldDecorator(item.key, { - initialValue: item.initVal || '', - rules: [ - { - required: !!item.required, - message: this.props.dict['form.required.select'] + item.label + '!' - } - ] - })( - <Select - showSearch - filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0} - getPopupContainer={() => document.getElementById('winter')} - > - {btnClasses.map(option => - <Select.Option id={option.MenuID} title={option.text} key={option.MenuID} value={option.MenuID}> - {option.text} - </Select.Option> - )} - </Select> - )} - </Form.Item> - </Col> - ) - } else if (item.type === 'select') { // 涓嬫媺鎼滅储 - fields.push( - <Col span={24} key={index}> - <Form.Item label={item.label}> - {getFieldDecorator(item.key, { - initialValue: item.initVal || '', - rules: [ - { - required: !!item.required, - message: this.props.dict['form.required.select'] + item.label + '!' - } - ] - })( - <Select - showSearch - filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0} + onChange={(value) => {this.openTypeChange(item.key, value)}} getPopupContainer={() => document.getElementById('winter')} > {item.options.map(option => <Select.Option id={option.MenuID} title={option.text} key={option.MenuID} value={option.MenuID}> - {option.text} + {item.key === 'icon' && <Icon type={option.MenuID} />} {option.text} </Select.Option> )} </Select> + )} + </Form.Item> + </Col> + ) + } else if (item.type === 'radio') { + fields.push( + <Col span={12} key={index}> + <Form.Item label={item.label}> + {getFieldDecorator(item.key, { + initialValue: item.initVal, + rules: [ + { + required: !!item.required, + message: this.props.dict['form.required.select'] + item.label + '!' + } + ] + })( + <Radio.Group onChange={(e) => {this.onChange(e, item.key)}}> + { + item.options.map(option => { + return ( + <Radio key={option.MenuID} value={option.MenuID}>{option.text}</Radio> + ) + }) + } + </Radio.Group> )} </Form.Item> </Col> @@ -190,6 +207,35 @@ }) } + UNSAFE_componentWillMount () { + let _opentype = this.props.formlist.filter(form => form.key === 'OpenType')[0].initVal + let _intertype = this.props.formlist.filter(form => form.key === 'intertype')[0].initVal + // let _options = ['label', 'intertype', 'interface', 'func', 'Ot', 'OpenType', 'pageTemplate', 'icon', 'class'] + let _options = null + if (_opentype === 'newpage') { + _options = ['label', 'Ot', 'OpenType', 'pageTemplate', 'icon', 'class'] + } else { + if (_intertype === 'outer') { + _options = ['label', 'OpenType', 'intertype', 'interface', 'func', 'callbackFunc', 'Ot', 'icon', 'class'] + } else { + _options = ['label', 'OpenType', 'intertype', 'func', 'Ot', 'icon', 'class'] + } + } + this.setState({ + openType: _opentype, + interType: _intertype, + formlist: this.props.formlist.map(item => { + if (item.key === 'class') { + item.options = btnClasses + } else if (item.key === 'icon') { + item.options = btnIcons + } + item.hidden = !_options.includes(item.key) + return item + }) + }) + } + render() { const formItemLayout = { labelCol: { -- Gitblit v1.8.0