| | |
| | | import React, {Component} from 'react' |
| | | import PropTypes from 'prop-types' |
| | | import { Form, Row, Col, Input, Select, Radio } from 'antd' |
| | | import { fromJS } from 'immutable' |
| | | import { Form, Row, Col, Input, Radio } from 'antd' |
| | | |
| | | import Utils from '@/utils/utils.js' |
| | | import './index.scss' |
| | | |
| | | class MainSearch extends Component { |
| | | static propTpyes = { |
| | | menu: PropTypes.any, // 菜单信息,新建时为null |
| | | dict: PropTypes.object, // 字典项 |
| | | type: PropTypes.string, // 操作类型 |
| | | inputSubmit: PropTypes.func |
| | | } |
| | |
| | | { |
| | | type: 'text', |
| | | key: 'menuName', |
| | | label: this.props.dict['model.menu'] + this.props.dict['model.name'], |
| | | label: '菜单名称', |
| | | initVal: '', |
| | | required: true, |
| | | readonly: false |
| | |
| | | { |
| | | type: 'radio', |
| | | key: 'openType', |
| | | label: this.props.dict['model.openway'], |
| | | label: '打开方式', |
| | | initVal: 'menu', |
| | | required: true, |
| | | options: [{ |
| | | id: 'menu', |
| | | text: this.props.dict['model.menu'] |
| | | text: '菜单' |
| | | }, { |
| | | id: 'outpage', |
| | | text: '外部页面' |
| | |
| | | initVal: '', |
| | | hidden: true, |
| | | required: true |
| | | }, |
| | | { |
| | | type: 'text', |
| | | key: 'linkProUrl', |
| | | label: '正式地址', |
| | | initVal: '', |
| | | hidden: true, |
| | | required: false |
| | | } |
| | | ] |
| | | } |
| | |
| | | UNSAFE_componentWillMount () { |
| | | const { menu } = this.props |
| | | |
| | | if (this.props.type === 'add') { |
| | | if (!menu) { |
| | | this.setState({ |
| | | formlist: this.state.defaultMenu |
| | | formlist: fromJS(this.state.defaultMenu).toJS() |
| | | }) |
| | | } else { |
| | | this.setState({ |
| | | formlist: this.state.defaultMenu.map(item => { |
| | | formlist: fromJS(this.state.defaultMenu).toJS().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 |
| | | } else if (item.key === 'linkUrl' || item.key === 'linkProUrl') { |
| | | item.initVal = menu.PageParam[item.key] || '' |
| | | if (menu.PageParam.OpenType === 'menu') { |
| | | item.hidden = true |
| | | } else if (menu.PageParam.OpenType === 'outpage') { |
| | |
| | | |
| | | openTypeChange = (key, value) => { |
| | | if (key === 'openType') { |
| | | let formlist = this.state.formlist |
| | | if (value === 'outpage') { |
| | | formlist.forEach(item => { |
| | | if (item.key === 'linkUrl') { |
| | | item.hidden = false |
| | | item.initVal = '' |
| | | } |
| | | }) |
| | | } else { |
| | | formlist.forEach(item => { |
| | | if (item.key === 'linkUrl') { |
| | | item.hidden = true |
| | | } |
| | | }) |
| | | } |
| | | let formlist = fromJS(this.state.formlist).toJS() |
| | | |
| | | formlist.forEach(item => { |
| | | if (item.key === 'linkUrl' || item.key === 'linkProUrl') { |
| | | item.hidden = value !== 'outpage' |
| | | } |
| | | }) |
| | | |
| | | this.setState({formlist}) |
| | | } |
| | |
| | | rules: [ |
| | | { |
| | | required: !!item.required, |
| | | message: this.props.dict['form.required.input'] + item.label + '!' |
| | | message: '请输入' + item.label + '!' |
| | | } |
| | | ] |
| | | })(<Input placeholder="" autoFocus={item.key.toLowerCase() === 'menuname'} autoComplete="off" disabled={item.readonly} />)} |
| | | </Form.Item> |
| | | </Col> |
| | | ) |
| | | } else if (item.type === 'select') { // 下拉搜索 |
| | | } else if (item.type === 'radio') { |
| | | fields.push( |
| | | <Col span={24} key={index}> |
| | | <Form.Item label={item.label}> |
| | |
| | | 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('first-menu-form-box')} |
| | | > |
| | | {item.options.map(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 + '!' |
| | | message: '请选择' + item.label + '!' |
| | | } |
| | | ] |
| | | })( |
| | |
| | | } |
| | | |
| | | handleConfirm = () => { |
| | | const { menu } = this.props |
| | | |
| | | // 表单提交时检查输入值是否正确 |
| | | return new Promise((resolve, reject) => { |
| | | this.props.form.validateFieldsAndScroll((err, values) => { |
| | | if (!err) { |
| | | if (this.props.type === 'add') { |
| | | resolve({ |
| | | MenuID: Utils.getuuid(), |
| | | MenuName: values.menuName, |
| | | PageParam: JSON.stringify({ |
| | | OpenType: values.openType, |
| | | linkUrl: values.openType !== 'menu' ? values.linkUrl : '' |
| | | }) |
| | | }) |
| | | } else { |
| | | resolve({ |
| | | MenuID: this.props.menu.MenuID, |
| | | MenuName: values.menuName, |
| | | PageParam: JSON.stringify({ |
| | | OpenType: values.openType, |
| | | linkUrl: values.openType !== 'menu' ? values.linkUrl : '' |
| | | }) |
| | | }) |
| | | if (err) return |
| | | |
| | | let PageParam = { |
| | | OpenType: values.openType |
| | | } |
| | | |
| | | if (values.openType !== 'menu') { |
| | | PageParam.linkUrl = values.linkUrl || '' |
| | | if (values.linkProUrl) { |
| | | PageParam.linkProUrl = values.linkProUrl |
| | | } |
| | | } |
| | | |
| | | if (!menu) { |
| | | resolve({ |
| | | MenuID: Utils.getuuid(), |
| | | MenuName: values.menuName, |
| | | PageParam: JSON.stringify(PageParam) |
| | | }) |
| | | } else { |
| | | reject(err) |
| | | resolve({ |
| | | MenuID: menu.MenuID, |
| | | MenuName: values.menuName, |
| | | PageParam: JSON.stringify(PageParam) |
| | | }) |
| | | } |
| | | }) |
| | | }) |