import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { Form, Row, Col, Input, Radio, Icon, Tooltip, InputNumber } from 'antd'
|
|
import './index.scss'
|
|
class CustomMenuForm extends Component {
|
static propTpyes = {
|
dict: PropTypes.object, // 字典项
|
config: PropTypes.object,
|
MenuId: PropTypes.string,
|
updateConfig: PropTypes.func
|
}
|
|
state = {}
|
|
// 一二级菜单切换
|
selectChange = (key, value) => {
|
const { config } = this.props
|
|
if (key === 'cacheUseful') {
|
this.props.updateConfig({...config, cacheUseful: value})
|
} else if (key === 'timeUnit') {
|
this.props.updateConfig({...config, timeUnit: 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})
|
}
|
|
changeCacheDay = (val) => {
|
if (typeof(val) !== 'number') {
|
val = ''
|
}
|
this.props.updateConfig({...this.props.config, cacheTime: val})
|
}
|
|
render() {
|
const { dict, config } = this.props
|
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'] + dict['mob.name']}>
|
{getFieldDecorator('MenuName', {
|
initialValue: config.MenuName,
|
rules: [
|
{
|
required: true,
|
message: dict['mob.required.input'] + dict['mob.menu'] + dict['mob.name'] + '!'
|
}
|
]
|
})(<Input placeholder="" disabled={!!(config.fixed && config.MenuName)} autoComplete="off" onChange={this.changeName}/>)}
|
</Form.Item>
|
</Col>
|
<Col span={24}>
|
<Form.Item label={dict['mob.menu'] + dict['mob.param']}>
|
{getFieldDecorator('MenuNo', {
|
initialValue: config.MenuNo,
|
rules: [
|
{
|
required: true,
|
message: dict['mob.required.input'] + dict['mob.menu'] + dict['mob.param'] + '!'
|
}
|
]
|
})(<Input placeholder="" disabled={!!(config.fixed && config.MenuName)} autoComplete="off" onChange={this.changeNo}/>)}
|
</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>
|
{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}
|
</Row>
|
</Form>
|
)
|
}
|
}
|
|
export default Form.create()(CustomMenuForm)
|