From e1281cc04b886678a5d0561af556a312ef2b9394 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期一, 11 十一月 2019 18:12:28 +0800 Subject: [PATCH] 2019-11-11 --- src/components/sidemenu/menuform/index.jsx | 192 ----------------------------------------------- 1 files changed, 3 insertions(+), 189 deletions(-) diff --git a/src/components/sidemenu/menuform/index.jsx b/src/components/sidemenu/menuform/index.jsx index 71151ef..df67ec6 100644 --- a/src/components/sidemenu/menuform/index.jsx +++ b/src/components/sidemenu/menuform/index.jsx @@ -1,143 +1,12 @@ import React, {Component} from 'react' import PropTypes from 'prop-types' -import { is, fromJS } from 'immutable' import { Form, Row, Col, Input, Select, Icon } from 'antd' -import Utils from '@/utils/utils.js' import './index.scss' class MainSearch extends Component { static propTpyes = { dict: PropTypes.object, // 瀛楀吀椤� - options: PropTypes.object - } - - state = { - formlist: [], - menuform: { - slevel: [ - { - type: 'select', - key: 'parentId', - label: this.props.dict['header.menu.supMenu'], - initVal: '', - required: true, - options: [] - }, - { - type: 'text', - key: 'menuName', - label: this.props.dict['header.menu.menuName'], - initVal: '', - required: true, - readonly: false - }, - { - type: 'select', - key: 'icon', - label: this.props.dict['header.menu.icon'], - initVal: 'folder', - required: true, - options: [{ - MenuID: 'folder', - text: 'folder' - }, { - MenuID: 'api', - text: 'api' - }] - } - ], - tlevel: [ - { - type: 'select', - key: 'parentId', - label: this.props.dict['header.menu.supMenu'], - initVal: '', - required: true, - options: [] - }, - { - type: 'text', - key: 'menuName', - label: this.props.dict['header.menu.menuName'], - initVal: '', - required: true, - readonly: false - }, - { - type: 'text', - key: 'menuNo', - label: this.props.dict['header.menu.menuNo'], - initVal: '', - required: true, - readonly: false - } - ] - } - } - - UNSAFE_componentWillMount () { - this.resetform(this.props.options) - } - - UNSAFE_componentWillReceiveProps (nextProps) { - if (nextProps.options.visible && !is(fromJS(this.props.options), fromJS(nextProps.options))) { - this.resetform(nextProps.options) - } - } - - resetform = (options) => { - if (!options.visible) return - - let formlist = JSON.parse(JSON.stringify(this.state.menuform[options.level])) - if (options.type === 'add' && options.level === 'slevel') { - this.setState({ - formlist: formlist.map(item =>{ - if (item.key === 'parentId') { - item.initVal = options.parentMenu.MenuID - item.options = options.supMenuList - } - return item - }) - }) - } else if (options.type === 'add' && options.level === 'tlevel') { - this.setState({ - formlist: formlist.map(item =>{ - if (item.key === 'parentId') { - item.initVal = options.parentMenu.MenuID - item.options = options.supMenuList - } - return item - }) - }) - } else if (options.type === 'edit' && options.level === 'slevel') { - this.setState({ - formlist: formlist.map(item => { - if (item.key === 'parentId') { - item.initVal = options.parentMenu.MenuID - item.options = options.supMenuList - } else if (item.key === 'menuName') { - item.initVal = options.menu.text - } else if (item.key === 'icon') { - item.initVal = options.menu.PageParam.Icon - } - return item - }) - }) - } else if (options.type === 'edit' && options.level === 'tlevel') { - this.setState({ - formlist: formlist.map(item => { - if (item.key === 'parentId') { - item.initVal = options.parentMenu.MenuID - item.options = options.supMenuList - } else if (item.key === 'menuName') { - item.initVal = options.menu.text - } else if (item.key === 'menuNo') { - item.initVal = options.menu.MenuNo - } - return item - }) - }) - } + formlist: PropTypes.array } openTypeChange = (key, value) => { @@ -164,9 +33,7 @@ getFields() { const { getFieldDecorator } = this.props.form const fields = [] - this.state.formlist.forEach((item, index) => { - if (item.hidden) return - + this.props.formlist.forEach((item, index) => { if (item.type === 'text') { // 鏂囨湰鎼滅储 fields.push( <Col span={24} key={index}> @@ -214,7 +81,6 @@ ) } }) - return fields } @@ -223,64 +89,12 @@ return new Promise((resolve, reject) => { this.props.form.validateFieldsAndScroll((err, values) => { if (!err) { - if (this.props.options.type === 'add' && this.props.options.level === 'slevel') { - // 浜岀骇鑿滃崟娣诲姞 - resolve({ - ParentID: values.parentId, - MenuID: Utils.getuuid(), - MenuName: values.menuName, - PageParam: JSON.stringify({ - Icon: values.icon - }) - }) - } else if (this.props.options.type === 'edit' && this.props.options.level === 'slevel') { - resolve({ - ParentID: values.parentId, - MenuID: this.props.options.menu.MenuID, - MenuName: values.menuName, - PageParam: JSON.stringify({ - Icon: values.icon - }) - }) - } else if (this.props.options.type === 'add' && this.props.options.level === 'tlevel') { - resolve({ - ParentID: values.parentId, - MenuID: this.props.options.menu.MenuID, - MenuName: values.menuName, - PageParam: JSON.stringify({ - Icon: values.icon - }) - }) - } else if (this.props.options.type === 'edit' && this.props.options.level === 'tlevel') { - resolve({ - ParentID: values.parentId, - MenuID: this.props.options.menu.MenuID, - MenuName: values.menuName, - MenuNo: values.menuNo, - PageParam: JSON.stringify({ - Icon: values.icon - }) - }) - } + resolve(values) } else { reject(err) } }) }) - } - - handleReset = (type) => { - // 閲嶇疆 - if (type === 'add') { - let formlist = this.state.formlist.map(item => { - if (item.key === 'linkUrl') { - item.hidden = true - } - return item - }) - this.setState({formlist}) - } - this.props.form.resetFields() } render() { -- Gitblit v1.8.0