import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { Form, Row, Col, Input, Select, notification, Radio, Icon, Tooltip, InputNumber, Switch } from 'antd'
|
|
import Api from '@/api'
|
import options from '@/store/options.js'
|
import './index.scss'
|
|
class CustomMenuForm extends Component {
|
static propTpyes = {
|
dict: PropTypes.object, // 字典项
|
config: PropTypes.object,
|
MenuId: PropTypes.string,
|
MenuName: PropTypes.string,
|
MenuNo: PropTypes.string,
|
parentId: PropTypes.string,
|
updateConfig: PropTypes.func
|
}
|
|
state = {
|
fstMenuId: '',
|
menulist: [],
|
smenulist: []
|
}
|
|
UNSAFE_componentWillMount () {
|
const { MenuId, config } = this.props
|
let _param = {func: 's_get_pc_menus', systemType: options.sysType, debug: 'Y'}
|
_param.pro_sys = window.GLOB.systemType === 'production' ? 'Y' : ''
|
|
Api.getSystemConfig(_param).then(result => {
|
if (result.status) {
|
let thdMenu = null
|
let thdMenuList = []
|
let menulist = result.fst_menu.map(fst => {
|
let fstItem = {
|
MenuID: fst.MenuID,
|
MenuName: fst.MenuName,
|
value: fst.MenuID,
|
label: fst.MenuName,
|
isLeaf: false,
|
children: []
|
}
|
|
if (fst.snd_menu) {
|
fstItem.children = fst.snd_menu.map(snd => {
|
let sndItem = {
|
ParentId: fst.MenuID,
|
MenuID: snd.MenuID,
|
MenuName: snd.MenuName,
|
value: snd.MenuID,
|
label: snd.MenuName,
|
children: []
|
}
|
|
if (snd.trd_menu) {
|
sndItem.children = snd.trd_menu.map(trd => {
|
let trdItem = {
|
FstId: fst.MenuID,
|
ParentId: snd.MenuID,
|
MenuID: trd.MenuID,
|
MenuName: trd.MenuName,
|
MenuNo: trd.MenuNo,
|
EasyCode: trd.EasyCode,
|
value: trd.MenuID,
|
label: trd.MenuName,
|
type: 'CommonTable',
|
// disabled: trd.MenuID === MenuId
|
disabled: false
|
}
|
|
if (MenuId === trd.MenuID) {
|
thdMenu = trdItem
|
}
|
|
if (trd.PageParam) {
|
try {
|
trd.PageParam = JSON.parse(trd.PageParam)
|
trdItem.type = trd.PageParam.Template || 'CommonTable'
|
} catch (e) {
|
|
}
|
}
|
|
thdMenuList.push(trdItem)
|
|
return trdItem
|
})
|
}
|
return sndItem
|
})
|
}
|
return fstItem
|
})
|
|
let smenulist = []
|
menulist.forEach(item => {
|
if (thdMenu && (item.MenuID === thdMenu.FstId)) {
|
smenulist = item.children
|
}
|
})
|
sessionStorage.setItem('fstMenuList', JSON.stringify(menulist))
|
sessionStorage.setItem('thdMenuList', JSON.stringify(thdMenuList))
|
this.props.updateConfig({...config, fstMenuId: thdMenu ? thdMenu.FstId : ''})
|
|
this.setState({
|
fstMenuId: thdMenu ? thdMenu.FstId : '',
|
menulist,
|
smenulist
|
}, () => {
|
this.props.form.setFieldsValue({
|
fstMenuId: thdMenu ? thdMenu.FstId : '',
|
parentId: thdMenu ? thdMenu.ParentId : ''
|
})
|
})
|
} else {
|
notification.warning({
|
top: 92,
|
message: result.message,
|
duration: 5
|
})
|
}
|
})
|
}
|
|
// 一二级菜单切换
|
selectChange = (key, value) => {
|
const { config } = this.props
|
const { menulist } = this.state
|
|
if (key === 'fstMenuId') {
|
let smenulist = []
|
menulist.forEach(item => {
|
if (item.MenuID === value) {
|
smenulist = item.children
|
}
|
})
|
|
this.setState({
|
smenulist
|
}, () => {
|
let _id = smenulist[0] ? smenulist[0].MenuID : ''
|
this.props.form.setFieldsValue({parentId: _id})
|
this.props.updateConfig({...config, fstMenuId: value, parentId: _id})
|
})
|
} else if (key === 'parentId') {
|
this.props.updateConfig({...config, parentId: value})
|
} else if (key === 'cacheUseful') {
|
this.props.updateConfig({...config, cacheUseful: value})
|
} else if (key === 'timeUnit') {
|
this.props.updateConfig({...config, timeUnit: value})
|
} else if (key === 'OpenType') {
|
this.props.updateConfig({...config, OpenType: value})
|
} else if (key === 'hidden') {
|
this.props.updateConfig({...config, hidden: value})
|
}
|
}
|
|
// 菜单名称
|
changeName = (e) => {
|
this.props.updateConfig({...this.props.config, MenuName: e.target.value})
|
}
|
|
// 菜单参数
|
changeNo = (e) => {
|
this.props.updateConfig({...this.props.config, MenuNo: e.target.value})
|
}
|
|
// 助记码
|
changeEasyCode = (e) => {
|
this.props.updateConfig({...this.props.config, easyCode: e.target.value})
|
}
|
|
changeCacheDay = (val) => {
|
if (typeof(val) !== 'number') {
|
val = ''
|
}
|
this.props.updateConfig({...this.props.config, cacheTime: val})
|
}
|
|
render() {
|
const { dict, MenuName, MenuNo, config } = this.props
|
const { menulist, smenulist } = this.state
|
const { getFieldDecorator } = this.props.form
|
const formItemLayout = {
|
labelCol: {
|
xs: { span: 24 },
|
sm: { span: 8 }
|
},
|
wrapperCol: {
|
xs: { span: 24 },
|
sm: { span: 16 }
|
}
|
}
|
|
return (
|
<Form {...formItemLayout} className="custom-menu-form">
|
<Row>
|
<Col span={24}>
|
<Form.Item label={dict['mob.menu.first'] + dict['mob.menu']}>
|
{getFieldDecorator('fstMenuId', {
|
initialValue: '',
|
rules: [
|
{
|
required: true,
|
message: dict['mob.required.select'] + dict['mob.menu.first'] + dict['mob.menu'] + '!'
|
}
|
]
|
})(
|
<Select onChange={(value) => {this.selectChange('fstMenuId', value)}}>
|
{menulist.map(option =>
|
<Select.Option key={option.MenuID} value={option.MenuID}>
|
{option.MenuName}
|
</Select.Option>
|
)}
|
</Select>
|
)}
|
</Form.Item>
|
</Col>
|
<Col span={24}>
|
<Form.Item label={dict['mob.menu.second'] + dict['mob.menu']}>
|
{getFieldDecorator('parentId', {
|
initialValue: '',
|
rules: [
|
{
|
required: true,
|
message: dict['mob.required.select'] + dict['mob.menu.second'] + dict['mob.menu'] + '!'
|
}
|
]
|
})(
|
<Select onChange={(value) => {this.selectChange('parentId', value)}}>
|
{smenulist.map(option =>
|
<Select.Option key={option.MenuID} value={option.MenuID}>
|
{option.MenuName}
|
</Select.Option>
|
)}
|
</Select>
|
)}
|
</Form.Item>
|
</Col>
|
<Col span={24}>
|
<Form.Item label={dict['mob.menu'] + dict['mob.name']}>
|
{getFieldDecorator('MenuName', {
|
initialValue: MenuName,
|
rules: [
|
{
|
required: true,
|
message: dict['mob.required.input'] + dict['mob.menu'] + dict['mob.name'] + '!'
|
}
|
]
|
})(<Input placeholder="" autoComplete="off" onChange={this.changeName}/>)}
|
</Form.Item>
|
</Col>
|
<Col span={24}>
|
<Form.Item label={dict['mob.menu'] + dict['mob.param']}>
|
{getFieldDecorator('MenuNo', {
|
initialValue: MenuNo,
|
rules: [
|
{
|
required: true,
|
message: dict['mob.required.input'] + dict['mob.menu'] + dict['mob.param'] + '!'
|
}
|
]
|
})(<Input placeholder="" autoComplete="off" onChange={this.changeNo}/>)}
|
</Form.Item>
|
</Col>
|
<Col span={24}>
|
<Form.Item label="打开方式">
|
{getFieldDecorator('OpenType', {
|
initialValue: config.OpenType || 'newtab',
|
rules: [
|
{
|
required: true,
|
message: dict['form.required.select'] + dict['model.openway'] + '!'
|
}
|
]
|
})(
|
<Radio.Group onChange={(e) => {this.selectChange('OpenType', e.target.value)}}>
|
<Radio value="newtab">标签页</Radio>
|
<Radio value="newpage">新页面</Radio>
|
</Radio.Group>
|
)}
|
</Form.Item>
|
</Col>
|
<Col span={24}>
|
<Form.Item label={
|
<Tooltip placement="topLeft" title="对于不经常性变动的信息,缓存数据有助于提高查询效率。">
|
<Icon type="question-circle" />
|
缓存数据
|
</Tooltip>
|
}>
|
{getFieldDecorator('cacheUseful', {
|
initialValue: config.cacheUseful || 'false'
|
})(
|
<Radio.Group onChange={(e) => {this.selectChange('cacheUseful', e.target.value)}}>
|
<Radio value="true">使用</Radio>
|
<Radio value="false">不使用</Radio>
|
</Radio.Group>
|
)}
|
</Form.Item>
|
</Col>
|
<Col span={24}>
|
<Form.Item label={
|
<Tooltip placement="topLeft" title="跳过权限验证时,页面中组件及按钮不在进行权限控制。">
|
<Icon type="question-circle" />
|
权限验证
|
</Tooltip>
|
}>
|
{getFieldDecorator('permission', {
|
initialValue: config.permission || 'true'
|
})(
|
<Radio.Group onChange={(e) => {this.selectChange('permission', e.target.value)}}>
|
<Radio value="true">使用</Radio>
|
<Radio value="false">不使用</Radio>
|
</Radio.Group>
|
)}
|
</Form.Item>
|
</Col>
|
{config.cacheUseful === 'true' ? <Col span={24}>
|
<Form.Item label="单位">
|
{getFieldDecorator('timeUnit', {
|
initialValue: config.timeUnit || 'day'
|
})(
|
<Radio.Group onChange={(e) => {this.selectChange('timeUnit', e.target.value)}}>
|
<Radio value="day">天</Radio>
|
<Radio value="hour">小时</Radio>
|
</Radio.Group>
|
)}
|
</Form.Item>
|
</Col> : null}
|
{config.cacheUseful === 'true' ? <Col span={24}>
|
<Form.Item label="时长">
|
{getFieldDecorator('cacheTime', {
|
initialValue: config.cacheTime,
|
rules: [
|
{
|
required: true,
|
message: dict['mob.required.input'] + '时长!'
|
}
|
]
|
})(
|
<InputNumber min={1} max={config.timeUnit !== 'hour' ? 7 : 23} precision={0} onChange={this.changeCacheDay}/>
|
)}
|
</Form.Item>
|
</Col> : null}
|
<Col span={24}>
|
<Form.Item label={dict['mob.menu.easycode']}>
|
{getFieldDecorator('easyCode', {
|
initialValue: config.easyCode
|
})(<Input placeholder="" autoComplete="off" onChange={this.changeEasyCode}/>)}
|
</Form.Item>
|
</Col>
|
<Col span={24}>
|
<Form.Item label={'隐藏菜单'}>
|
<Switch checkedChildren={'是'} checked={config.hidden === 'true'} unCheckedChildren={'否'} onChange={(value) => {
|
this.selectChange('hidden', value + '')
|
}} />
|
</Form.Item>
|
</Col>
|
</Row>
|
</Form>
|
)
|
}
|
}
|
|
export default Form.create()(CustomMenuForm)
|