| | |
| | | import React, {Component} from 'react' |
| | | import PropTypes from 'prop-types' |
| | | import { Form, Row, Col, Input, Select, Radio } from 'antd' |
| | | 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: '外部页面' |
| | |
| | | UNSAFE_componentWillMount () { |
| | | const { menu } = this.props |
| | | |
| | | if (this.props.type === 'add') { |
| | | if (!menu) { |
| | | this.setState({ |
| | | formlist: this.state.defaultMenu |
| | | }) |
| | |
| | | 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') { |
| | | if (err) return |
| | | |
| | | if (!menu) { |
| | | resolve({ |
| | | MenuID: Utils.getuuid(), |
| | | MenuName: values.menuName, |
| | |
| | | }) |
| | | } else { |
| | | resolve({ |
| | | MenuID: this.props.menu.MenuID, |
| | | MenuID: menu.MenuID, |
| | | MenuName: values.menuName, |
| | | PageParam: JSON.stringify({ |
| | | OpenType: values.openType, |
| | | linkUrl: values.openType !== 'menu' ? values.linkUrl : '' |
| | | }) |
| | | }) |
| | | } |
| | | } else { |
| | | reject(err) |
| | | } |
| | | }) |
| | | }) |