king
2020-11-23 f8c3c53f9e29541f8c0e3fcbf682c301fd17e06a
src/templates/menuconfig/editfirstmenu/menuform/index.jsx
File was renamed from src/templates/headerconfig/menuform/index.jsx
@@ -1,6 +1,6 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { Form, Row, Col, Input, Select } from 'antd'
import { Form, Row, Col, Input, Select, Radio } from 'antd'
import Utils from '@/utils/utils.js'
import './index.scss'
@@ -23,7 +23,7 @@
        readonly: false
      },
      {
        type: 'select',
        type: 'radio',
        key: 'openType',
        label: this.props.dict['model.openway'],
        initVal: 'menu',
@@ -31,44 +31,45 @@
        options: [{
          id: 'menu',
          text: this.props.dict['model.menu']
        // }, {
        //   id: 'newpage',
        //   text: this.props.dict['model.new'] + this.props.dict['model.window']
        }, {
          id: 'outpage',
          text: '外部页面'
        }]
      },
      {
        type: 'select',
        type: 'text',
        key: 'linkUrl',
        label: '页面地址',
        initVal: '',
        hidden: true,
        label: this.props.dict['model.new'] + this.props.dict['model.window'],
        initVal: 'service',
        required: true,
        options: []
        required: true
      }
    ]
  }
  UNSAFE_componentWillMount () {
    const { menu } = this.props
    if (this.props.type === 'add') {
      this.setState({
        formlist: this.state.defaultMenu
      })
    } else {
      this.setState({
        formlist: this.state.defaultMenu.map(menu => {
          if (menu.key === 'menuName') {
            menu.initVal = this.props.menu.MenuName
          } else if (menu.key === 'openType') {
            menu.initVal = this.props.menu.PageParam.OpenType
          } else if (menu.key === 'linkUrl') {
            menu.initVal = this.props.menu.PageParam.linkUrl
            if (this.props.menu.PageParam.OpenType === 'menu') {
              menu.hidden = true
            } else if (this.props.menu.PageParam.OpenType === 'newpage') {
              menu.hidden = false
        formlist: this.state.defaultMenu.map(item => {
          if (item.key === 'menuName') {
            item.initVal = menu.MenuName
          } else if (item.key === 'openType') {
            item.initVal = menu.PageParam.OpenType
          } else if (item.key === 'linkUrl') {
            item.initVal = menu.PageParam.linkUrl
            if (menu.PageParam.OpenType === 'menu') {
              item.hidden = true
            } else if (menu.PageParam.OpenType === 'outpage') {
              item.hidden = false
            }
          }
          return menu
          return item
        })
      })
    }
@@ -77,11 +78,11 @@
  openTypeChange = (key, value) => {
    if (key === 'openType') {
      let formlist = this.state.formlist
      if (value === 'newpage') {
      if (value === 'outpage') {
        formlist.forEach(item => {
          if (item.key === 'linkUrl') {
            item.hidden = false
            item.initVal = 'service'
            item.initVal = ''
          }
        })
      } else {
@@ -91,6 +92,7 @@
          }
        })
      }
      this.setState({formlist})
    }
  }
@@ -137,13 +139,39 @@
                  getPopupContainer={() => document.getElementById('form-box')}
                >
                  {item.options.map(option =>
                    <Select.Option id={option.id} title={option.text} key={option.id} value={option.id}>{option.text}</Select.Option>
                    <Select.Option key={option.id} value={option.id}>{option.text}</Select.Option>
                  )}
                </Select>
              )}
            </Form.Item>
          </Col>
        )
      } else if (item.type === 'radio') { // 下拉搜索
        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 + '!'
                  }
                ]
              })(
                <Radio.Group onChange={(e) => {this.openTypeChange(item.key, e.target.value)}}>
                  {
                    item.options.map(option => {
                      return (
                        <Radio key={option.id} value={option.id}>{option.text}</Radio>
                      )
                    })
                  }
                </Radio.Group>
              )}
            </Form.Item>
          </Col>
        )
      }
    })