import React, { Component } from 'react'
|
import { DndProvider } from 'react-dnd'
|
import { withRouter } from 'react-router'
|
import { is, fromJS } from 'immutable'
|
import moment from 'moment'
|
import HTML5Backend from 'react-dnd-html5-backend'
|
import { ConfigProvider, notification, Modal, Collapse, Card, Switch, Button, Typography } from 'antd'
|
import { DoubleLeftOutlined, DoubleRightOutlined } from '@ant-design/icons'
|
|
import Api from '@/api'
|
import Utils, { setGLOBFuncs } from '@/utils/utils.js'
|
import antdZhCN from 'antd/es/locale/zh_CN'
|
import MKEmitter from '@/utils/events.js'
|
import asyncComponent from '@/utils/asyncComponent'
|
|
import './index.scss'
|
|
const { Panel } = Collapse
|
const { confirm } = Modal
|
const { Paragraph } = Typography
|
const _locale = antdZhCN
|
|
const MenuForm = asyncComponent(() => import('./menuform'))
|
const Header = asyncComponent(() => import('@/menu/header'))
|
const MenuShell = asyncComponent(() => import('@/menu/tableshell'))
|
const BgController = asyncComponent(() => import('@/pc/bgcontroller'))
|
const StyleController = asyncComponent(() => import('@/menu/stylecontroller'))
|
const ReplaceField = asyncComponent(() => import('@/menu/replaceField'))
|
const Versions = asyncComponent(() => import('@/menu/versions'))
|
const SysInterface = asyncComponent(() => import('@/menu/sysinterface'))
|
const UrlFieldComponent = asyncComponent(() => import('@/menu/urlfieldcomponent'))
|
const PictureController = asyncComponent(() => import('@/menu/picturecontroller'))
|
const ModalController = asyncComponent(() => import('@/menu/modalconfig/controller'))
|
const TableComponent = asyncComponent(() => import('@/templates/sharecomponent/tablecomponent'))
|
|
sessionStorage.setItem('isEditState', 'true')
|
sessionStorage.setItem('appType', '') // 应用类型
|
document.body.className = ''
|
|
class TableDesign extends Component {
|
state = {
|
MenuId: '',
|
ParentId: '',
|
MenuName: '',
|
MenuNo: '',
|
activeKey: 'basedata',
|
menuloading: false,
|
oriConfig: null,
|
config: null,
|
customComponents: [],
|
comloading: false,
|
settingshow: true,
|
modalStatus: false // 弹窗是否开启,判断ctrl+s是否可用
|
}
|
|
UNSAFE_componentWillMount() {
|
sessionStorage.setItem('editMenuType', 'menu') // 编辑菜单类型
|
|
window.GLOB.UserComponentMap = new Map() // 缓存用户自定义组件
|
window.GLOB.TabsMap = new Map() // 缓存用户操作的标签页
|
window.GLOB.urlFields = [] // url变量
|
window.GLOB.customMenu = null // 保存菜单信息
|
|
try {
|
let param = JSON.parse(window.decodeURIComponent(window.atob(this.props.match.params.param)))
|
|
this.setState({
|
MenuId: param.MenuID,
|
ParentId: param.ParentId || '',
|
MenuName: param.MenuName || '',
|
MenuNo: param.MenuNo || '',
|
}, () => {
|
this.getMenuParam()
|
})
|
} catch (e) {
|
notification.warning({
|
top: 92,
|
message: '菜单信息解析错误!',
|
duration: 5
|
})
|
}
|
}
|
|
shouldComponentUpdate (nextProps, nextState) {
|
return !is(fromJS(this.state), fromJS(nextState))
|
}
|
|
componentDidMount () {
|
MKEmitter.addListener('modalStatus', this.modalStatus)
|
MKEmitter.addListener('changePopview', this.initPopview)
|
MKEmitter.addListener('triggerMenuSave', this.triggerMenuSave)
|
MKEmitter.addListener('submitComponentStyle', this.updateComponentStyle)
|
MKEmitter.addListener('updateCustomComponent', this.updateCustomComponent)
|
setTimeout(() => {
|
if (sessionStorage.getItem('app_custom_components')) {
|
let list = sessionStorage.getItem('app_custom_components')
|
list = JSON.parse(list)
|
|
this.setCustomComponent(list)
|
} else {
|
this.updateCustomComponent()
|
}
|
this.getAppPictures()
|
this.getPrintTemp()
|
this.getRoleFields()
|
setGLOBFuncs()
|
}, 1000)
|
|
document.onkeydown = (event) => {
|
let e = event || window.event
|
let keyCode = e.keyCode || e.which || e.charCode
|
let preKey = ''
|
|
if (e.ctrlKey) {
|
preKey = 'ctrl'
|
}
|
if (e.shiftKey) {
|
preKey = 'shift'
|
} else if (e.altKey) {
|
preKey = 'alt'
|
}
|
|
if (!preKey || !keyCode) return
|
|
let _shortcut = `${preKey}+${keyCode}`
|
|
if (_shortcut === 'ctrl+83') {
|
if (this.state.modalStatus) {
|
notification.warning({
|
top: 92,
|
message: '请保存' + this.state.modalStatus,
|
duration: 5
|
})
|
return false
|
}
|
|
let node = document.getElementById('save-modal-config')
|
if (!node) {
|
node = document.getElementById('save-config')
|
}
|
|
if (node) {
|
node.click()
|
}
|
return false
|
}
|
}
|
}
|
|
/**
|
* @description 组件销毁,清除state更新
|
*/
|
componentWillUnmount () {
|
this.setState = () => {
|
return
|
}
|
MKEmitter.removeListener('modalStatus', this.modalStatus)
|
MKEmitter.removeListener('changePopview', this.initPopview)
|
MKEmitter.removeListener('triggerMenuSave', this.triggerMenuSave)
|
MKEmitter.removeListener('submitComponentStyle', this.updateComponentStyle)
|
MKEmitter.removeListener('updateCustomComponent', this.updateCustomComponent)
|
}
|
|
modalStatus = (val) => {
|
this.setState({modalStatus: val})
|
}
|
|
triggerMenuSave = () => {
|
this.submitConfig()
|
}
|
|
getPrintTemp = () => {
|
if (!sessionStorage.getItem('printTemps')) {
|
let _sql = `select ID,Images,PrintTempNO+PrintTempName as PN from sPrintTemplate
|
where appkey= @appkey@ and Deleted=0 and typechartwo='web_print'
|
union select ID,Images,a.PrintTempNO+PrintTempName as PN
|
from (select * from sPrintTemplate where appkey= '' and Deleted=0 and typechartwo='web_print') a
|
left join (select PrintTempNO from sPrintTemplate where appkey= @appkey@ and Deleted=0 ) b
|
on a.PrintTempNO=b.PrintTempNO
|
left join (select Srcid from sPrintTemplate_Log where appkey='' and apicode= @appkey@ and Deleted=0 ) c
|
on a.ID=c.Srcid where b.PrintTempNO is null and c.Srcid is null`
|
|
let param = {
|
func: 'sPC_Get_SelectedList',
|
LText: Utils.formatOptions(_sql),
|
obj_name: 'data',
|
arr_field: 'PN,ID,Images'
|
}
|
|
param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
|
param.secretkey = Utils.encrypt(param.LText, param.timestamp)
|
|
param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp) // 云端数据验证
|
|
Api.getSystemConfig(param).then(res => {
|
if (res.status) {
|
let temps = res.data.map(temp => {
|
return {
|
value: temp.ID,
|
text: temp.PN
|
}
|
})
|
|
sessionStorage.setItem('printTemps', JSON.stringify(temps))
|
} else {
|
notification.warning({
|
top: 92,
|
message: res.message,
|
duration: 5
|
})
|
}
|
})
|
}
|
}
|
|
getAppPictures = () => {
|
if (sessionStorage.getItem('app_videos') || sessionStorage.getItem('app_pictures')) return
|
|
Api.getSystemConfig({
|
func: 's_url_db_adduptdel',
|
PageIndex: 0, // 0 代表全部
|
PageSize: 0, // 0 代表全部
|
typecharone: 'image',
|
type: 'search'
|
}).then(res => {
|
if (res.status) {
|
sessionStorage.setItem('app_pictures', JSON.stringify(res.data || []))
|
}
|
|
Api.getSystemConfig({
|
func: 's_url_db_adduptdel',
|
PageIndex: 0, // 0 代表全部
|
PageSize: 0, // 0 代表全部
|
typecharone: 'video',
|
type: 'search'
|
}).then(res => {
|
if (res.status) {
|
sessionStorage.setItem('app_videos', JSON.stringify(res.data || []))
|
}
|
})
|
Api.getSystemConfig({
|
func: 's_url_db_adduptdel',
|
PageIndex: 0, // 0 代表全部
|
PageSize: 0, // 0 代表全部
|
typecharone: 'color',
|
type: 'search'
|
}).then(res => {
|
if (res.status) {
|
sessionStorage.setItem('app_colors', JSON.stringify(res.data || []))
|
}
|
})
|
})
|
}
|
|
updateCustomComponent = () => {
|
Api.getSystemConfig({
|
func: 's_get_custom_components',
|
typename: '',
|
typecharone: ''
|
}).then(res => {
|
if (!res.status) {
|
notification.warning({
|
top: 92,
|
message: res.message,
|
duration: 5
|
})
|
} else if (res.cus_list) {
|
sessionStorage.setItem('app_custom_components', JSON.stringify(res.cus_list))
|
this.setCustomComponent(res.cus_list)
|
}
|
})
|
}
|
|
setCustomComponent = (cus_list) => {
|
let coms = []
|
|
cus_list.forEach(item => {
|
let config = ''
|
|
try {
|
config = JSON.parse(window.decodeURIComponent(window.atob(item.long_param)))
|
} catch (e) {
|
console.warn('Parse Failure')
|
config = ''
|
}
|
|
if (!config || !item.c_name) return
|
|
window.GLOB.UserComponentMap.set(item.c_id, item.c_name)
|
coms.push({
|
uuid: item.c_id,
|
type: 'menu',
|
title: item.c_name,
|
url: item.images,
|
component: config.type,
|
subtype: config.subtype,
|
config
|
})
|
})
|
this.setState({customComponents: coms})
|
}
|
|
updateComponentStyle = (parentId, keys, style) => {
|
const { config } = this.state
|
|
if (config.uuid !== parentId) return
|
|
let components = config.components.map(item => {
|
if (keys.includes(item.uuid)) {
|
item.style = {...item.style, ...style}
|
}
|
return item
|
})
|
|
this.setState({
|
config: {...config, components},
|
comloading: true
|
}, () => {
|
this.setState({
|
comloading: false
|
})
|
})
|
}
|
|
initPopview = (card, btn) => {
|
const { oriConfig, config } = this.state
|
|
if (!is(fromJS(oriConfig), fromJS(config))) {
|
notification.warning({
|
top: 92,
|
message: '配置已修改,请保存!',
|
duration: 5
|
})
|
return
|
}
|
|
let _btn = fromJS(btn).toJS()
|
_btn.MenuName = config.MenuName + '-' + card.name + '-' + btn.label
|
_btn.ParentMenuID = config.uuid
|
|
this.props.history.push('/popdesign/' + window.btoa(window.encodeURIComponent((JSON.stringify(_btn)))))
|
}
|
|
closeView = () => {
|
const { oriConfig, config } = this.state
|
|
if (!config) {
|
window.close()
|
return
|
}
|
|
if (!is(fromJS(oriConfig), fromJS(config))) {
|
confirm({
|
title: '配置已修改,放弃保存吗?',
|
content: '',
|
onOk() {
|
window.close()
|
},
|
onCancel() {}
|
})
|
} else {
|
window.close()
|
}
|
}
|
|
getMenuParam = () => {
|
const { MenuId, ParentId, MenuName, MenuNo } = this.state
|
|
let param = {
|
func: 'sPC_Get_LongParam',
|
MenuID: MenuId
|
}
|
|
Api.getSystemConfig(param).then(result => {
|
if (result.status) {
|
let config = null
|
|
try {
|
config = result.LongParam ? JSON.parse(window.decodeURIComponent(window.atob(result.LongParam))) : null
|
} catch (e) {
|
console.warn('Parse Failure')
|
config = null
|
}
|
|
if (!config) {
|
config = {
|
version: 1.0,
|
uuid: MenuId,
|
MenuID: MenuId,
|
parentId: ParentId,
|
Template: 'BaseTable',
|
easyCode: '',
|
enabled: false,
|
MenuName: MenuName,
|
MenuNo: MenuNo,
|
tables: [],
|
components: [
|
{
|
uuid: Utils.getuuid(),
|
type: 'table',
|
tabId: '',
|
parentId: '',
|
format: 'array', // 组件属性 - 数据格式
|
pageable: true, // 组件属性 - 是否可分页
|
switchable: true, // 组件属性 - 数据是否可切换
|
dataName: '',
|
width: 24,
|
search: [
|
{ origin: true, uuid: Utils.getuuid(), label: 'label', field: '', type: 'text', match: 'like' },
|
{ origin: true, uuid: Utils.getuuid(), label: 'label', field: '', type: 'select', match: 'equal' }
|
],
|
action: [
|
{ origin: true, uuid: Utils.getuuid(), label: '添加', intertype: 'system', OpenType: 'pop', execSuccess: 'grid', icon: 'plus', class: 'green', style: {color: 'rgb(255, 255, 255)', background: 'rgb(38, 194, 129)', marginRight: '15px'} },
|
{ origin: true, uuid: Utils.getuuid(), label: '修改', intertype: 'system', OpenType: 'pop', execSuccess: 'grid', icon: 'form', class: 'purple', style: {color: 'rgb(255, 255, 255)', background: 'rgb(142, 68, 173)', marginRight: '15px'} },
|
{ origin: true, uuid: Utils.getuuid(), label: '删除', intertype: 'system', OpenType: 'prompt', execSuccess: 'grid', Ot: 'required', icon: 'delete', class: 'danger', style: {color: 'rgb(255, 255, 255)', background: 'rgb(255, 77, 79)', marginRight: '15px'} }
|
],
|
name: '主表',
|
subtype: 'basetable',
|
setting: { interType: 'system' },
|
wrap: {},
|
style: {},
|
headerStyle: {},
|
columns: [],
|
cols: [
|
{ origin: true, uuid: Utils.getuuid(), Align: 'left', label: 'label1', field: '', Hide: 'false', type: 'text', Width: 120 },
|
{ origin: true, uuid: Utils.getuuid(), Align: 'left', label: 'label2', field: '', Hide: 'false', IsSort: 'true', type: 'text', Width: 120 },
|
{ origin: true, uuid: Utils.getuuid(), Align: 'left', label: 'label3', field: '', Hide: 'false', IsSort: 'true', type: 'text', Width: 120 },
|
],
|
scripts: [],
|
isNew: true
|
}
|
],
|
viewType: 'menu',
|
style: {
|
backgroundColor: '#ffffff', backgroundImage: '',
|
paddingTop: '16px', paddingBottom: '80px', paddingLeft: '16px', paddingRight: '16px'
|
},
|
}
|
} else {
|
config.uuid = MenuId
|
config.MenuID = MenuId
|
config.Template = 'BaseTable'
|
}
|
|
config.open_edition = result.open_edition || ''
|
window.GLOB.urlFields = config.urlFields || []
|
|
this.setState({
|
oriConfig: config,
|
config: fromJS(config).toJS()
|
})
|
window.GLOB.customMenu = config
|
} else {
|
notification.warning({
|
top: 92,
|
message: result.message,
|
duration: 5
|
})
|
}
|
})
|
}
|
|
getMenuMessage = (delButtons) => {
|
const { config } = this.state
|
let buttons = []
|
let _sort = 1
|
|
let traversal = (components) => {
|
components.forEach(item => {
|
if (item.type === 'tabs') {
|
item.subtabs.forEach(tab => {
|
traversal(tab.components)
|
})
|
} else if (item.type === 'group') {
|
traversal(item.components)
|
} else if (item.type === 'card' || (item.type === 'table' && item.subtype === 'tablecard')) {
|
item.action && item.action.forEach(btn => {
|
if (btn.hidden === 'true') {
|
delButtons.push(btn.uuid)
|
return
|
}
|
buttons.push(`select '${btn.uuid}' as menuid, '${item.name + '-' + btn.label}' as menuname, '${_sort * 10}' as Sort`)
|
_sort++
|
})
|
item.subcards.forEach(card => {
|
card.elements && card.elements.forEach(cell => {
|
if (cell.eleType !== 'button') return
|
if (cell.hidden === 'true') {
|
delButtons.push(cell.uuid)
|
return
|
}
|
buttons.push(`select '${cell.uuid}' as menuid, '${item.name + '-' + cell.label}' as menuname, '${_sort * 10}' as Sort`)
|
_sort++
|
})
|
card.backElements && card.backElements.forEach(cell => {
|
if (cell.eleType !== 'button') return
|
if (cell.hidden === 'true') {
|
delButtons.push(cell.uuid)
|
return
|
}
|
buttons.push(`select '${cell.uuid}' as menuid, '${item.name + '-' + cell.label}' as menuname, '${_sort * 10}' as Sort`)
|
_sort++
|
})
|
})
|
} else if (item.type === 'carousel' || item.type === 'timeline') {
|
item.subcards.forEach(card => {
|
card.elements && card.elements.forEach(cell => {
|
if (cell.eleType !== 'button') return
|
if (cell.hidden === 'true') {
|
delButtons.push(cell.uuid)
|
return
|
}
|
buttons.push(`select '${cell.uuid}' as menuid, '${item.name + '-' + cell.label}' as menuname, '${_sort * 10}' as Sort`)
|
_sort++
|
})
|
})
|
} else if (item.type === 'balcony') {
|
item.elements && item.elements.forEach(cell => {
|
if (cell.eleType !== 'button') return
|
if (cell.hidden === 'true') {
|
delButtons.push(cell.uuid)
|
return
|
}
|
buttons.push(`select '${cell.uuid}' as menuid, '${item.name + '-' + cell.label}' as menuname, '${_sort * 10}' as Sort`)
|
_sort++
|
})
|
} else if (item.type === 'line' || item.type === 'bar' || item.type === 'chart') {
|
item.action && item.action.forEach(btn => {
|
if (btn.hidden === 'true') {
|
delButtons.push(btn.uuid)
|
return
|
}
|
buttons.push(`select '${btn.uuid}' as menuid, '${item.name + '-' + btn.label}' as menuname, '${_sort * 10}' as Sort`)
|
_sort++
|
})
|
} else if (item.type === 'table' && (item.subtype === 'normaltable' || item.subtype === 'editable')) {
|
item.action && item.action.forEach(btn => {
|
if (btn.hidden === 'true') {
|
delButtons.push(btn.uuid)
|
return
|
}
|
buttons.push(`select '${btn.uuid}' as menuid, '${item.name + '-' + btn.label}' as menuname, '${_sort * 10}' as Sort`)
|
_sort++
|
})
|
item.cols && item.cols.forEach(col => {
|
if (col.type !== 'action') return
|
col.elements.forEach(btn => {
|
if (btn.hidden === 'true') {
|
delButtons.push(btn.uuid)
|
return
|
}
|
buttons.push(`select '${btn.uuid}' as menuid, '${item.name + '-' + btn.label}' as menuname, '${_sort * 10}' as Sort`)
|
_sort++
|
})
|
})
|
}
|
})
|
}
|
|
traversal(config.components)
|
|
return buttons
|
}
|
|
submitConfig = () => {
|
let config = fromJS(this.state.config).toJS()
|
|
if (!config.MenuName || !config.MenuNo || !config.fstMenuId || !config.parentId) {
|
notification.warning({
|
top: 92,
|
message: '请完善菜单基本信息!',
|
duration: 5
|
})
|
return
|
}
|
|
this.setState({
|
menuloading: true
|
})
|
|
setTimeout(() => {
|
if (config.enabled && this.verifyConfig()) {
|
config.enabled = false
|
}
|
|
let param = {
|
func: 'sPC_TrdMenu_AddUpt',
|
FstID: config.fstMenuId || '',
|
SndID: config.parentId,
|
ParentID: config.parentId,
|
MenuID: config.uuid,
|
MenuNo: config.MenuNo || '',
|
EasyCode: config.easyCode || '',
|
Template: 'BaseTable',
|
MenuName: config.MenuName || '',
|
PageParam: JSON.stringify({Template: 'BaseTable', OpenType: config.OpenType || 'newtab', hidden: config.hidden || 'false'}),
|
LongParam: window.btoa(window.encodeURIComponent(JSON.stringify(config))),
|
open_edition: config.open_edition,
|
LText: '',
|
LTexttb: ''
|
}
|
|
param.LText = Utils.formatOptions(param.LText)
|
param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
|
param.secretkey = Utils.encrypt(param.LText, param.timestamp)
|
|
let btnParam = { // 添加菜单按钮
|
func: 'sPC_Button_AddUpt',
|
Type: 40, // 添加菜单下的按钮type为40,按钮下的按钮type为60
|
ParentID: config.uuid,
|
MenuNo: config.MenuNo,
|
Template: 'BaseTable',
|
PageParam: '',
|
LongParam: '',
|
LText: []
|
}
|
|
let delButtons = []
|
|
btnParam.LText = this.getMenuMessage(delButtons)
|
btnParam.LText = btnParam.LText.join(' union all ')
|
|
btnParam.LText = Utils.formatOptions(btnParam.LText)
|
btnParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
|
btnParam.secretkey = Utils.encrypt(btnParam.LText, btnParam.timestamp)
|
|
new Promise(resolve => {
|
resolve(true)
|
}).then(res => { // 按钮删除
|
if (delButtons.length === 0) {
|
return {
|
status: true
|
}
|
} else {
|
let _param = {
|
func: 'sPC_MainMenu_Del',
|
MenuID: delButtons.join(',')
|
}
|
return Api.getSystemConfig(_param)
|
}
|
}).then(res => { // 页面保存
|
if (!res) return
|
|
if (res.status) {
|
return Api.getSystemConfig(param)
|
} else {
|
notification.warning({
|
top: 92,
|
message: res.message,
|
duration: 5
|
})
|
return false
|
}
|
}).then(res => { // 页面按钮关系保存
|
if (!res) return
|
|
if (res.status) {
|
let ori = this.state.oriConfig
|
if (config.MenuName !== ori.MenuName || config.MenuNo !== ori.MenuNo || config.parentId !== ori.parentId) {
|
localStorage.setItem('menuUpdate', new Date().getTime())
|
}
|
config.open_edition = res.open_edition || ''
|
this.setState({
|
config,
|
oriConfig: fromJS(config).toJS(),
|
})
|
|
if (btnParam.LText) {
|
return Api.getSystemConfig(btnParam)
|
} else {
|
return {
|
status: true
|
}
|
}
|
} else {
|
notification.warning({
|
top: 92,
|
message: res.message,
|
duration: 5
|
})
|
return false
|
}
|
}).then(res => { // 按钮复制
|
if (!res) return
|
if (!res.status) {
|
notification.warning({
|
top: 92,
|
message: res.message,
|
duration: 5
|
})
|
return false
|
}
|
}).then(res => {
|
if (res && res.status) {
|
this.setState({
|
menuloading: false
|
})
|
notification.success({
|
top: 92,
|
message: '保存成功',
|
duration: 2
|
})
|
} else {
|
this.setState({
|
menuloading: false
|
})
|
}
|
MKEmitter.emit('completeSave')
|
})
|
}, 300 + (+sessionStorage.getItem('mkDelay')))
|
}
|
|
getRoleFields = () => {
|
if (sessionStorage.getItem('sysRoles')) return
|
Api.getSystemConfig({func: 'sPC_Get_Roles_sModular'}).then(res => {
|
if (res.status) {
|
let _permFuncField = []
|
let _sysRoles = []
|
|
if (res.Roles && res.Roles.length > 0) {
|
_sysRoles = res.Roles.map(role => {
|
return {
|
uuid: Utils.getuuid(),
|
value: role.RoleID,
|
text: role.RoleName
|
}
|
})
|
}
|
|
if (res.sModular && res.sModular.length > 0) {
|
res.sModular.forEach(field => {
|
if (field.ModularNo) {
|
_permFuncField.push(field.ModularNo)
|
}
|
})
|
_permFuncField = _permFuncField.sort()
|
}
|
|
sessionStorage.setItem('sysRoles', JSON.stringify(_sysRoles))
|
sessionStorage.setItem('permFuncField', JSON.stringify(_permFuncField))
|
}
|
})
|
}
|
|
onEnabledChange = () => {
|
const { config } = this.state
|
|
if (!config || (!config.enabled && this.verifyConfig(true))) {
|
return
|
}
|
|
this.setState({
|
config: {...config, enabled: !config.enabled}
|
})
|
}
|
|
verifyConfig = (show) => {
|
const { config } = this.state
|
let error = ''
|
|
let check = (components) => {
|
components.forEach(item => {
|
if (error) return
|
|
if (item.type === 'tabs') {
|
item.subtabs.forEach(tab => {
|
check(tab.components)
|
})
|
return
|
} else if (item.type === 'group') {
|
check(item.components)
|
return
|
} else if (!item.errors || item.errors.length === 0) {
|
return
|
}
|
|
item.errors.forEach(err => {
|
if (err.level !== 0 || error) return
|
error = `组件《${item.name}》${err.detail}`
|
})
|
})
|
}
|
|
check(config.components)
|
|
if (show && error) {
|
notification.warning({
|
top: 92,
|
message: error,
|
duration: 5
|
})
|
}
|
|
return error
|
}
|
|
// 更新配置信息
|
updateConfig = (config) => {
|
this.setState({
|
config: config
|
})
|
window.GLOB.customMenu = config
|
}
|
|
resetConfig = (config) => {
|
this.setState({
|
config,
|
comloading: true
|
}, () => {
|
this.setState({
|
comloading: false
|
})
|
})
|
window.GLOB.customMenu = config
|
}
|
|
insert = (item) => {
|
let config = fromJS(this.state.config).toJS()
|
|
config.components.push(item)
|
|
this.setState({config})
|
window.GLOB.customMenu = config
|
|
notification.success({
|
top: 92,
|
message: '粘贴成功!',
|
duration: 2
|
})
|
}
|
|
changeSetting = () => {
|
this.setState({settingshow: !this.state.settingshow})
|
|
setTimeout(() => {
|
MKEmitter.emit('tabsChange', 'all')
|
}, 400)
|
}
|
|
render () {
|
const { activeKey, comloading, MenuId, config, settingshow, ParentId, menuloading } = this.state
|
|
return (
|
<ConfigProvider locale={_locale}>
|
<div className="pc-table-view">
|
<Header />
|
<DndProvider backend={HTML5Backend}>
|
<div className="menu-body">
|
<div className={'menu-setting ' + (!settingshow ? 'hidden' : '')}>
|
<div className="draw">
|
{settingshow ? <DoubleLeftOutlined onClick={this.changeSetting}/> : <DoubleRightOutlined onClick={this.changeSetting}/>}
|
</div>
|
<Collapse accordion activeKey={activeKey} bordered={false} onChange={(key) => this.setState({activeKey: key})}>
|
{/* 基本信息 */}
|
<Panel header="基本信息" key="basedata">
|
{/* 菜单信息 */}
|
{config ? <MenuForm
|
config={config}
|
MenuId={MenuId}
|
parentId={ParentId}
|
MenuName={config.MenuName}
|
MenuNo={config.MenuNo}
|
updateConfig={this.updateConfig}
|
/> : null}
|
{config ? <UrlFieldComponent
|
config={config}
|
updateConfig={this.updateConfig}
|
/> : null}
|
{/* 表名添加 */}
|
{config ? <TableComponent config={config} updatetable={this.updateConfig}/> : null}
|
{config ? <Paragraph style={{padding: '15px 0px 0px 18px'}} copyable={{ text: MenuId }}>菜单ID</Paragraph> : null}
|
</Panel>
|
<Panel header="页面样式" key="background">
|
{config ? <BgController config={config} updateConfig={this.updateConfig} /> : null}
|
</Panel>
|
</Collapse>
|
</div>
|
<div className={'menu-view' + (menuloading ? ' saving' : '')}>
|
<Card title={
|
<div style={{paddingLeft: '15px'}}> {config && config.MenuName} </div>
|
} bordered={false} extra={
|
<div>
|
<Versions MenuId={MenuId} open_edition={config ? config.open_edition : ''}/>
|
<ReplaceField type="custom" config={config} updateConfig={this.resetConfig}/>
|
<SysInterface config={config} updateConfig={this.updateConfig}/>
|
<PictureController/>
|
<Switch className="big" checkedChildren="启" unCheckedChildren="停" checked={config && config.enabled} onChange={this.onEnabledChange} />
|
<Button type="primary" id="save-config" onClick={this.submitConfig} loading={menuloading}>保存</Button>
|
<Button type="default" onClick={this.closeView}>关闭</Button>
|
</div>
|
} style={{ width: '100%' }}>
|
{config && !comloading ? <MenuShell menu={config} handleList={this.updateConfig} /> : null}
|
</Card>
|
</div>
|
</div>
|
</DndProvider>
|
<StyleController />
|
<ModalController />
|
</div>
|
</ConfigProvider>
|
)
|
}
|
}
|
|
export default withRouter(TableDesign)
|