From 365ea069f179ee71a7a8cc7785ccd2d86bd4881c Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期三, 03 二月 2021 18:33:45 +0800 Subject: [PATCH] 2021-02-03 --- src/components/sidemenu/index.jsx | 218 ++---------------------------------------------------- 1 files changed, 9 insertions(+), 209 deletions(-) diff --git a/src/components/sidemenu/index.jsx b/src/components/sidemenu/index.jsx index fe1c20f..adcd930 100644 --- a/src/components/sidemenu/index.jsx +++ b/src/components/sidemenu/index.jsx @@ -1,22 +1,15 @@ import React, {Component} from 'react' -import { withRouter } from 'react-router-dom' import PropTypes from 'prop-types' import { connect } from 'react-redux' import { is, fromJS } from 'immutable' -import { Menu, Icon, notification } from 'antd' +import { Menu, Icon } from 'antd' -import asyncComponent from '@/utils/asyncComponent' -import { modifyTabview, resetEditLevel, modifyMenuTree, modifyMainMenu } from '@/store/action' -import { SySMenuList } from './config' -import options from '@/store/options.js' +import { modifyTabview } from '@/store/action' import MKEmitter from '@/utils/events.js' import zhCN from '@/locales/zh-CN/main.js' import enUS from '@/locales/en-US/main.js' -import Api from '@/api' import './index.scss' -const EditSecMenu = asyncComponent(() => import('@/templates/menuconfig/editsecmenu')) -const EditThdMenu = asyncComponent(() => import('@/templates/menuconfig/editthdmenu')) const { SubMenu } = Menu class Sidemenu extends Component { @@ -27,9 +20,7 @@ state = { dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, subMenulist: [], // 浜岀骇鑿滃崟 - editMenu: null, // 缂栬緫涓夌骇鑿滃崟鏃惰缃� rootSubmenuKeys: null, - createThirdMenu: false, openKeys: null, preview: null } @@ -40,7 +31,6 @@ subMenulist: [], rootSubmenuKeys: [], openKeys: [], - editMenu: null }) return } @@ -56,39 +46,11 @@ subMenulist: menu.children, rootSubmenuKeys: menu.children.map(item => item.MenuID), openKeys: this.props.collapse ? [] : [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: this.props.collapse ? [] : [menulist[0].MenuID] }) } changemenu(e, menu) { e.preventDefault() - if (this.props.editState && this.props.editLevel !== 'HS') { - return - } if (menu.OpenType === 'newpage' || menu.OpenType === 'NewPage') { window.open(menu.src) @@ -119,9 +81,7 @@ } 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))) { + if (!is(fromJS(this.props.mainMenu), fromJS(nextProps.mainMenu))) { // 涓昏彍鍗曞垏鎹紝璇锋眰2銆�3绾ц彍鍗曟暟鎹� this.loadsubmenu(nextProps.mainMenu) } else if (nextProps.collapse && this.props.collapse !== nextProps.collapse) { @@ -147,161 +107,25 @@ } } - enterSubEdit = (e) => { - // 缂栬緫浜岀骇鑿滃崟 - e.stopPropagation() - this.props.resetEditLevel('level2') - } - - enterThrEdit = (e, menu) => { - // 缂栬緫涓夌骇鑿滃崟 - e.stopPropagation() - this.props.resetEditLevel('level3') - 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}) - } - this.props.resetEditLevel(false) - } - render () { const { mainMenu } = this.props - const editShow = (this.props.editState && !this.props.editLevel) || false if (mainMenu === '') return (<span className="mk-side-menu-hidden"></span>) return ( - <aside id="mk-sidemenu-wrap" className={'mk-side-menu ant-menu-dark' + (this.props.collapse ? ' collapsed' : '') + (this.props.isiframe ? ' mk-iframe' : '') + (this.props.editState ? ' mk-edit' : '')}> - {!(this.props.editLevel === 'level2' || this.props.editLevel === 'level3') && - <Menu openKeys={this.state.openKeys} onOpenChange={this.onOpenChange} mode="inline" theme="dark" inlineCollapsed={this.props.collapse}> - {editShow && <li className="sup-menu"><Icon onClick={this.enterSubEdit} className="edit-check" type="edit" /></li>} - {this.state.subMenulist && this.state.subMenulist.map((item, index) => { + <aside id="mk-sidemenu-wrap" className={'mk-side-menu ant-menu-dark' + (this.props.collapse ? ' collapsed' : '') + (this.props.isiframe ? ' mk-iframe' : '')}> + <Menu openKeys={this.state.openKeys} onOpenChange={this.onOpenChange} mode="inline" theme="dark" inlineCollapsed={this.props.collapse}> + {this.state.subMenulist && this.state.subMenulist.map((item) => { return ( <SubMenu key={item.MenuID} title={ - <span className={editShow && index === 0 ? 'edit-control' : ''}> + <span> <Icon type={item.PageParam.Icon} /> <span>{item.MenuName}</span> </span> } > - {editShow ? <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} {item.children.map(cell => { return ( <Menu.Item key={cell.MenuID}> @@ -312,25 +136,7 @@ </SubMenu> ) })} - </Menu>} - {this.props.editLevel === 'level2' ? - <EditSecMenu - menulist={this.state.subMenulist} - menuTree={this.props.menuTree} - supMenu={this.props.mainMenu} - reload={this.reload} - exitEdit={this.exitEdit} - /> : null - } - {this.props.editLevel === 'level3' && this.state.editMenu ? - <EditThdMenu - menulist={this.state.editMenu.children} - supMenuList={this.state.subMenulist} - supMenu={this.state.editMenu} - reload={this.reload} - exitEdit={this.exitEdit} - /> : null - } + </Menu> </aside> ) } @@ -343,19 +149,13 @@ isiframe: state.isiframe, mainMenu: state.mainMenu, menuTree: state.menuTree, - memberLevel: state.memberLevel, - editState: state.editState, - 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 withRouter(connect(mapStateToProps, mapDispatchToProps)(Sidemenu)) \ No newline at end of file +export default connect(mapStateToProps, mapDispatchToProps)(Sidemenu) \ No newline at end of file -- Gitblit v1.8.0