import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { Form, Row, Col, Radio, Tooltip, InputNumber, notification } from 'antd'
|
import { QuestionCircleOutlined } from '@ant-design/icons'
|
|
import Api from '@/api'
|
import options from '@/store/options.js'
|
// import './index.scss'
|
|
class CustomMenuForm extends Component {
|
static propTpyes = {
|
config: PropTypes.object,
|
updateConfig: PropTypes.func
|
}
|
|
state = {}
|
|
UNSAFE_componentWillMount () {
|
if (sessionStorage.getItem('thdMenuList') && sessionStorage.getItem('fstMenuList')) {
|
|
} else {
|
this.getMenus()
|
}
|
}
|
|
getMenus = () => {
|
Api.getSystemConfig({func: 's_get_pc_menus', systemType: options.sysType, debug: 'Y'}).then(result => {
|
if (result.status) {
|
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: false
|
}
|
|
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
|
})
|
|
sessionStorage.setItem('fstMenuList', JSON.stringify(menulist))
|
sessionStorage.setItem('thdMenuList', JSON.stringify(thdMenuList))
|
} else {
|
notification.warning({
|
top: 92,
|
message: result.message,
|
duration: 5
|
})
|
}
|
})
|
}
|
|
// 一二级菜单切换
|
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})
|
} else if (key === 'cacheLocal') {
|
this.props.updateConfig({...config, cacheLocal: value})
|
}
|
}
|
|
changeCacheDay = (val) => {
|
if (typeof(val) !== 'number') {
|
val = ''
|
}
|
this.props.updateConfig({...this.props.config, cacheTime: val})
|
}
|
|
render() {
|
const { 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}>
|
<Row>
|
<Col span={24}>
|
<Form.Item label={
|
<Tooltip placement="topLeft" title="数据会缓存到用户本地,方便页面快速呈现。">
|
<QuestionCircleOutlined className="mk-form-tip" />
|
本地缓存
|
</Tooltip>
|
}>
|
{getFieldDecorator('cacheLocal', {
|
initialValue: config.cacheLocal || 'false'
|
})(
|
<Radio.Group onChange={(e) => {this.selectChange('cacheLocal', 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="对于不经常性变动的信息,缓存数据有助于提高查询效率。">
|
<QuestionCircleOutlined className="mk-form-tip" />
|
后端缓存
|
</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: '请输入时长!'
|
}
|
]
|
})(
|
<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)
|