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, Spin } from 'antd'
|
import { DoubleLeftOutlined, DoubleRightOutlined, EyeOutlined, EyeInvisibleOutlined } from '@ant-design/icons'
|
import html2canvas from 'html2canvas'
|
import md5 from 'md5'
|
|
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 { getTables, getFuncsAndInters } from '@/utils/utils-custom.js'
|
import asyncComponent from '@/utils/asyncComponent'
|
|
import '@/assets/css/design.scss'
|
import './index.scss'
|
|
const { Panel } = Collapse
|
const { confirm } = Modal
|
const { Paragraph } = Typography
|
const _locale = antdZhCN
|
|
const MenuForm = asyncComponent(() => import('./menuform'))
|
const HomeForm = asyncComponent(() => import('./homeform'))
|
const PopView = asyncComponent(() => import('./popview'))
|
const Header = asyncComponent(() => import('@/menu/header'))
|
const MenuShell = asyncComponent(() => import('@/menu/menushell'))
|
const PrintMenuForm = asyncComponent(() => import('./printmenuform'))
|
const SourceWrap = asyncComponent(() => import('@/menu/modulesource'))
|
const Modulecell = asyncComponent(() => import('@/menu/modulecell'))
|
const BgController = asyncComponent(() => import('@/pc/bgcontroller'))
|
const PasteController = asyncComponent(() => import('@/menu/pastecontroller'))
|
const StyleController = asyncComponent(() => import('@/menu/stylecontroller'))
|
const ReplaceField = asyncComponent(() => import('@/menu/replaceField'))
|
const Debug = asyncComponent(() => import('@/menu/debug'))
|
const NormalCss = asyncComponent(() => import('@/menu/normalCss'))
|
const Versions = asyncComponent(() => import('@/menu/versions'))
|
const TableNodes = asyncComponent(() => import('@/menu/tablenodes'))
|
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 StyleCombController = asyncComponent(() => import('@/menu/stylecombcontroller'))
|
const StyleCombControlButton = asyncComponent(() => import('@/menu/stylecombcontrolbutton'))
|
const TableComponent = asyncComponent(() => import('@/templates/sharecomponent/tablecomponent'))
|
|
sessionStorage.setItem('appType', '') // 应用类型
|
document.body.className = ''
|
|
class MenuDesign extends Component {
|
state = {
|
MenuType: '',
|
MenuId: '',
|
ParentId: '',
|
MenuName: '',
|
MenuNo: '',
|
delButtons: [],
|
menuloading: false,
|
oriConfig: null,
|
config: null,
|
comloading: false,
|
settingshow: sessionStorage.getItem('settingshow') !== 'false',
|
eyeopen: false,
|
view: '',
|
popConfig: null,
|
needUpdate: false
|
}
|
|
UNSAFE_componentWillMount() {
|
if (sessionStorage.getItem('devError') === 'true') {
|
sessionStorage.clear()
|
window.history.replaceState(null, null, window.location.href.split('#')[0] + '#/login')
|
window.location.reload()
|
return
|
}
|
|
if (!sessionStorage.getItem('UserID')) {
|
sessionStorage.removeItem('appType')
|
this.props.history.replace('/login')
|
return
|
}
|
|
sessionStorage.setItem('editMenuType', 'menu') // 编辑菜单类型
|
|
window.GLOB.curDate = moment().format('YYYY-MM-DD')
|
window.GLOB.UserComponentMap = new Map() // 缓存用户自定义组件
|
window.GLOB.TabsMap = new Map() // 缓存用户操作的标签页
|
window.GLOB.urlFields = [] // url变量
|
window.GLOB.customMenu = null // 保存菜单信息
|
window.GLOB.developing = true
|
|
try {
|
let param = JSON.parse(window.decodeURIComponent(window.atob(this.props.match.params.param)))
|
|
sessionStorage.setItem('MenuType', param.MenuType || 'custom')
|
|
this.setState({
|
MenuType: param.MenuType,
|
MenuId: param.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 () {
|
if (!sessionStorage.getItem('UserID')) return
|
|
MKEmitter.addListener('changePopview', this.initPopview)
|
MKEmitter.addListener('triggerMenuSave', this.triggerMenuSave)
|
MKEmitter.addListener('changeEditMenu', this.changeEditMenu)
|
setTimeout(() => {
|
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') {
|
let modals = document.querySelectorAll('.mk-pop-modal')
|
let msg = null
|
for (let i = 0; i < modals.length; i++) {
|
if (msg) {
|
break
|
}
|
|
let node = modals[i].querySelector('.mk-com-name')
|
|
if (node) {
|
msg = node.innerText
|
}
|
}
|
if (msg) {
|
notification.warning({
|
top: 92,
|
message: '请保存' + msg,
|
duration: 5
|
})
|
return false
|
}
|
|
let node = document.getElementById('save-modal-config')
|
if (!node) {
|
node = document.getElementById('save-pop-config')
|
}
|
if (!node) {
|
node = document.getElementById('save-config')
|
}
|
|
if (node) {
|
node.click()
|
}
|
return false
|
}
|
}
|
}
|
|
/**
|
* @description 组件销毁,清除state更新
|
*/
|
componentWillUnmount () {
|
this.setState = () => {
|
return
|
}
|
MKEmitter.removeListener('changePopview', this.initPopview)
|
MKEmitter.removeListener('triggerMenuSave', this.triggerMenuSave)
|
MKEmitter.removeListener('changeEditMenu', this.changeEditMenu)
|
}
|
|
changeEditMenu = (menu) => {
|
if (menu.MenuID && menu.MenuID.length === 3 && menu.MenuNo && !this.menuLoading) {
|
this.menuLoading = true
|
let param = {
|
func: 'sPC_Get_LongParam',
|
MenuID: menu.MenuID[2]
|
}
|
|
Api.getCloudConfig(param).then(result => {
|
this.menuLoading = false
|
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) {
|
let _param = {
|
MenuId: menu.MenuID[2],
|
MenuID: menu.MenuID[2],
|
ParentId: menu.MenuID[1],
|
MenuName: menu.MenuName,
|
MenuNo: menu.MenuNo
|
}
|
if (config.Template === 'BaseTable') {
|
_param = window.btoa(window.encodeURIComponent(JSON.stringify(_param)))
|
window.open(`#/tabledesign/${_param}`)
|
} else if (config.Template === 'CustomPage') {
|
_param.MenuType = 'custom'
|
_param = window.btoa(window.encodeURIComponent(JSON.stringify(_param)))
|
window.open(`#/menudesign/${_param}`)
|
}
|
}
|
}
|
})
|
}
|
}
|
|
triggerMenuSave = () => {
|
if (this.state.view === 'popview') return
|
|
this.submitConfig()
|
}
|
|
submitPopConfig = (btnconfig) => {
|
let parents = {[btnconfig.ParentId]: true}
|
let popbtns = {[btnconfig.uuid]: fromJS(btnconfig).toJS()}
|
let config = fromJS(this.state.config).toJS()
|
|
config.components = this.setPopView(config.components, parents, popbtns)
|
|
this.setState({ config }, () => {
|
this.submitConfig()
|
})
|
}
|
|
closePop = () => {
|
const {config} = this.state
|
|
sessionStorage.setItem('editMenuType', 'menu')
|
|
window.GLOB.urlFields = config.urlFields || []
|
window.GLOB.customMenu = config
|
|
this.setState({view: '', popConfig: null})
|
}
|
|
initPopview = (card, btn) => {
|
const { config } = this.state
|
|
if (!this.checkBase()) {
|
notification.warning({
|
top: 92,
|
message: '请完善基本信息!',
|
duration: 5
|
})
|
return
|
}
|
|
let _btn = fromJS(btn).toJS()
|
|
if (_btn.config) {
|
_btn.config.uuid = _btn.uuid
|
_btn.config.MenuID = _btn.uuid
|
_btn.config.ParentId = card.uuid
|
_btn.config.MenuName = _btn.label
|
|
_btn.config.components = this.updateComponents(_btn.config.components || [])
|
} else {
|
_btn.config = {
|
uuid: _btn.uuid,
|
MenuID: _btn.uuid,
|
ParentId: card.uuid,
|
enabled: false,
|
MenuName: _btn.label,
|
tables: config.tables || [],
|
Template: 'CustomPage',
|
components: [],
|
viewType: 'popview',
|
style: { backgroundColor: '#ffffff', backgroundImage: '', paddingTop: '16px', paddingBottom: '40px', paddingLeft: '16px', paddingRight: '16px' }
|
}
|
}
|
|
this.setState({view: 'popview', popConfig: _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, MenuType } = this.state
|
|
let param = {
|
func: 'sPC_Get_LongParam',
|
MenuID: MenuId
|
}
|
|
Api.getCloudConfig(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: 2.0,
|
uuid: MenuId,
|
MenuID: MenuId,
|
parentId: ParentId,
|
Template: 'CustomPage',
|
easyCode: '',
|
enabled: false,
|
MenuName: MenuName,
|
MenuNo: MenuNo,
|
tables: [],
|
components: [],
|
viewType: 'menu',
|
style: {
|
backgroundColor: '#ffffff', backgroundImage: '',
|
paddingTop: '16px', paddingBottom: '80px', paddingLeft: '16px', paddingRight: '16px'
|
},
|
}
|
if (MenuType === 'billPrint') {
|
config.style.paddingTop = '50px'
|
config.style.paddingBottom = '50px'
|
config.style.paddingLeft = '30px'
|
config.style.paddingRight = '30px'
|
}
|
} else {
|
config.uuid = MenuId
|
config.MenuID = MenuId
|
config.Template = 'CustomPage'
|
}
|
|
if (MenuType === 'billPrint') {
|
config.fstMenuId = 'BillPrintTemp'
|
config.parentId = 'BillPrintTemp'
|
config.MenuName = MenuName
|
config.MenuNo = MenuNo
|
|
if (config.everyPCount && !config.printPage) {
|
config.printPage = 'page'
|
}
|
|
config.printPage = config.printPage || 'auto'
|
config.everyPCount = config.everyPCount || 15
|
}
|
|
config.open_edition = result.open_edition || ''
|
window.GLOB.urlFields = config.urlFields || []
|
|
if (config.version !== 2.0) {
|
this.setState({
|
oriConfig: fromJS(config).toJS(),
|
comloading: true,
|
needUpdate: true
|
})
|
this.updatePage(config)
|
} else {
|
config.components = this.updateComponents(config.components)
|
this.setState({
|
oriConfig: fromJS(config).toJS(),
|
config: config
|
})
|
window.GLOB.customMenu = config
|
}
|
} else {
|
notification.warning({
|
top: 92,
|
message: result.message,
|
duration: 5
|
})
|
}
|
})
|
}
|
|
updateComponents = (components) => { // 兼容性升级 table
|
return components.map(item => {
|
if (item.type === 'tabs') {
|
item.subtabs.forEach(tab => {
|
tab.components = this.updateComponents(tab.components)
|
})
|
} else if (item.type === 'group') {
|
item.components = this.updateComponents(item.components)
|
} else if (item.type === 'table') {
|
item.cols = item.cols.map(col => {
|
if (col.type === 'action') {
|
col.type = 'custom'
|
}
|
return col
|
})
|
}
|
|
return item
|
})
|
}
|
|
collectTB = (components, popBtns) => {
|
return components.map(item => {
|
if (item.type === 'tabs') {
|
item.subtabs.forEach(tab => {
|
delete tab.floor
|
delete tab.hasSearch
|
delete tab.parentId
|
|
tab.components = this.collectTB(tab.components, popBtns)
|
})
|
} else if (item.type === 'group') {
|
item.components = this.collectTB(item.components, popBtns)
|
} else {
|
item.$tables = getTables(item, popBtns)
|
}
|
|
if (item.subtype === 'tablecard') { // 兼容
|
item.type = 'card'
|
} else if (item.type === 'table') {
|
item.cols = item.cols.map(col => {
|
if (col.type === 'action') {
|
col.type = 'custom'
|
}
|
return col
|
})
|
}
|
|
delete item.tabId
|
delete item.parentId
|
delete item.btnlog
|
delete item.floor
|
delete item.dataName
|
|
return item
|
})
|
}
|
|
setPopView = (components, parents, popbtns) => {
|
return components.map(item => {
|
if (item.type === 'tabs') {
|
item.subtabs.forEach(tab => {
|
tab.components = this.setPopView(tab.components, parents, popbtns)
|
})
|
} else if (item.type === 'group') {
|
item.components = this.setPopView(item.components, parents, popbtns)
|
} else if (parents[item.uuid]) {
|
this.setpopConfig(item, popbtns)
|
}
|
return item
|
})
|
}
|
|
setpopConfig = (config, popbtns) => {
|
config.subcards && config.subcards.forEach(item => {
|
item.elements.forEach(cell => {
|
if (cell.eleType !== 'button') return
|
if (cell.OpenType === 'popview' && popbtns[cell.uuid]) {
|
cell.config = popbtns[cell.uuid]
|
}
|
})
|
})
|
|
if (config.cols) {
|
let loopCol = (cols) => {
|
cols.forEach(col => {
|
if (col.type === 'colspan') {
|
loopCol(col.subcols)
|
} else if (col.type === 'custom') {
|
col.elements.forEach(cell => {
|
if (cell.eleType !== 'button') return
|
if (cell.OpenType === 'popview' && popbtns[cell.uuid]) {
|
cell.config = popbtns[cell.uuid]
|
}
|
})
|
}
|
})
|
}
|
loopCol(config.cols)
|
}
|
|
config.elements && config.elements.forEach(cell => {
|
if (cell.eleType !== 'button') return
|
if (cell.OpenType === 'popview' && popbtns[cell.uuid]) {
|
cell.config = popbtns[cell.uuid]
|
}
|
})
|
|
config.action && config.action.forEach(cell => {
|
if (cell.OpenType === 'popview' && popbtns[cell.uuid]) {
|
cell.config = popbtns[cell.uuid]
|
}
|
})
|
|
config.$tables = getTables(config)
|
}
|
|
updatePage = (config) => {
|
let popBtns = []
|
|
config.components = this.collectTB(config.components, popBtns)
|
config.version = 2.0
|
|
if (popBtns.length === 0) {
|
this.setState({
|
config: config,
|
comloading: false,
|
needUpdate: true
|
})
|
|
window.GLOB.customMenu = config
|
return
|
}
|
|
Promise.all(popBtns.map((pop, i) => {
|
return new Promise(resolve => {
|
let param = {
|
func: 'sPC_Get_LongParam',
|
MenuID: pop.uuid
|
}
|
|
setTimeout(() => {
|
Api.getCloudConfig(param).then(res => {
|
let _config = null
|
try {
|
_config = res.LongParam ? JSON.parse(window.decodeURIComponent(window.atob(res.LongParam))) : null
|
} catch (e) {
|
console.warn('Parse Failure')
|
_config = null
|
}
|
|
if (_config && _config.Template !== 'CustomPage') {
|
_config = null
|
}
|
if (_config) {
|
_config.uuid = pop.uuid
|
_config.MenuID = pop.uuid
|
_config.ParentId = pop.parentId
|
_config.MenuName = pop.label
|
|
delete _config.MenuNo
|
delete _config.open_edition
|
delete _config.version
|
|
_config.components = this.collectTB(_config.components)
|
} else {
|
_config = {
|
uuid: pop.uuid,
|
MenuID: pop.uuid,
|
ParentId: pop.parentId,
|
enabled: false,
|
MenuName: pop.label,
|
tables: config.tables || [],
|
Template: 'CustomPage',
|
components: [],
|
viewType: 'popview',
|
style: { backgroundColor: '#ffffff', backgroundImage: '', paddingTop: '16px', paddingBottom: '40px', paddingLeft: '16px', paddingRight: '16px' }
|
}
|
}
|
|
resolve(_config)
|
})
|
}, i * 40)
|
})
|
})).then(results => {
|
let bts = []
|
results = results.map(res => {
|
let tbs = []
|
bts.push(...this.getMenuMessage(res, tbs))
|
|
res.$tables = Array.from(new Set(tbs))
|
|
return res
|
})
|
|
bts = bts.map(bt => bt.replace(/select\s'/, '').replace(/'\sas.*/, ''))
|
bts.push(...popBtns.map(pop => pop.uuid))
|
|
let parents = {}
|
let popbtns = {}
|
|
results.forEach(item => {
|
parents[item.ParentId] = true
|
popbtns[item.uuid] = item
|
})
|
|
config.components = this.setPopView(config.components, parents, popbtns)
|
|
this.setState({ delButtons: bts, config, comloading: false })
|
|
window.GLOB.customMenu = config
|
})
|
}
|
|
getMenuMessage = (config, tbs) => {
|
let buttons = []
|
let _sort = 1
|
|
let traversal = (components) => {
|
components.forEach(item => {
|
if (item.$tables) {
|
tbs.push(...item.$tables)
|
}
|
|
if (item.wrap && item.wrap.permission === 'false') {
|
return
|
}
|
|
if (item.action && item.action.length > 0) {
|
item.action.forEach(btn => {
|
if (btn.hidden === 'true' || btn.permission === 'false') return
|
buttons.push(`select '${btn.uuid}' as menuid, '${item.name + '-' + btn.label}' as menuname, '${_sort * 10}' as Sort, '${config.uuid}' as parentid, 40 as Type`)
|
_sort++
|
})
|
}
|
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 === 'carousel' || item.type === 'timeline') {
|
item.subcards.forEach(card => {
|
card.elements && card.elements.forEach(cell => {
|
if (cell.eleType !== 'button') return
|
if (cell.hidden === 'true' || cell.permission === 'false') return
|
buttons.push(`select '${cell.uuid}' as menuid, '${item.name + '-' + cell.label}' as menuname, '${_sort * 10}' as Sort, '${config.uuid}' as parentid, 40 as Type`)
|
_sort++
|
})
|
card.backElements && card.backElements.forEach(cell => {
|
if (cell.eleType !== 'button') return
|
if (cell.hidden === 'true' || cell.permission === 'false') return
|
buttons.push(`select '${cell.uuid}' as menuid, '${item.name + '-' + cell.label}' as menuname, '${_sort * 10}' as Sort, '${config.uuid}' as parentid, 40 as Type`)
|
_sort++
|
})
|
})
|
} else if (item.type === 'balcony') {
|
item.elements && item.elements.forEach(cell => {
|
if (cell.eleType !== 'button') return
|
if (cell.hidden === 'true' || cell.permission === 'false') return
|
buttons.push(`select '${cell.uuid}' as menuid, '${item.name + '-' + cell.label}' as menuname, '${_sort * 10}' as Sort, '${config.uuid}' as parentid, 40 as Type`)
|
_sort++
|
})
|
} else if (item.type === 'table') {
|
let loopCol = (cols) => {
|
cols.forEach(col => {
|
if (col.type === 'colspan') {
|
loopCol(col.subcols)
|
} else if (col.type === 'custom') {
|
col.elements.forEach(cell => {
|
if (cell.eleType !== 'button' || cell.hidden === 'true' || cell.permission === 'false') return
|
buttons.push(`select '${cell.uuid}' as menuid, '${item.name + '-' + cell.label}' as menuname, '${_sort * 10}' as Sort, '${config.uuid}' as parentid, 40 as Type`)
|
_sort++
|
})
|
}
|
})
|
}
|
loopCol(item.cols)
|
}
|
})
|
}
|
|
traversal(config.components)
|
|
if (config.interfaces) {
|
config.interfaces.forEach(item => {
|
if (item.$tables) {
|
tbs.push(...item.$tables)
|
}
|
})
|
}
|
|
return buttons
|
}
|
|
checkBase = () => {
|
const { MenuType, config } = this.state
|
|
if (MenuType === 'billPrint' && ((config.printPage === 'page' && !config.everyPCount) || (config.callback === 'true' && !config.callNo))) {
|
return false
|
} else if (MenuType === 'home' && (config.cacheUseful === 'true' && !config.cacheTime)) {
|
return false
|
} else if (MenuType === 'custom' && (!config.MenuName || !config.MenuNo || !config.fstMenuId || !config.parentId || (config.cacheUseful === 'true' && !config.cacheTime))) {
|
return false
|
}
|
return true
|
}
|
|
resetSyncQuery = (components) => {
|
return components.map(item => {
|
if (item.type === 'tabs') {
|
item.subtabs.forEach(tab => {
|
tab.components = this.resetSyncQuery(tab.components)
|
})
|
} else if (item.type === 'group') {
|
item.components = this.resetSyncQuery(item.components)
|
} else if (item.setting && item.setting.interType === 'system' && item.setting.sync === 'true') {
|
let sql = ''
|
if (item.setting.execute !== 'false' && item.setting.dataresource) {
|
sql = item.setting.dataresource
|
}
|
|
item.scripts && item.scripts.forEach(script => {
|
if (script.status === 'false') return
|
|
sql += script.sql
|
})
|
|
if (sql.length > 8000) {
|
item.setting.sync = 'false'
|
}
|
}
|
|
return item
|
})
|
}
|
|
submitConfig = () => {
|
const { MenuType } = this.state
|
let config = fromJS(this.state.config).toJS()
|
|
if (!this.checkBase()) {
|
notification.warning({
|
top: 92,
|
message: '请完善基本信息!',
|
duration: 5
|
})
|
return
|
}
|
|
this.setState({
|
menuloading: true
|
})
|
|
setTimeout(() => {
|
let _pass = this.verifyConfig(config)
|
|
if (config.enabled && !_pass) {
|
config.enabled = false
|
config.force = true
|
} else if (!config.enabled && config.force && _pass) {
|
config.enabled = true
|
delete config.force
|
}
|
|
if (config.cacheUseful !== 'true') {
|
config.components = this.resetSyncQuery(config.components)
|
}
|
|
if (config.MenuID === 'home_page_id') {
|
config.permission = 'false'
|
}
|
|
let tbs = []
|
let btns = this.getMenuMessage(config, tbs)
|
|
if (config.permission === 'false') {
|
btns = []
|
}
|
|
let arr = []
|
tbs = tbs.filter(tb => {
|
let _tb = tb.toLowerCase()
|
|
if (arr.includes(_tb)) return false
|
arr.push(_tb)
|
|
return true
|
})
|
tbs.sort()
|
if (tbs.length && sessionStorage.getItem('mk_tb_names')) {
|
let names = sessionStorage.getItem('mk_tb_names')
|
tbs = tbs.filter(tb => names.indexOf(',' + tb.toLowerCase() + ',') > -1)
|
}
|
tbs = tbs.map(tb => `'${tb}'`).join(';')
|
|
let key = md5(config.uuid + tbs.toLowerCase())
|
let url = ''
|
|
if (config.tbkey === key) {
|
key = ''
|
} else {
|
let urlparam = JSON.parse(window.decodeURIComponent(window.atob(this.props.match.params.param)))
|
urlparam.type = 'admin'
|
url = window.btoa(window.encodeURIComponent(JSON.stringify(urlparam)))
|
config.tbkey = key
|
}
|
|
let interfaces = getFuncsAndInters(config)
|
let urlFields = config.urlFields ? config.urlFields.join(',') : ''
|
|
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: 'CustomPage',
|
MenuName: config.MenuName || '',
|
PageParam: JSON.stringify({Template: 'CustomPage', OpenType: config.OpenType || 'newtab', hidden: config.hidden || 'false', menuColor: config.menuColor || '', interfaces, urlFields}),
|
open_edition: config.open_edition,
|
LText: '',
|
LTexttb: '',
|
debug_md5: key,
|
debug_url: url,
|
debug_list: window.btoa(tbs),
|
LongParam: window.btoa(window.encodeURIComponent(JSON.stringify(config)))
|
}
|
|
param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
|
param.secretkey = Utils.encrypt('', param.timestamp)
|
|
let btnParam = { // 添加菜单按钮
|
func: 'sPC_Button_AddUpt',
|
Type: 40, // 添加菜单下的按钮type为40,按钮下的按钮type为60
|
ParentID: config.uuid,
|
MenuNo: config.MenuNo,
|
Template: 'CustomPage',
|
button_proc_edition: 'Y',
|
exec_type: 'x'
|
}
|
|
btnParam.LText = btns.join(' union all ')
|
btnParam.LText = Utils.formatOptions(btnParam.LText, 'x')
|
btnParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
|
btnParam.secretkey = Utils.encrypt('', btnParam.timestamp)
|
|
new Promise(resolve => {
|
if (MenuType === 'billPrint') { // 打印生成页面效果图
|
html2canvas(document.getElementById('menu-shell-inner')).then(canvas => {
|
let param = {
|
Base64Img: canvas.toDataURL('image/png') // 获取生成的图片
|
}
|
|
if (window.GLOB.cloudServiceApi) {
|
param.rduri = window.GLOB.cloudServiceApi
|
param.userid = sessionStorage.getItem('CloudUserID') || ''
|
param.LoginUID = sessionStorage.getItem('CloudLoginUID') || ''
|
}
|
|
Api.fileuploadbase64(param).then(result => {
|
if (result.status) {
|
let url = result.Images
|
let baseurl = ''
|
|
if (window.GLOB.cloudServiceApi) {
|
baseurl = window.GLOB.cloudServiceApi.replace(/webapi(.*)$/, '')
|
} else {
|
baseurl = window.GLOB.baseurl
|
}
|
|
url = url.match(/^http/) || url.match(/^\/\//) ? url : baseurl + url
|
|
Api.getCloudConfig({
|
func: 's_PrintTemplateMSub',
|
ID: config.uuid,
|
Images: url,
|
Remark: '',
|
temp_type: 'billprint',
|
}).then(response => {
|
resolve(response)
|
})
|
} else {
|
resolve(result)
|
}
|
}, this.netError)
|
})
|
} else {
|
resolve({status: true})
|
}
|
}).then(res => { // 页面保存
|
if (!res || !res.status) return res
|
|
return Api.getCloudConfig(param)
|
}).then(res => { // 按钮删除
|
if (!res || !res.status) return res
|
|
if (MenuType !== 'billPrint') { // 基本信息改变时,通知菜单列表更新
|
localStorage.setItem('menuUpdate', new Date().getTime() + ',' + config.uuid)
|
}
|
config.open_edition = res.open_edition || ''
|
this.setState({
|
config,
|
oriConfig: fromJS(config).toJS(),
|
needUpdate: false
|
})
|
|
if (this.state.delButtons.length === 0) {
|
return {
|
status: true
|
}
|
} else {
|
let _param = {
|
func: 'sPC_MainMenu_Del',
|
MenuID: this.state.delButtons.join(',')
|
}
|
return Api.getCloudConfig(_param)
|
}
|
}, this.netError).then(res => { // 页面按钮关系保存
|
if (!res || !res.status) return res
|
|
this.setState({
|
delButtons: []
|
})
|
|
if (MenuType !== 'billPrint') {
|
return Api.getCloudConfig(btnParam)
|
} else {
|
return {
|
status: true
|
}
|
}
|
}, this.netError).then(res => {
|
this.setState({
|
menuloading: false
|
})
|
|
if (!res) return
|
|
if (res.status) {
|
notification.success({
|
top: 92,
|
message: '保存成功',
|
duration: 2
|
})
|
} else {
|
Modal.warning({
|
width: 400,
|
title: res.message,
|
okText: '知道了'
|
})
|
}
|
MKEmitter.emit('completeSave')
|
}, this.netError)
|
}, 300 + (+sessionStorage.getItem('mkDelay')))
|
}
|
|
netError = (error) => {
|
this.setState({
|
menuloading: false
|
})
|
|
if (!error) {
|
notification.warning({
|
top: 92,
|
message: '保存失败,请检查网络是否正常。',
|
duration: 5
|
})
|
}
|
MKEmitter.emit('completeSave')
|
}
|
|
getRoleFields = () => {
|
if (sessionStorage.getItem('sysRoles')) return
|
|
Api.getCloudConfig({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
|
|
let _config = {...config, enabled: !config.enabled}
|
|
delete _config.force
|
|
if (!_config.enabled) {
|
this.setState({
|
config: _config
|
})
|
} else if (this.verifyConfig(_config)) {
|
this.setState({
|
config: _config
|
})
|
}
|
}
|
|
verifyConfig = (config) => {
|
const { MenuType } = 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 (config.enabled && error) {
|
notification.warning({
|
top: 92,
|
message: error,
|
duration: 5
|
})
|
}
|
|
if (MenuType === 'billPrint' && !error) {
|
let forbid = {
|
tabs: '标签页',
|
search: '搜索条件',
|
form: '表单',
|
carousel: '轮播',
|
tree: '树形列表',
|
chart: '自定义图表',
|
// editor: '富文本',
|
group: '分组',
|
iframe: 'iframe'
|
}
|
let subforbid = {
|
editable: '可编辑表格',
|
voucher: '凭证',
|
account: '账套'
|
}
|
|
config.components.forEach(item => {
|
if (!error && forbid[item.type]) {
|
error = '打印模板中不可使用' + forbid[item.type]
|
} else if (!error && subforbid[item.type]) {
|
error = '打印模板中不可使用' + subforbid[item.type]
|
}
|
})
|
|
if (config.enabled && 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
|
}
|
|
changeSetting = () => {
|
this.setState({settingshow: !this.state.settingshow})
|
sessionStorage.setItem('settingshow', '' + !this.state.settingshow)
|
|
setTimeout(() => {
|
MKEmitter.emit('tabsChange', 'all')
|
}, 400)
|
}
|
|
checklog = () => {
|
const { oriConfig, config } = this.state
|
|
return is(fromJS(oriConfig), fromJS(config))
|
}
|
|
updateLogConfig = (config) => {
|
config.fstMenuId = this.state.config.fstMenuId || config.fstMenuId || ''
|
config.parentId = this.state.config.parentId || config.parentId || ''
|
config.open_edition = this.state.config.open_edition || ''
|
|
this.setState({
|
config: null
|
}, () => {
|
this.setState({
|
config: config
|
})
|
})
|
|
window.GLOB.customMenu = config
|
}
|
|
render () {
|
const { view, comloading, MenuType, MenuId, config, settingshow, ParentId, menuloading, eyeopen, needUpdate } = this.state
|
|
return (
|
<ConfigProvider locale={_locale}>
|
<Header menuName={config ? config.MenuName : ''}/>
|
<DndProvider backend={HTML5Backend}>
|
{view !== 'popview' ? <div className={'pc-menu-view ' + (MenuType || '')}>
|
<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 defaultActiveKey="basedata" bordered={false}>
|
{/* 基本信息 */}
|
<Panel header="基本信息" key="basedata">
|
{config ? <>
|
{MenuType === 'custom' ? <MenuForm
|
config={config}
|
MenuId={MenuId}
|
parentId={ParentId}
|
MenuName={config.MenuName}
|
MenuNo={config.MenuNo}
|
updateConfig={this.updateConfig}
|
/> : null}
|
{MenuType === 'home' ? <HomeForm
|
config={config}
|
updateConfig={this.updateConfig}
|
/> : null}
|
{MenuType === 'billPrint' ? <PrintMenuForm
|
config={config}
|
updateConfig={this.updateConfig}
|
/> : null}
|
<UrlFieldComponent
|
config={config}
|
updateConfig={this.updateConfig}
|
/>
|
{/* 表名添加 */}
|
<TableComponent config={config} updatetable={this.updateConfig}/>
|
<Paragraph style={{padding: '15px 0px 0px 18px'}} copyable={{ text: MenuId }}>菜单ID</Paragraph>
|
<NormalCss config={config} updateConfig={this.updateConfig}/>
|
</> : null}
|
</Panel>
|
{/* 组件添加 */}
|
<Panel header="组件" key="component">
|
<SourceWrap MenuType={MenuType} />
|
</Panel>
|
<Panel header="元素" key="element">
|
<Modulecell />
|
</Panel>
|
<Panel header="页面样式" key="background">
|
{config ? <BgController config={config} updateConfig={this.updateConfig} /> : null}
|
</Panel>
|
</Collapse>
|
</div>
|
<div className={'menu-view' + (menuloading ? ' saving' : '') + (eyeopen ? ' eye-open' : '')}>
|
<Card bordered={false} extra={
|
<div className="mk-opeartion-list">
|
{config ? <Debug config={config}/> : null}
|
<Button className="mk-border-purple" onClick={() => this.setState({eyeopen: !eyeopen})}>{!eyeopen ? <EyeOutlined /> : <EyeInvisibleOutlined />} 组件名</Button>
|
{config ? <Versions MenuId={MenuId} Template="CustomPage" checklog={this.checklog} updateConfig={this.updateLogConfig}/> : null}
|
<TableNodes config={config} />
|
<ReplaceField type="custom" config={config} updateConfig={this.resetConfig}/>
|
<SysInterface config={config} updateConfig={this.updateConfig}/>
|
<PictureController/>
|
<StyleCombControlButton menu={config} />
|
<PasteController insert={this.insert} />
|
{config ? <Switch className="big" checkedChildren="启" unCheckedChildren="停" checked={config.enabled} onChange={this.onEnabledChange} /> : null}
|
<Button type="primary" id="save-config" className={needUpdate ? 'update-tip' : ''} 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} /> : <Spin className="loading-config" size="large" />}
|
</Card>
|
</div>
|
</div>
|
</div> : <PopView btn={this.state.popConfig} save={this.submitPopConfig} cancel={this.closePop}/>}
|
</DndProvider>
|
<ModalController />
|
<StyleController />
|
<StyleCombController />
|
</ConfigProvider>
|
)
|
}
|
}
|
|
export default withRouter(MenuDesign)
|