From 7e46c386be5c2cfc20af3936d26839ad3fce44b0 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期三, 16 八月 2023 17:40:32 +0800 Subject: [PATCH] Merge branch 'master' into positec --- src/views/design/sidemenu/index.jsx | 488 ++++++++++++++++++++++++++++++----------------------- 1 files changed, 275 insertions(+), 213 deletions(-) diff --git a/src/views/design/sidemenu/index.jsx b/src/views/design/sidemenu/index.jsx index 925abe2..3e07e00 100644 --- a/src/views/design/sidemenu/index.jsx +++ b/src/views/design/sidemenu/index.jsx @@ -1,35 +1,39 @@ import React, {Component} from 'react' -import { connect } from 'react-redux' import { is, fromJS } from 'immutable' -import { Menu, Icon, notification } from 'antd' +import { Menu, Popover, Modal, notification } from 'antd' +import { EditOutlined, PlusOutlined, SettingOutlined } from '@ant-design/icons' +import moment from 'moment' import asyncComponent from '@/utils/asyncComponent' -import { modifyTabview, resetEditLevel, modifyMenuTree, modifyMainMenu } from '@/store/action' -import { SySMenuList } from './config' -import options from '@/store/options.js' -import zhCN from '@/locales/zh-CN/main.js' -import enUS from '@/locales/en-US/main.js' +import Utils from '@/utils/utils.js' import Api from '@/api' +import MKEmitter from '@/utils/events.js' +import MkIcon from '@/components/mk-icon' import './index.scss' -const EditSecMenu = asyncComponent(() => import('@/templates/menuconfig/editsecmenu')) -const EditThdMenu = asyncComponent(() => import('@/templates/menuconfig/editthdmenu')) +const EditSecMenu = asyncComponent(() => import('./editsecmenu')) +const EditThdMenu = asyncComponent(() => import('./editthdmenu')) +const ThawMenu = asyncComponent(() => import('@/components/thawmenu')) +const AddThdMenu = asyncComponent(() => import('./thdmenuplus')) +const ThdMenuForm = asyncComponent(() => import('./thdmenuform')) +const MenuForm = asyncComponent(() => import('./menuform')) const { SubMenu } = Menu class Sidemenu extends Component { state = { - dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, - subMenulist: [], // 浜岀骇鑿滃崟 editMenu: null, // 缂栬緫涓夌骇鑿滃崟鏃惰缃� rootSubmenuKeys: null, openKeys: null, - preview: null + preview: null, + loading: false, + thdVisible: false, + sysMenu: null, + formlist: [] } async loadsubmenu (menu) { if (!menu || !menu.MenuID) { // 娌℃湁涓昏彍鍗曟椂锛屾竻绌轰笅绾ц彍鍗� this.setState({ - subMenulist: [], rootSubmenuKeys: [], openKeys: [], editMenu: null @@ -40,76 +44,32 @@ menu = fromJS(menu).toJS() let openKey = '' - if (menu.children[0]) { - openKey = menu.openId || menu.children[0].MenuID + // 鑿滃崟鏇存柊鏃讹紝灞曞紑鍘熶簩绾ц彍鍗� + if (this.props.mainMenu && menu.MenuID === this.props.mainMenu.MenuID && this.state.openKeys && this.state.openKeys[0]) { + openKey = this.state.openKeys[0] + if (menu.children.filter(m => m.MenuID === openKey).length === 0) { + openKey = '' + } + } + if (!openKey && menu.children[0]) { + openKey = menu.children[0].MenuID } this.setState({ - subMenulist: menu.children, rootSubmenuKeys: menu.children.map(item => item.MenuID), openKeys: openKey ? [openKey] : [], editMenu: this.props.editLevel === 'level3' ? menu.children.filter(_menu => _menu.MenuID === this.state.editMenu.MenuID)[0] : null }) } - enterManageView = () => { - let menulist = SySMenuList - - if (window.GLOB.systemType === 'production') { - menulist.forEach(menu => { - menu.children = menu.children.filter(item => item.systems && item.systems.includes(window.GLOB.systemType)) - }) - - menulist = menulist.filter(menu => menu.children.length > 0) - } else { - menulist.forEach(menu => { - menu.children = menu.children.filter(item => !item.systems || item.systems.includes(options.sysType)) - }) - - menulist = menulist.filter(menu => menu.children.length > 0) - } - - this.setState({ - subMenulist: menulist, - rootSubmenuKeys: menulist.map(item => item.MenuID), - openKeys: [menulist[0].MenuID] - }) - } - - changemenu(e, menu) { - e.preventDefault() - if (this.props.editLevel !== 'HS') { - return - } - - let tabs = fromJS(this.props.tabviews).toJS() - tabs = tabs.filter(tab => { - tab.selected = false - return tab.MenuID !== menu.MenuID - }) - - if (this.props.tabviews.length !== tabs.length) { - this.props.modifyTabview(fromJS(tabs).toJS()) - } - - this.setState({}, () => { - menu.selected = true - tabs.push(menu) - this.props.modifyTabview(tabs) - }) + shouldComponentUpdate (nextProps, nextState) { + return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState)) } UNSAFE_componentWillReceiveProps (nextProps) { - if (!is(fromJS(this.props.mainMenu), fromJS(nextProps.mainMenu)) && nextProps.mainMenu && nextProps.mainMenu.MenuID === 'systemManageView') { - this.enterManageView() - } else if (!is(fromJS(this.props.mainMenu), fromJS(nextProps.mainMenu))) { - // 涓昏彍鍗曞垏鎹紝璇锋眰2銆�3绾ц彍鍗曟暟鎹� + if (!is(fromJS(this.props.mainMenu), fromJS(nextProps.mainMenu))) { this.loadsubmenu(nextProps.mainMenu) } - } - - shouldComponentUpdate(nextProps, nextState) { - return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState)) } onOpenChange = openKeys => { @@ -126,6 +86,9 @@ enterSubEdit = (e) => { // 缂栬緫浜岀骇鑿滃崟 e.stopPropagation() + + if (this.props.mainMenu.children.length === 0) return + this.props.resetEditLevel('level2') } @@ -136,113 +99,6 @@ this.setState({editMenu: menu}) } - reload = () => { - const { mainMenu } = this.props - let _param = {func: 's_get_pc_menus', systemType: options.sysType, debug: 'Y'} - if (options.sysType !== 'cloud' && window.GLOB.systemType !== 'production') { - _param.linkurl = window.GLOB.linkurl - } - _param.pro_sys = window.GLOB.systemType === 'production' ? 'Y' : '' - - Api.getSystemConfig(_param).then(result => { - // 鐧诲綍瓒呮椂 - if (!result) return - - if (result.status) { - let res = this.getMenulist(result) - let _mainMenu = res.menulist.filter(item => item.MenuID === mainMenu.MenuID)[0] - - this.props.modifyMenuTree(res.menulist) - this.props.modifyMainMenu(_mainMenu || null) - } else { - notification.error({ - top: 92, - message: result.message, - duration: 10 - }) - } - this.loadsubmenu(this.props.mainMenu) - }) - } - - getMenulist = (result) => { - let iframes = ['Main/Index', 'bda/rdt', 'Home/rdt'] - let menulist = result.fst_menu.map(fst => { - let fstItem = { - MenuID: fst.MenuID, - MenuName: fst.MenuName, - PageParam: {OpenType: 'menu', linkUrl: ''}, - children: [] - } - if (fst.PageParam) { - try { - fstItem.PageParam = JSON.parse(fst.PageParam) - } catch (e) { - fstItem.PageParam = {OpenType: 'menu', linkUrl: ''} - } - } - - if (fst.snd_menu) { - fstItem.children = fst.snd_menu.map(snd => { - let sndItem = { - ParentId: fst.MenuID, - MenuID: snd.MenuID, - MenuName: snd.MenuName, - PageParam: {Icon: 'folder'}, - children: [] - } - - if (snd.PageParam) { - try { - sndItem.PageParam = JSON.parse(snd.PageParam) - } catch (e) { - sndItem.PageParam = {Icon: 'folder'} - } - } - - if (snd.trd_menu) { - sndItem.children = snd.trd_menu.map(trd => { - let trdItem = { - FstId: fst.MenuID, - ParentId: snd.MenuID, - MenuID: trd.MenuID, - MenuName: trd.MenuName, - MenuNo: trd.MenuNo, - EasyCode: trd.EasyCode, - type: 'CommonTable', // 榛樿鍊间负甯哥敤琛� - OpenType: 'newtab' // 鎵撳紑鏂瑰紡 - } - - if (trd.LinkUrl && iframes.includes(trd.LinkUrl.split('?')[0])) { - trdItem.type = 'iframe' - trdItem.LinkUrl = trd.LinkUrl - trdItem.forbidden = true - } else { - try { - trdItem.PageParam = trd.PageParam ? JSON.parse(trd.PageParam) : {OpenType: 'newtab'} - } catch (e) { - trdItem.PageParam = {OpenType: 'newtab'} - } - - trdItem.type = trdItem.PageParam.Template || trdItem.type - trdItem.OpenType = trdItem.PageParam.OpenType || trdItem.OpenType - - if (trdItem.type === 'CustomPage' && this.props.memberLevel < 20) { // 浼氬憳绛夌骇澶т簬绛変簬20鏃讹紝鏈夌紪杈戞潈闄� - trdItem.forbidden = true - } - } - return trdItem - }) - } - return sndItem - }) - } - return fstItem - }) - - return { menulist } - } - exitEdit = () => { if (this.props.editLevel === 'level3') { this.setState({editMenu: null}) @@ -250,77 +106,283 @@ this.props.resetEditLevel(false) } + editmenu = (cell) => { + if (window.GLOB.systemType === 'production') return + + if (cell.type === 'CustomPage') { + let _param = { + MenuType: 'custom', + MenuId: cell.MenuID, + ParentId: cell.ParentId, + MenuName: cell.MenuName, + MenuNo: cell.MenuNo + } + _param = window.btoa(window.encodeURIComponent(JSON.stringify(_param))) + window.open(`#/menudesign/${_param}`) + } else if (['CommonTable', 'TreePage'].includes(cell.type)) { + sessionStorage.setItem('menuTree', JSON.stringify(this.props.menuTree)) + let _param = window.btoa(window.encodeURIComponent(JSON.stringify(cell))) + + window.open(`#/basedesign/${_param}`) + } else if (cell.type === 'BaseTable') { + sessionStorage.setItem('menuTree', JSON.stringify(this.props.menuTree)) + let _param = window.btoa(window.encodeURIComponent(JSON.stringify(cell))) + + window.open(`#/tabledesign/${_param}`) + } else if (['RolePermission', 'NewPage'].includes(cell.type)) { + let _cell = fromJS(cell).toJS() + _cell.Template = _cell.PageParam.Template + _cell.url = _cell.PageParam.url || '' + + _cell.fstMenuId = _cell.FstId + _cell.supMenuList = this.props.mainMenu.children + _cell.fstMenuList = this.props.menuTree + + this.setState({ + thdVisible: true, + loading: false, + sysMenu: _cell + }) + } else { + notification.warning({ + top: 92, + message: '褰撳墠鑿滃崟涓嶅彲缂栬緫', + duration: 5 + }) + } + } + + addSecMenu = () => { + this.setState({ + visible: true, + loading: false, + formlist: [ + { // 鐖剁骇鑿滃崟 + type: 'select', + key: 'parentId', + label: '涓婄骇鑿滃崟', + initVal: this.props.mainMenu.MenuID, + required: true, + options: this.props.menuTree + }, + { // 鑿滃崟鍚嶇О + type: 'text', + key: 'menuName', + label: '鑿滃崟鍚嶇О', + initVal: '', + required: true, + readonly: false + }, + { // 鑿滃崟鍥炬爣 + type: 'icon', + key: 'icon', + label: '鍥炬爣', + initVal: 'folder', + required: true + } + ] + }) + } + + secSubmit = () => { + this.menuFormRef.handleConfirm().then(values => { + let param = { + ParentID: values.parentId, + MenuID: Utils.getuuid(), + MenuName: values.menuName, + PageParam: JSON.stringify({ + Icon: values.icon + }) + } + param.func = 'sPC_SndMenu_Add' + param.Sort = (this.props.mainMenu.children.length + 1) * 10 + + this.setState({ + loading: true + }) + Api.getCloudConfig(param).then(res => { + if (res.status) { + this.setState({ + loading: false, + visible: false + }) + MKEmitter.emit('mkUpdateMenuList') + } else { + this.setState({ + loading: false + }) + notification.warning({ + top: 92, + message: res.message, + duration: 5 + }) + } + }) + }) + } + + /** + * @description 涓夌骇鑿滃崟淇敼 + */ + thdSubmit = () => { + const { sysMenu } = this.state + + this.menuThdFormRef.handleConfirm().then(res => { + let PageParam = { + Template: sysMenu.Template, + OpenType: 'newtab' + } + + if (sysMenu.Template === 'NewPage') { + PageParam.OpenType = 'NewPage' + PageParam.url = res.url + } + + let param = { + func: 'sPC_TrdMenu_AddUpt', + FstID: res.fstMenuId, + SndID: res.ParentID, + ParentID: res.ParentID, + MenuID: sysMenu.MenuID, + MenuNo: res.MenuNo, + Template: sysMenu.Template, + MenuName: res.MenuName, + PageParam: JSON.stringify(PageParam), + LongParam: '', + LText: '', + LTexttb: '' + } + + param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + param.secretkey = Utils.encrypt(param.LText, param.timestamp) + + this.setState({ + loading: true + }) + + Api.getCloudConfig(param).then(response => { + if (response.status) { + this.setState({ + loading: false, + thdVisible: false, + sysMenu: null + }) + MKEmitter.emit('mkUpdateMenuList') + } else { + this.setState({ + loading: false + }) + notification.warning({ + top: 92, + message: response.message, + duration: 5 + }) + } + }) + }) + } + render () { + const { mainMenu, editLevel } = this.props + const { visible, loading, thdVisible } = this.state + return ( - <aside id="mk-sidemenu-wrap" className="mk-sys-side-menu ant-menu-dark mk-edit"> - {!(this.props.editLevel === 'level2' || this.props.editLevel === 'level3') && + <aside className="mk-sys-side-menu ant-menu-dark mk-edit"> + {editLevel !== 'level2' && editLevel !== 'level3' && mainMenu ? <Menu openKeys={this.state.openKeys} onOpenChange={this.onOpenChange} mode="inline" theme="dark"> - {!this.props.editLevel && <li className="sup-menu"><Icon onClick={this.enterSubEdit} className="edit-check" type="edit" /></li>} - {this.state.subMenulist && this.state.subMenulist.map((item, index) => { + <li className="sup-menu"> + <Popover overlayClassName="mk-popover-control-wrap mk-menu-control" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={ + <div className="mk-popover-control"> + <PlusOutlined onClick={this.addSecMenu}/> + <EditOutlined onClick={this.enterSubEdit} className={'mk-swap' + (mainMenu.children.length === 0 ? ' disabled' : '')}/> + <div style={{display: 'inline-block', minWidth: '32px'}}><ThawMenu ParentId={mainMenu.MenuID} Type="20"/></div> + </div> + } trigger="hover" placement="top"> + <SettingOutlined className="edit-check"/> + </Popover> + </li> + {mainMenu.children.map((item, index) => { return ( <SubMenu key={item.MenuID} title={ - <span className={!this.props.editLevel && index === 0 ? 'edit-control' : ''}> - <Icon type={item.PageParam.Icon} /> + <span className={!editLevel && index === 0 ? 'edit-control' : ''}> + <MkIcon type={item.PageParam ? item.PageParam.Icon : 'folder'} /> <span>{item.MenuName}</span> </span> } > - {!this.props.editLevel ? <li className={'ant-menu-item ' + (item.children.length > 0 ? 'sub-menu' : '')}> - <Icon onClick={(e) => {this.enterThrEdit(e, item)}} className="edit-check" type="edit" /> - </li> : null} + <li className={'ant-menu-item ' + (item.children.length > 0 ? 'sub-menu' : '')}> + <Popover overlayClassName="mk-popover-control-wrap mk-menu-control" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={ + <div className="mk-popover-control"> + <div style={{display: 'inline-block', minWidth: '32px'}}><AddThdMenu mainMenu={mainMenu} supMenu={item} menuTree={this.props.menuTree}/></div> + <EditOutlined onClick={(e) => {this.enterThrEdit(e, item)}} className="mk-swap"/> + <div style={{display: 'inline-block', minWidth: '32px'}}><ThawMenu ParentId={item.MenuID} Type="30"/></div> + </div> + } trigger="hover" placement="top"> + <SettingOutlined className="edit-check"/> + </Popover> + </li> {item.children.map(cell => { return ( <Menu.Item key={cell.MenuID}> - <a href={cell.src} id={cell.MenuID} onClick={(e) => this.changemenu(e, cell)}>{cell.MenuName}</a> + <span className="editable-menu-item" onDoubleClick={() => this.editmenu(cell)}>{cell.MenuName}</span> </Menu.Item> ) })} </SubMenu> ) })} - </Menu>} - {this.props.editLevel === 'level2' ? + </Menu> : null} + {editLevel === 'level2' && mainMenu ? <EditSecMenu - menulist={this.state.subMenulist} + menulist={mainMenu.children} menuTree={this.props.menuTree} supMenu={this.props.mainMenu} - reload={this.reload} exitEdit={this.exitEdit} /> : null } - {this.props.editLevel === 'level3' && this.state.editMenu ? + {editLevel === 'level3' && mainMenu && this.state.editMenu ? <EditThdMenu menulist={this.state.editMenu.children} - supMenuList={this.state.subMenulist} + supMenuList={mainMenu.children} supMenu={this.state.editMenu} - reload={this.reload} + menuTree={this.props.menuTree} exitEdit={this.exitEdit} /> : null } + <Modal + title="娣诲姞鑿滃崟" + visible={visible} + onOk={this.secSubmit} + // confirmLoading={loading} + onCancel={() => this.setState({visible: false})} + destroyOnClose + > + <MenuForm + inputSubmit={this.secSubmit} + formlist={this.state.formlist} + wrappedComponentRef={(inst) => this.menuFormRef = inst} + /> + </Modal> + <Modal + title="淇敼鑿滃崟" + visible={thdVisible} + width={700} + onOk={this.thdSubmit} + confirmLoading={loading} + onCancel={() => {this.setState({thdVisible: false})}} + destroyOnClose + > + <ThdMenuForm + menu={this.state.sysMenu} + inputSubmit={this.thdSubmit} + wrappedComponentRef={(inst) => this.menuThdFormRef = inst} + /> + </Modal> </aside> ) } } -const mapStateToProps = (state) => { - return { - tabviews: state.tabviews, - mainMenu: state.mainMenu, - menuTree: state.menuTree, - memberLevel: state.memberLevel, - editLevel: state.editLevel - } -} - -const mapDispatchToProps = (dispatch) => { - return { - modifyMenuTree: (menuTree) => dispatch(modifyMenuTree(menuTree)), - modifyMainMenu: (mainMenu) => dispatch(modifyMainMenu(mainMenu)), - modifyTabview: (tabviews) => dispatch(modifyTabview(tabviews)), - resetEditLevel: (level) => dispatch(resetEditLevel(level)) - } -} - -export default connect(mapStateToProps, mapDispatchToProps)(Sidemenu) \ No newline at end of file +export default Sidemenu \ No newline at end of file -- Gitblit v1.8.0