From 5b75a82df7876f7c2c3e1f9da48752e2b2008ff8 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期一, 20 三月 2023 15:41:41 +0800 Subject: [PATCH] 2023-03-20 --- src/views/menudesign/index.jsx | 1155 ++++++++++++++++++++++++++++++++++----------------------- 1 files changed, 691 insertions(+), 464 deletions(-) diff --git a/src/views/menudesign/index.jsx b/src/views/menudesign/index.jsx index f5246d3..e816b50 100644 --- a/src/views/menudesign/index.jsx +++ b/src/views/menudesign/index.jsx @@ -1,43 +1,45 @@ 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 { 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 options from '@/store/options.js' import Utils, { setGLOBFuncs } from '@/utils/utils.js' -import zhCN from '@/locales/zh-CN/mob.js' -import enUS from '@/locales/en-US/mob.js' -import antdEnUS from 'antd/es/locale/en_US' import antdZhCN from 'antd/es/locale/zh_CN' import MKEmitter from '@/utils/events.js' -import MenuUtils from '@/utils/utils-custom.js' +import { getTables } 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 = sessionStorage.getItem('lang') !== 'en-US' ? antdZhCN : antdEnUS +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 PopviewController = asyncComponent(() => import('@/menu/popview')) -const BgController = asyncComponent(() => import('@/menu/bgcontroller')) +const Modulecell = asyncComponent(() => import('@/menu/modulecell')) +const BgController = asyncComponent(() => import('@/pc/bgcontroller')) const PasteController = asyncComponent(() => import('@/menu/pastecontroller')) -const PaddingController = asyncComponent(() => import('@/menu/padcontroller')) const StyleController = asyncComponent(() => import('@/menu/stylecontroller')) const ReplaceField = asyncComponent(() => import('@/menu/replaceField')) -// const BaseScript = asyncComponent(() => import('@/menu/baseScript')) +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')) @@ -47,42 +49,43 @@ const TableComponent = asyncComponent(() => import('@/templates/sharecomponent/tablecomponent')) sessionStorage.setItem('isEditState', 'true') -sessionStorage.setItem('editMenuType', 'menu') // 缂栬緫鑿滃崟绫诲瀷 sessionStorage.setItem('appType', '') // 搴旂敤绫诲瀷 document.body.className = '' -window.GLOB.UserComponentMap = new Map() // 缂撳瓨鐢ㄦ埛鑷畾涔夌粍浠� -window.GLOB.TabsMap = new Map() // 缂撳瓨鐢ㄦ埛鎿嶄綔鐨勬爣绛鹃〉 -window.GLOB.urlFields = [] // url鍙橀噺 -window.GLOB.customMenu = null // 淇濆瓨鑿滃崟淇℃伅 class MenuDesign extends Component { state = { - dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, MenuType: '', MenuId: '', ParentId: '', MenuName: '', MenuNo: '', delButtons: [], - copyButtons: [], - thawButtons: [], - activeKey: 'basedata', menuloading: false, oriConfig: null, config: null, - popBtn: null, // 寮圭獥鏍囩椤� - visible: false, customComponents: [], - comloading: false + comloading: false, + settingshow: sessionStorage.getItem('settingshow') !== 'false', + eyeopen: false, + view: '', + popConfig: null, + needUpdate: false } 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({ MenuType: param.MenuType, - MenuId: param.MenuId, + MenuId: param.MenuId || param.MenuID, ParentId: param.ParentId || '', MenuName: param.MenuName || '', MenuNo: param.MenuNo || '', @@ -103,18 +106,79 @@ } componentDidMount () { - MKEmitter.addListener('delButtons', this.delButtons) - MKEmitter.addListener('thawButtons', this.thawButtons) - MKEmitter.addListener('copyButtons', this.copyButtons) MKEmitter.addListener('changePopview', this.initPopview) MKEmitter.addListener('triggerMenuSave', this.triggerMenuSave) - MKEmitter.addListener('submitComponentStyle', this.updateComponentStyle) MKEmitter.addListener('updateCustomComponent', this.updateCustomComponent) setTimeout(() => { - this.updateCustomComponent() + 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') { + 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 + } + } } /** @@ -124,57 +188,118 @@ this.setState = () => { return } - MKEmitter.removeListener('delButtons', this.delButtons) - MKEmitter.removeListener('thawButtons', this.thawButtons) - MKEmitter.removeListener('copyButtons', this.copyButtons) MKEmitter.removeListener('changePopview', this.initPopview) MKEmitter.removeListener('triggerMenuSave', this.triggerMenuSave) - MKEmitter.removeListener('submitComponentStyle', this.updateComponentStyle) MKEmitter.removeListener('updateCustomComponent', this.updateCustomComponent) } triggerMenuSave = () => { - if (this.state.visible) return + 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}) + } + + 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 + if (sessionStorage.getItem('app_pictures')) return - Api.getSystemConfig({ + let deffers = [] + let param = { func: 's_url_db_adduptdel', PageIndex: 0, // 0 浠h〃鍏ㄩ儴 PageSize: 0, // 0 浠h〃鍏ㄩ儴 - typecharone: 'image', type: 'search' - }).then(res => { - if (res.status) { - sessionStorage.setItem('app_pictures', JSON.stringify(res.data || [])) - } + } + deffers = [new Promise(resolve => { + setTimeout(() => { + Api.getSystemConfig({...param, typecharone: 'image'}).then(res => { + resolve(res.data) + }) + }, 500) + }), new Promise(resolve => { + setTimeout(() => { + Api.getSystemConfig({...param, typecharone: 'video'}).then(res => { + resolve(res.data) + }) + }, 1000) + }), new Promise(resolve => { + setTimeout(() => { + Api.getSystemConfig({...param, typecharone: 'color'}).then(res => { + resolve(res.data) + }) + }, 1500) + })] - Api.getSystemConfig({ - func: 's_url_db_adduptdel', - PageIndex: 0, // 0 浠h〃鍏ㄩ儴 - PageSize: 0, // 0 浠h〃鍏ㄩ儴 - 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 浠h〃鍏ㄩ儴 - PageSize: 0, // 0 浠h〃鍏ㄩ儴 - typecharone: 'color', - type: 'search' - }).then(res => { - if (res.status) { - sessionStorage.setItem('app_colors', JSON.stringify(res.data || [])) - } - }) + Promise.all(deffers).then(response => { + sessionStorage.setItem('app_pictures', JSON.stringify(response[0] || [])) + sessionStorage.setItem('app_videos', JSON.stringify(response[1] || [])) + sessionStorage.setItem('app_colors', JSON.stringify(response[2] || [])) }) } @@ -184,98 +309,83 @@ typename: '', typecharone: '' }).then(res => { - let coms = [] - if (res.cus_list && res.cus_list.length > 0) { - res.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, - width: config.width || 24, - config - }) + 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) } - this.setState({customComponents: coms}) - this.getRoleFields() }) } - updateComponentStyle = (parentId, keys, style) => { - const { config } = this.state + setCustomComponent = (cus_list) => { + let coms = [] - if (config.uuid !== parentId) return + cus_list.forEach(item => { + let config = '' - let components = config.components.map(item => { - if (keys.includes(item.uuid)) { - item.style = {...item.style, ...style} + try { + config = JSON.parse(window.decodeURIComponent(window.atob(item.long_param))) + } catch (e) { + console.warn('Parse Failure') + config = '' } - return item - }) - this.setState({ - config: {...config, components}, - comloading: true - }, () => { - this.setState({ - comloading: false + 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 }) }) - } - - delButtons = (items) => { - this.setState({ delButtons: [...this.state.delButtons, ...items] }) - } - - copyButtons = (items) => { - this.setState({copyButtons: [...this.state.copyButtons, ...items]}) - } - - thawButtons = (item) => { - this.setState({thawButtons: [...this.state.thawButtons, item]}) + this.setState({customComponents: coms}) } initPopview = (card, btn) => { - const { oriConfig, config } = this.state + const { config } = this.state - if (!is(fromJS(oriConfig), fromJS(config))) { + if (!this.checkBase()) { notification.warning({ top: 92, - message: '閰嶇疆宸蹭慨鏀癸紝璇蜂繚瀛橈紒', + message: '璇峰畬鍠勫熀鏈俊鎭紒', duration: 5 }) return } - btn.config = fromJS(config).toJS() - btn.component = card + let _btn = fromJS(btn).toJS() - sessionStorage.setItem('editMenuType', 'popview') // 缂栬緫寮圭獥鏍囩 + if (_btn.config) { + _btn.config.uuid = _btn.uuid + _btn.config.MenuID = _btn.uuid + _btn.config.ParentId = card.uuid + _btn.config.MenuName = _btn.label + } 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({popBtn: btn, visible: true}) - } - - handleBack = () => { - this.setState({popBtn: null, delButtons: [], copyButtons: []}, () => { - sessionStorage.setItem('editMenuType', 'menu') - window.GLOB.customMenu = this.state.config - this.setState({visible: false}) - }) + this.setState({view: 'popview', popConfig: _btn}) } closeView = () => { @@ -321,7 +431,7 @@ if (!config) { config = { - version: 1.0, + version: 2.0, uuid: MenuId, MenuID: MenuId, parentId: ParentId, @@ -355,19 +465,32 @@ config.parentId = 'BillPrintTemp' config.MenuName = MenuName config.MenuNo = MenuNo - config.firstCount = config.firstCount || 15 + + if (config.everyPCount && !config.printPage) { + config.printPage = 'page' + } + + config.printPage = config.printPage || 'auto' config.everyPCount = config.everyPCount || 15 - config.lastCount = config.lastCount || '' } config.open_edition = result.open_edition || '' window.GLOB.urlFields = config.urlFields || [] - this.setState({ - oriConfig: config, - config: fromJS(config).toJS() - }) - window.GLOB.customMenu = config + if (config.version !== 2.0) { + this.setState({ + oriConfig: fromJS(config).toJS(), + comloading: true, + needUpdate: true + }) + this.updatePage(config) + } else { + this.setState({ + oriConfig: fromJS(config).toJS(), + config: config + }) + window.GLOB.customMenu = config + } } else { notification.warning({ top: 92, @@ -378,72 +501,230 @@ }) } - getMenuMessage = () => { - const { config } = this.state + 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' + } + + 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] + } + }) + }) + + config.cols && config.cols.forEach(col => { + if (col.type === 'action') { + col.elements.forEach(cell => { + if (cell.OpenType === 'popview' && popbtns[cell.uuid]) { + cell.config = popbtns[cell.uuid] + } + }) + } + }) + + 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 + }) + return + } + + Promise.all(popBtns.map((pop, i) => { + return new Promise(resolve => { + let param = { + func: 'sPC_Get_LongParam', + MenuID: pop.uuid + } + + setTimeout(() => { + Api.getSystemConfig(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 }) + }) + } + + getMenuMessage = (config, tbs) => { let buttons = [] let _sort = 1 let traversal = (components) => { components.forEach(item => { + if (item.$tables) { + tbs.push(...item.$tables) + } + if (item.action && item.action.length > 0) { + item.action.forEach(btn => { + if (btn.hidden === 'true') 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 === 'table' && item.subtype === 'tablecard')) { - item.action && item.action.forEach(btn => { - this.checkBtn(btn) - buttons.push(`select '${btn.uuid}' as menuid, '${item.name + '-' + btn.label}' as menuname, '${_sort * 10}' as Sort`) - _sort++ - }) + } 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 - this.checkBtn(cell) - buttons.push(`select '${cell.uuid}' as menuid, '${item.name + '-' + cell.label}' as menuname, '${_sort * 10}' as Sort`) + if (cell.hidden === 'true') 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 - this.checkBtn(cell) - 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 - this.checkBtn(cell) - buttons.push(`select '${cell.uuid}' as menuid, '${item.name + '-' + cell.label}' as menuname, '${_sort * 10}' as Sort`) + if (cell.hidden === 'true') 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 - this.checkBtn(cell) - buttons.push(`select '${cell.uuid}' as menuid, '${item.name + '-' + cell.label}' as menuname, '${_sort * 10}' as Sort`) + if (cell.hidden === 'true') 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 === 'line' || item.type === 'bar' || item.type === 'chart') { - item.action && item.action.forEach(btn => { - this.checkBtn(btn) - 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 => { - this.checkBtn(btn) - buttons.push(`select '${btn.uuid}' as menuid, '${item.name + '-' + btn.label}' as menuname, '${_sort * 10}' as Sort`) - _sort++ - }) + } else if (item.type === 'table') { item.cols && item.cols.forEach(col => { if (col.type !== 'action') return col.elements.forEach(btn => { - this.checkBtn(btn) - buttons.push(`select '${btn.uuid}' as menuid, '${item.name + '-' + btn.label}' as menuname, '${_sort * 10}' as Sort`) + if (btn.hidden === 'true') 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++ }) }) @@ -453,51 +734,67 @@ traversal(config.components) + if (config.interfaces) { + config.interfaces.forEach(item => { + if (item.$tables) { + tbs.push(...item.$tables) + } + }) + } + return buttons } - checkBtn = (btn) => { - if (['prompt', 'exec', 'pop'].includes(btn.OpenType) && btn.Ot === 'required' && btn.verify && btn.verify.scripts && btn.verify.scripts.length > 0) { - let hascheck = false - btn.verify.scripts.forEach(item => { - if (item.status === 'false') return - - if (/\$check@|@check\$/ig.test(item.sql)) { - hascheck = true - } - }) - if (hascheck) { - notification.warning({ - top: 92, - message: `鍙�夋嫨澶氳鐨勬寜閽��${btn.label}銆嬩腑 $check@ 鎴� @check$ 灏嗕笉浼氱敓鏁堬紒`, - duration: 5 - }) - } + checkBase = () => { + const { MenuType, config } = this.state + + if (MenuType === 'billPrint' && config.printPage === 'page' && !config.everyPCount) { + 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, delButtons, copyButtons, thawButtons } = this.state + const { MenuType } = this.state let config = fromJS(this.state.config).toJS() - if (MenuType === 'billPrint' && (!config.firstCount || !config.everyPCount)) { + if (!this.checkBase()) { notification.warning({ top: 92, message: '璇峰畬鍠勫熀鏈俊鎭紒', - duration: 5 - }) - return - } else if (MenuType === 'home' && (config.cacheUseful === 'true' && !config.cacheTime)) { - notification.warning({ - top: 92, - message: '璇峰畬鍠勮彍鍗曞熀鏈俊鎭紒', - duration: 5 - }) - return - } else if (MenuType === 'custom' && (!config.MenuName || !config.MenuNo || !config.fstMenuId || !config.parentId || (config.cacheUseful === 'true' && !config.cacheTime))) { - notification.warning({ - top: 92, - message: '璇峰畬鍠勮彍鍗曞熀鏈俊鎭紒', duration: 5 }) return @@ -512,6 +809,40 @@ config.enabled = false } + if (config.cacheUseful !== 'true') { + config.components = this.resetSyncQuery(config.components) + } + + let tbs = [] + let btns = this.getMenuMessage(config, tbs) + 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 param = { func: 'sPC_TrdMenu_AddUpt', FstID: config.fstMenuId || '', @@ -523,10 +854,13 @@ Template: 'CustomPage', MenuName: config.MenuName || '', PageParam: JSON.stringify({Template: 'CustomPage', OpenType: config.OpenType || 'newtab', hidden: config.hidden || 'false'}), - LongParam: window.btoa(window.encodeURIComponent(JSON.stringify(config))), open_edition: config.open_edition, LText: '', - LTexttb: '' + LTexttb: '', + debug_md5: key, + debug_url: url, + debug_list: window.btoa(tbs), + LongParam: window.btoa(window.encodeURIComponent(JSON.stringify(config))) } param.LText = Utils.formatOptions(param.LText) @@ -539,24 +873,14 @@ ParentID: config.uuid, MenuNo: config.MenuNo, Template: 'CustomPage', - PageParam: '', - LongParam: '', - LText: [] + button_proc_edition: 'Y' } - let btnIds = '' // 鐢ㄤ簬澶嶅埗鎸夐挳鐨勮繃婊� - if (MenuType !== 'billPrint') { - btnParam.LText = this.getMenuMessage() - btnParam.LText = btnParam.LText.join(' union all ') + btnParam.LText = btns.join(' union all ') - btnIds = btnParam.LText - - btnParam.LText = Utils.formatOptions(btnParam.LText) - btnParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') - btnParam.secretkey = Utils.encrypt(btnParam.LText, btnParam.timestamp) - } else { - btnParam.LText = '' - } + 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 => { if (MenuType === 'billPrint') { // 鎵撳嵃鐢熸垚椤甸潰鏁堟灉鍥� @@ -580,222 +904,99 @@ Remark: '', temp_type: 'billprint', }).then(response => { - if (response.status) { - resolve(true) - } else { - notification.warning({ - top: 92, - message: response.message, - duration: 5 - }) - resolve(false) - } + resolve(response) }) } else { - notification.warning({ - top: 92, - message: result.ErrMesg, - duration: 5 - }) - resolve(false) + resolve(result) } - }) + }, this.netError) }) } else { - resolve(true) + resolve({status: true}) } - }).then(res => { // 鎸夐挳鍒犻櫎 - if (!res) return + }).then(res => { // 椤甸潰淇濆瓨 + if (!res || !res.status) return res - if (delButtons.length === 0) { + return Api.getSystemConfig(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: delButtons.join(',') + MenuID: this.state.delButtons.join(',') } return Api.getSystemConfig(_param) } - }).then(res => { // 鎸夐挳瑙i櫎鍐荤粨 - if (!res) return - if (!res.status) { - notification.warning({ - top: 92, - message: res.message, - duration: 5 - }) - return false - } + }, this.netError).then(res => { // 椤甸潰鎸夐挳鍏崇郴淇濆瓨 + if (!res || !res.status) return res - let ids = thawButtons.filter(item => btnIds.indexOf(item) !== -1) - if (ids.length === 0) { + this.setState({ + delButtons: [] + }) + + if (MenuType !== 'billPrint') { + return Api.getSystemConfig(btnParam) + } else { return { status: true } - } else { - return Api.getSystemConfig({ - func: 'sPC_MainMenu_ReDel', - MenuID: ids.join(',') - }) } - }).then(res => { // 椤甸潰淇濆瓨 + }, this.netError).then(res => { + this.setState({ + menuloading: false + }) + 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) { - 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 - } - - if (copyButtons.length === 0) { - return { - status: true - } - } else { - return new Promise(resolve => { - let deffers = copyButtons.map(item => { - return new Promise(resolve => { - if (btnIds.indexOf(item.uuid) === -1) { // 澶嶅埗鐨勬寜閽凡鍒犻櫎 - resolve({ - status: true - }) - return - } - - Api.getSystemConfig({ - func: 'sPC_Get_LongParam', - MenuID: item.$originUuid - }).then(result => { - if (result.status) { - let _conf = '' - - try { - _conf = result.LongParam ? JSON.parse(window.decodeURIComponent(window.atob(result.LongParam))) : '' - } catch (e) { - console.warn('Parse Failure') - _conf = '' - } - - if (_conf) { - _conf.components = MenuUtils.resetConfig(_conf.components) - _conf.uuid = item.uuid - _conf.MenuID = item.uuid - _conf.Template = 'CustomPage' - _conf.enabled = false - } else { - resolve({ - status: true - }) - return - } - - let _param = { - func: 'sPC_ButtonParam_AddUpt', - ParentID: config.uuid, - MenuID: item.uuid, - MenuNo: '', - Template: 'CustomPage', - MenuName: item.label, - PageParam: JSON.stringify({Template: 'CustomPage'}), - LongParam: window.btoa(window.encodeURIComponent(JSON.stringify(_conf))) - } - - Api.getSystemConfig(_param).then(response => { - resolve(response) - }) - } - }) - }) - }) - Promise.all(deffers).then(result => { - let error = null - result.forEach(response => { - if (!response.status) { - error = response - } - }) - - if (error) { - notification.warning({ - top: 92, - message: error.message, - duration: 5 - }) - resolve(false) - } else { - resolve({ - status: true - }) - } - }) - }) - } - }).then(res => { - if (res && res.status) { - this.setState({ - delButtons: [], - copyButtons: [], - thawButtons: [], - menuloading: false - }) notification.success({ top: 92, message: '淇濆瓨鎴愬姛', duration: 2 }) + MKEmitter.emit('completeSave') } else { - this.setState({ - menuloading: false + notification.warning({ + top: 92, + message: res.message, + duration: 5 }) } - MKEmitter.emit('completeSave') + }, this.netError) + }, 300 + (+sessionStorage.getItem('mkDelay'))) + } + + netError = (error) => { + this.setState({ + menuloading: false + }) + if (!error) { + notification.warning({ + top: 92, + message: '淇濆瓨澶辫触锛岃妫�鏌ョ綉缁滄槸鍚︽甯搞��', + duration: 5 }) - }, 300) + } } getRoleFields = () => { + if (sessionStorage.getItem('sysRoles')) return + Api.getSystemConfig({func: 'sPC_Get_Roles_sModular'}).then(res => { if (res.status) { let _permFuncField = [] @@ -839,12 +1040,13 @@ } verifyConfig = (show) => { - const { config } = this.state + const { config, 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) @@ -853,32 +1055,14 @@ } else if (item.type === 'group') { check(item.components) return + } else if (!item.errors || item.errors.length === 0) { + return } - if (['propcard', 'brafteditor', 'sandbox', 'stepform', 'tabform'].includes(item.subtype) && item.wrap.datatype === 'static') return - if (['balcony'].includes(item.type) && item.wrap.datatype === 'static') return - - if (item.setting) { - if (item.setting.interType === 'system' && item.setting.execute !== 'false' && !item.setting.dataresource) { - error = `缁勪欢銆�${item.name}銆嬫湭璁剧疆鏁版嵁婧愶紒` - } else if (item.setting.interType === 'system' && item.setting.execute === 'false' && item.scripts.length === 0) { - error = `缁勪欢銆�${item.name}銆嬫湭璁剧疆鏁版嵁婧愶紒` - } else if (!item.setting.primaryKey) { - error = `缁勪欢銆�${item.name}銆嬫湭璁剧疆涓婚敭锛乣 - } else if (!item.setting.supModule && item.type !== 'balcony' && (!item.wrap || item.wrap.supType !== 'multi')) { - error = `缁勪欢銆�${item.name}銆嬫湭璁剧疆涓婄骇缁勪欢锛乣 - } - } - if (item.type === 'bar' || item.type === 'line' || item.type === 'pie') { - if (!item.plot.Xaxis) { - error = `缁勪欢銆�${item.name}銆嬪浘琛ㄥ瓧娈靛皻鏈缃紒` - } - } else if (item.type === 'dashboard' && !item.plot.valueField) { - error = `缁勪欢銆�${item.name}銆嬫樉绀哄�煎皻鏈缃紒` - } else if (item.type === 'scatter' && (!item.plot.Xaxis || !item.plot.Yaxis || !item.plot.gender)) { - error = `缁勪欢銆�${item.name}銆嬪潗鏍囪酱灏氭湭璁剧疆锛乣 - } else if (item.type === 'tree' && (!item.wrap.valueField || !item.wrap.labelField || !item.wrap.parentField)) { - error = `缁勪欢銆�${item.name}銆嬪熀鏈俊鎭皻鏈缃紒` - } + + item.errors.forEach(err => { + if (err.level !== 0 || error) return + error = `缁勪欢銆�${item.name}銆�${err.detail}` + }) }) } @@ -890,6 +1074,41 @@ 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 (show && error) { + notification.warning({ + top: 92, + message: error, + duration: 5 + }) + } } return error @@ -930,36 +1149,45 @@ }) } + changeSetting = () => { + this.setState({settingshow: !this.state.settingshow}) + sessionStorage.setItem('settingshow', '' + !this.state.settingshow) + + setTimeout(() => { + MKEmitter.emit('tabsChange', 'all') + }, 400) + } + render () { - const { activeKey, comloading, MenuType, popBtn, visible, dict, MenuId, config, ParentId, MenuName, MenuNo, menuloading, customComponents } = this.state + const { view, comloading, MenuType, MenuId, config, settingshow, ParentId, menuloading, customComponents, eyeopen, needUpdate } = this.state return ( <ConfigProvider locale={_locale}> - <div className={'pc-menu-view ' + (MenuType || '')} id="mk-menu-design-view"> - <Header /> - {!popBtn && !visible ? <DndProvider backend={HTML5Backend}> + <Header /> + <DndProvider backend={HTML5Backend}> + {view !== 'popview' ? <div className={'pc-menu-view ' + (MenuType || '')}> <div className="menu-body"> - <div className="menu-setting"> - <Collapse accordion activeKey={activeKey} bordered={false} onChange={(key) => this.setState({activeKey: key})}> + <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={dict['mob.basemsg']} key="basedata"> + <Panel header="鍩烘湰淇℃伅" key="basedata"> {/* 鑿滃崟淇℃伅 */} {config && MenuType === 'custom' ? <MenuForm - dict={dict} config={config} MenuId={MenuId} parentId={ParentId} - MenuName={MenuName} - MenuNo={MenuNo} + MenuName={config.MenuName} + MenuNo={config.MenuNo} updateConfig={this.updateConfig} /> : null} {config && MenuType === 'home' ? <HomeForm - dict={dict} config={config} updateConfig={this.updateConfig} /> : null} {config && MenuType === 'billPrint' ? <PrintMenuForm - dict={dict} config={config} updateConfig={this.updateConfig} /> : null} @@ -970,52 +1198,51 @@ {/* 琛ㄥ悕娣诲姞 */} {config ? <TableComponent config={config} updatetable={this.updateConfig}/> : null} {config ? <Paragraph style={{padding: '15px 0px 0px 18px'}} copyable={{ text: MenuId }}>鑿滃崟ID</Paragraph> : null} + {config ? <NormalCss config={config} updateConfig={this.updateConfig}/> : null} </Panel> {/* 缁勪欢娣诲姞 */} - <Panel header={dict['mob.component']} key="component"> + <Panel header="缁勪欢" key="component"> <SourceWrap MenuType={MenuType} /> + </Panel> + <Panel header="鍏冪礌" key="element"> + <Modulecell /> </Panel> {customComponents && customComponents.length ? <Panel header="鑷畾涔夌粍浠�" key="cuscomponent"> <SourceWrap components={customComponents} MenuType={MenuType} /> </Panel> : null} - <Panel header={'椤甸潰鑳屾櫙'} key="background"> + <Panel header="椤甸潰鏍峰紡" key="background"> {config ? <BgController config={config} updateConfig={this.updateConfig} /> : null} - </Panel> - <Panel header={'椤甸潰鍐呰竟璺�'} key="padding"> - {config ? <PaddingController config={config} updateConfig={this.updateConfig} /> : null} </Panel> </Collapse> </div> - <div className={'menu-view ' + (menuloading ? 'saving' : '')}> - <Card title={ - <div> {config && config.MenuName} </div> - } bordered={false} extra={ - <div> - {/* <BaseScript config={config} updateConfig={this.updateConfig}/> */} + <div className={'menu-view' + (menuloading ? ' saving' : '') + (eyeopen ? ' eye-open' : '')}> + <Card title={config ? config.MenuName : ''} bordered={false} extra={ + <div className="mk-opeartion-list"> + <Button className="mk-border-purple" onClick={() => this.setState({eyeopen: !eyeopen})}>{!eyeopen ? <EyeOutlined /> : <EyeInvisibleOutlined />} 缁勪欢鍚�</Button> <Versions MenuId={MenuId} open_edition={config ? config.open_edition : ''}/> + <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} /> - <Switch className="big" checkedChildren={dict['mob.enable']} unCheckedChildren={dict['mob.disable']} checked={config && config.enabled} onChange={this.onEnabledChange} /> - <Button type="primary" onClick={this.submitConfig} loading={menuloading}>{dict['mob.save']}</Button> + <Switch className="big" checkedChildren="鍚�" unCheckedChildren="鍋�" checked={config && config.enabled} onChange={this.onEnabledChange} /> + <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} /> : null} + {config && !comloading ? <MenuShell menu={config} handleList={this.updateConfig} /> : <Spin className="loading-config" size="large" />} </Card> </div> </div> - </DndProvider> : null} - {popBtn && visible ? <PopviewController btn={popBtn} handleBack={this.handleBack}/> : null} - <StyleController /> - <StyleCombController /> - <ModalController /> - </div> + </div> : <PopView btn={this.state.popConfig} save={this.submitPopConfig} cancel={this.closePop}/>} + </DndProvider> + <ModalController /> + <StyleController /> + <StyleCombController /> </ConfigProvider> ) } } -export default MenuDesign \ No newline at end of file +export default withRouter(MenuDesign) \ No newline at end of file -- Gitblit v1.8.0