import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { Form, Row, Col, Input, Radio, Tooltip, InputNumber } from 'antd'
|
import { QuestionCircleOutlined } from '@ant-design/icons'
|
|
import asyncComponent from '@/utils/asyncComponent'
|
import './index.scss'
|
|
const { TextArea } = Input
|
const ColorSketch = asyncComponent(() => import('@/mob/colorsketch'))
|
const SourceComponent = asyncComponent(() => import('@/menu/components/share/sourcecomponent'))
|
|
class CustomMenuForm extends Component {
|
static propTpyes = {
|
config: PropTypes.object,
|
MenuId: PropTypes.string,
|
adapters: PropTypes.array,
|
updateConfig: PropTypes.func
|
}
|
|
state = {}
|
|
componentDidMount() {
|
const { config } = this.props
|
|
if (config.getLocation === 'true') {
|
window.GLOB.getLocation = true
|
}
|
}
|
|
// 一二级菜单切换
|
selectChange = (key, value, hex) => {
|
if (key === 'cacheTime' || key === 'localCacheTime') {
|
if (typeof(value) !== 'number') {
|
value = ''
|
}
|
}
|
|
let _config = {...this.props.config, [key]: value}
|
|
if (key === 'statusBarbgColor') { // 小程序状态栏
|
if (hex) {
|
_config.statusBarHexColor = hex
|
} else {
|
delete _config.statusBarHexColor
|
}
|
} else if (key === 'getLocation') {
|
window.GLOB.getLocation = value === 'true'
|
}
|
|
this.props.updateConfig(_config)
|
}
|
|
render() {
|
const { config, adapters } = 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="菜单名称">
|
{getFieldDecorator('MenuName', {
|
initialValue: config.MenuName,
|
rules: [
|
{
|
required: true,
|
message: '请输入菜单名称!'
|
}
|
]
|
})(<Input placeholder="" autoComplete="off" onChange={(e) => {this.selectChange('MenuName', e.target.value)}}/>)}
|
</Form.Item>
|
</Col>
|
<Col span={24}>
|
<Form.Item label="菜单参数">
|
{getFieldDecorator('MenuNo', {
|
initialValue: config.MenuNo,
|
rules: [
|
{
|
required: true,
|
message: '请输入菜单参数!'
|
}
|
]
|
})(<Input placeholder="" autoComplete="off" onChange={(e) => {this.selectChange('MenuNo', e.target.value)}}/>)}
|
</Form.Item>
|
</Col>
|
<Col span={24}>
|
<Form.Item label={
|
<Tooltip placement="topLeft" title="是否检验后端sql的权限,使用后端sql脚本时有效。">
|
<QuestionCircleOutlined className="mk-form-tip" />
|
sql验证
|
</Tooltip>
|
}>
|
{getFieldDecorator('sqlperm', {
|
initialValue: config.sqlperm || 'true'
|
})(
|
<Radio.Group onChange={(e) => {this.selectChange('sqlperm', 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('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>
|
{config.cacheLocal === 'true' ? <Col span={24}>
|
<Form.Item label={
|
<Tooltip placement="topLeft" title="设置本地缓存时长后,在缓存期限内不向后台请求数据,时长最大为5天(即7200分钟)。注:时长为空时缓存数据只用于页面快速呈现,不影响接口请求。">
|
<QuestionCircleOutlined className="mk-form-tip" />
|
时长(分)
|
</Tooltip>
|
}>
|
{getFieldDecorator('localCacheTime', {
|
initialValue: config.localCacheTime
|
})(
|
<InputNumber min={1} max={7200} precision={0} onChange={(val) => {this.selectChange('localCacheTime', val)}}/>
|
)}
|
</Form.Item>
|
</Col> : null}
|
<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>
|
{/* <Col span={24}>
|
<Form.Item label={
|
<Tooltip placement="topLeft" title="跳过权限验证时,页面中组件及按钮不在进行权限控制。">
|
<QuestionCircleOutlined className="mk-form-tip" />
|
权限验证
|
</Tooltip>
|
}>
|
{getFieldDecorator('permission', {
|
initialValue: config.permission || 'false'
|
})(
|
<Radio.Group onChange={(e) => {this.selectChange('permission', 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('logincheck', {
|
initialValue: config.logincheck || 'false'
|
})(
|
<Radio.Group onChange={(e) => {this.selectChange('logincheck', 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 style={{whiteSpace: 'nowrap'}} onChange={(e) => {this.selectChange('timeUnit', e.target.value)}}>
|
<Radio value="day">天</Radio>
|
<Radio value="hour">小时</Radio>
|
<Radio value="minute">分钟</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 === 'day' ? 7 : (config.timeUnit === 'hour' ? 23 : 59)} precision={0} onChange={(val) => {this.selectChange('cacheTime', val)}}/>
|
)}
|
</Form.Item>
|
</Col> : null}
|
<Col span={24}>
|
<Form.Item label="下拉刷新">
|
{getFieldDecorator('pullRefresh', {
|
initialValue: config.pullRefresh || 'false'
|
})(
|
<Radio.Group onChange={(e) => {this.selectChange('pullRefresh', e.target.value)}}>
|
<Radio value="false">关闭</Radio>
|
<Radio value="true">开启</Radio>
|
</Radio.Group>
|
)}
|
</Form.Item>
|
</Col>
|
<Col span={24}>
|
<Form.Item label="屏幕方向">
|
{getFieldDecorator('direction', {
|
initialValue: config.direction || 'vertical'
|
})(
|
<Radio.Group onChange={(e) => {this.selectChange('direction', e.target.value)}}>
|
<Radio value="vertical">竖屏</Radio>
|
<Radio value="horizontal">横屏</Radio>
|
</Radio.Group>
|
)}
|
</Form.Item>
|
</Col>
|
{adapters.includes('app') || adapters.includes('wxmini') ? <Col span={24}>
|
<Form.Item className="status-bar" label={
|
<Tooltip placement="topLeft" title="在明科云APP或小程序中,状态栏的背景色。">
|
<QuestionCircleOutlined className="mk-form-tip" />
|
状态栏背景
|
</Tooltip>
|
}>
|
<ColorSketch value={config.statusBarbgColor || '#ffffff'} onChange={(val, hex) => {this.selectChange('statusBarbgColor', val, hex)}} />
|
</Form.Item>
|
</Col> : null}
|
{adapters.includes('wxmini') ? <Col span={24}>
|
<Form.Item className="status-bar-color" label={
|
<Tooltip placement="topLeft" title="在使用小程序时,状态栏的字体颜色。">
|
<QuestionCircleOutlined className="mk-form-tip" />
|
状态栏字体
|
</Tooltip>
|
}>
|
{getFieldDecorator('statusBarColor', {
|
initialValue: config.statusBarColor || 'black'
|
})(
|
<Radio.Group onChange={(e) => {this.selectChange('statusBarColor', e.target.value)}}>
|
<Radio value="black">黑色</Radio>
|
<Radio value="white">白色</Radio>
|
</Radio.Group>
|
)}
|
</Form.Item>
|
</Col> : null}
|
{adapters.includes('app') ? <Col span={24}>
|
<Form.Item label={
|
<Tooltip placement="topLeft" title="在明科云APP中有效。">
|
<QuestionCircleOutlined className="mk-form-tip" />
|
广告页
|
</Tooltip>
|
}>
|
{getFieldDecorator('advertUrl', {
|
initialValue: config.advertUrl || ''
|
})(
|
<SourceComponent type="picture" placement="right" onChange={(val) => {this.selectChange('advertUrl', val)}}/>
|
)}
|
</Form.Item>
|
</Col> : null}
|
{adapters.includes('app') && config.advertUrl ? <Col span={24}>
|
<Form.Item label={
|
<Tooltip placement="topLeft" title="广告页的停留时间。">
|
<QuestionCircleOutlined className="mk-form-tip" />
|
停留(s)
|
</Tooltip>
|
}>
|
{getFieldDecorator('advertTime', {
|
initialValue: config.advertTime || 3,
|
rules: [
|
{
|
required: true,
|
message: '请输入停留时间!'
|
}
|
]
|
})(
|
<InputNumber min={1} max={10} precision={0} onChange={(val) => {this.selectChange('advertTime', val)}}/>
|
)}
|
</Form.Item>
|
</Col> : null}
|
<Col span={24}>
|
<Form.Item label={
|
<Tooltip placement="topLeft" title="开启后数据源中将替换 @mk_longitude@、@mk_latitude@,在小程序中将获取用户所在经纬度。">
|
<QuestionCircleOutlined className="mk-form-tip" />
|
定位
|
</Tooltip>
|
}>
|
{getFieldDecorator('getLocation', {
|
initialValue: config.getLocation || 'false'
|
})(
|
<Radio.Group onChange={(e) => {this.selectChange('getLocation', e.target.value)}}>
|
<Radio value="true">开启</Radio>
|
<Radio value="false">不开启</Radio>
|
</Radio.Group>
|
)}
|
</Form.Item>
|
</Col>
|
{adapters.includes('weixin') || adapters.includes('wxmini') ? <Col span={24}>
|
<Form.Item label={
|
<Tooltip placement="topLeft" title="使用默认时请在子应用设置分享信息,使用url参数会使用上页参数替换相应字段(@field@)。注:使用自定义或url参数时会分享当前页面。">
|
<QuestionCircleOutlined className="mk-form-tip" />
|
分享
|
</Tooltip>
|
}>
|
{getFieldDecorator('share', {
|
initialValue: config.share || 'default'
|
})(
|
<Radio.Group className="mini-radio" onChange={(e) => {this.selectChange('share', e.target.value)}}>
|
<Radio value="default">默认</Radio>
|
<Radio value="custom">自定义</Radio>
|
<Radio value="url">url参数</Radio>
|
</Radio.Group>
|
)}
|
</Form.Item>
|
</Col> : null}
|
{['custom', 'url'].includes(config.share) && (adapters.includes('weixin') || adapters.includes('wxmini')) ? <Col span={24}>
|
<Form.Item label="分享标题">
|
{getFieldDecorator('share_title', {
|
initialValue: config.share_title || '',
|
rules: [
|
{
|
required: true,
|
message: '请输入分享标题!'
|
}
|
]
|
})(<Input placeholder="" autoComplete="off" onChange={(e) => {this.selectChange('share_title', e.target.value)}}/>)}
|
</Form.Item>
|
</Col> : null}
|
{['custom', 'url'].includes(config.share) && (adapters.includes('weixin') || adapters.includes('wxmini')) ? <Col span={24}>
|
<Form.Item label="分享描述">
|
{getFieldDecorator('share_des', {
|
initialValue: config.share_des || ''
|
})(<Input placeholder="" autoComplete="off" onChange={(e) => {this.selectChange('share_des', e.target.value)}}/>)}
|
</Form.Item>
|
</Col> : null}
|
{config.share === 'custom' && (adapters.includes('weixin') || adapters.includes('wxmini')) ? <Col span={24}>
|
<Form.Item label="分享图片">
|
{getFieldDecorator('share_url', {
|
initialValue: config.share_url || ''
|
})(
|
<SourceComponent type="picture" placement="right" onChange={(val) => {this.selectChange('share_url', val)}}/>
|
)}
|
</Form.Item>
|
</Col> : null}
|
{config.share === 'url' && (adapters.includes('weixin') || adapters.includes('wxmini')) ? <Col span={24}>
|
<Form.Item label="分享图片">
|
{getFieldDecorator('share_url', {
|
initialValue: config.share_url || ''
|
})(
|
<Input placeholder="" autoComplete="off" onChange={(e) => {this.selectChange('share_url', e.target.value)}}/>
|
)}
|
</Form.Item>
|
</Col> : null}
|
<Col span={24} className="red-font">
|
<Form.Item label="备注">
|
{getFieldDecorator('Remark', {
|
initialValue: config.Remark || '',
|
rules: [
|
{
|
max: 512,
|
message: '备注最多512个字符!'
|
}
|
]
|
})(<TextArea rows={2} placeholder={''} onChange={(e) => {this.selectChange('Remark', e.target.value)}}/>)}
|
</Form.Item>
|
</Col>
|
</Row>
|
</Form>
|
)
|
}
|
}
|
|
export default Form.create()(CustomMenuForm)
|