import React, { PureComponent } from 'react'; import { Form, Input, Card, Row, Col, Button, InputNumber, TreeSelect, Radio, Icon, Modal, message, } from 'antd'; import { connect } from 'dva'; import Panel from '../../../components/Panel'; import styles from '../../../layouts/Sword.less'; import { MENU_DETAIL, MENU_INIT, MENU_SUBMIT } from '../../../actions/menu'; import func from '../../../utils/Func'; import IconPreview from '../../../components/IconPreview'; const FormItem = Form.Item; const { TextArea, Search } = Input; const RadioGroup = Radio.Group; @connect(({ menu, loading }) => ({ menu, submitting: loading.effects['menu/submit'], })) @Form.create() class MenuEdit extends PureComponent { state = { visible: false }; componentWillMount() { const { dispatch, match: { params: { id }, }, } = this.props; dispatch(MENU_DETAIL(id)); dispatch(MENU_INIT()); } handleSubmit = e => { e.preventDefault(); const { dispatch, match: { params: { id }, }, form, } = this.props; const parentId = form.getFieldValue('parentId'); if (id === parentId.toString()) { message.warn('上级菜单不能选择自身!'); return; } form.validateFieldsAndScroll((err, values) => { if (!err) { const params = { id, ...values, }; dispatch(MENU_SUBMIT(params)); } }); }; showModal = () => { this.setState({ visible: true, }); }; handleCancel = () => { this.setState({ visible: false, }); }; handleSyncLocale = () => { const { form } = this.props; const locale = form.getFieldValue('menuLocale'); if (func.isEmpty(locale)) { const code = form.getFieldValue('code'); form.setFieldsValue({ menuLocale: code }); } }; render() { const { form: { getFieldDecorator }, menu: { detail, init: { tree }, }, submitting, } = this.props; const { visible } = this.state; const formItemLayout = { labelCol: { span: 8, }, wrapperCol: { span: 16, }, }; const formAllItemLayout = { labelCol: { span: 4, }, wrapperCol: { span: 20, }, }; const action = ( ); return (
{getFieldDecorator('name', { rules: [ { required: true, message: '请输入菜单名称', }, ], initialValue: detail.name, })()} {getFieldDecorator('path', { rules: [ { required: true, message: '请输入路由地址', }, ], initialValue: detail.path, })()} {getFieldDecorator('parentId', { initialValue: detail.parentId, })( )} {getFieldDecorator('source', { initialValue: detail.source, })( } placeholder="请选择菜单图标" onSearch={this.showModal} enterButton /> )} {getFieldDecorator('code', { rules: [ { required: true, message: '请输入菜单编号', }, ], initialValue: detail.code, })()} {getFieldDecorator('category', { rules: [ { required: true, message: '请选择菜单类型', }, ], initialValue: detail.category, })( 菜单 按钮 )} {getFieldDecorator('alias', { rules: [ { required: true, message: '请选择菜单别名', }, ], initialValue: detail.alias, })()} {getFieldDecorator('action', { rules: [ { required: true, message: '请选择按钮功能', }, ], initialValue: detail.action, })( 工具栏 操作栏 工具操作栏 )} {getFieldDecorator('sort', { rules: [ { required: true, message: '请输入菜单排序', }, ], initialValue: detail.sort, })()} {getFieldDecorator('isOpen', { rules: [ { required: true, message: '请选择是否新窗口打开', }, ], initialValue: detail.isOpen, })( )} {getFieldDecorator('remark', { initialValue: detail.remark, })(