| | |
| | | import { Menu, Icon, notification } from 'antd' |
| | | |
| | | import asyncComponent from '@/utils/asyncComponent' |
| | | import { modifyTabview, resetEditLevel } from '@/store/action' |
| | | 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' |
| | |
| | | |
| | | class Sidemenu extends Component { |
| | | static propTypes = { |
| | | collapse: PropTypes.bool, |
| | | mainMenu: PropTypes.oneOfType([ |
| | | PropTypes.string, |
| | | PropTypes.object |
| | | ]) |
| | | collapse: PropTypes.bool |
| | | } |
| | | |
| | | state = { |
| | | dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, |
| | | mainMenuList: null, // 一级菜单,编辑调整上级菜单时获取 |
| | | subMenulist: [], // 二级菜单 |
| | | editMenu: null, // 编辑三级菜单时设置 |
| | | rootSubmenuKeys: null, |
| | |
| | | return |
| | | } |
| | | |
| | | let _param = {func: 'sPC_Get_FunMenu', ParentID: menu.MenuID, systemType: options.sysType} |
| | | menu = fromJS(menu).toJS() |
| | | let openKey = '' |
| | | |
| | | if (sessionStorage.getItem('isEditState') === 'true') { // 编辑状态时,获取菜单,增加参数debug |
| | | _param.debug = 'Y' |
| | | if (menu.children[0]) { |
| | | openKey = menu.openId || menu.children[0].MenuID |
| | | } |
| | | |
| | | let result = await Api.getSystemConfig(_param) |
| | | if (result.status) { |
| | | if (this.props.editState && this.props.editLevel === 'HS') return |
| | | |
| | | if (result.data.length === 0) { // 查询菜单为空 |
| | | this.setState({ |
| | | subMenulist: [], |
| | | rootSubmenuKeys: [], |
| | | openKeys: [] |
| | | }) |
| | | return |
| | | } |
| | | |
| | | let SubMenuId = sessionStorage.getItem('SubMenu') // 是否为打开新页面 |
| | | let ThirdMenuId = sessionStorage.getItem('ThirdMenu') // 是否为打开新页面 |
| | | let submenuId = '' // 展开二级菜单ID |
| | | let tabId = '' // 打开的tab页id |
| | | let msg = { |
| | | UserID: sessionStorage.getItem('UserID'), |
| | | LoginUID: sessionStorage.getItem('LoginUID'), |
| | | User_Name: sessionStorage.getItem('User_Name'), |
| | | Full_Name: sessionStorage.getItem('Full_Name'), |
| | | Member_Level: sessionStorage.getItem('Member_Level'), |
| | | dataM: sessionStorage.getItem('dataM'), |
| | | avatar: sessionStorage.getItem('avatar'), |
| | | debug: sessionStorage.getItem('debug'), |
| | | role_id: sessionStorage.getItem('role_id'), |
| | | mainlogo: window.GLOB.mainlogo, |
| | | mstyle: window.GLOB.style, |
| | | MainMenu: menu.MenuID |
| | | } |
| | | |
| | | if (SubMenuId && ThirdMenuId) { |
| | | submenuId = SubMenuId |
| | | let submenu = result.data.filter(item => item.ParentID === SubMenuId)[0] |
| | | |
| | | if (!submenu) { |
| | | submenuId = '' |
| | | } else { |
| | | tabId = ThirdMenuId |
| | | let tabmenu = submenu.FunMenu.filter(item => item.MenuID === ThirdMenuId)[0] |
| | | if (!tabmenu) { |
| | | submenuId = '' |
| | | tabId = '' |
| | | } |
| | | } |
| | | sessionStorage.removeItem('SubMenu') |
| | | sessionStorage.removeItem('ThirdMenu') |
| | | } |
| | | let parentID = submenuId ? submenuId : result.data[0].ParentID // 展开二级菜单ID |
| | | |
| | | let iframes = ['Main/Index', 'bda/rdt', 'Home/rdt'] |
| | | |
| | | let menulist = result.data.map(item => { |
| | | let _smenu = {} |
| | | _smenu.id = item.ParentID |
| | | _smenu.MenuID = item.ParentID |
| | | _smenu.text = item.MenuNameP |
| | | |
| | | try { |
| | | _smenu.PageParam = JSON.parse(item.PageParamP) |
| | | } catch (e) { |
| | | _smenu.PageParam = {Icon: 'folder'} |
| | | } |
| | | |
| | | if (item.FunMenu) { |
| | | _smenu.children = item.FunMenu.map(child => { |
| | | let _tmenu = { |
| | | ParentId: item.ParentID, |
| | | OpenType: 'newtab' |
| | | } |
| | | |
| | | if (child.LinkUrl === 'CommonTable') { |
| | | _tmenu.type = 'CommonTable' |
| | | } else if (iframes.includes(child.LinkUrl.split('?')[0])) { |
| | | _tmenu.type = 'iframe' |
| | | _tmenu.forbidden = true |
| | | } |
| | | |
| | | if (_tmenu.type !== 'iframe') { |
| | | try { |
| | | _tmenu.PageParam = JSON.parse(child.PageParam) |
| | | } catch (e) { |
| | | _tmenu.PageParam = {OpenType: 'newtab'} |
| | | } |
| | | _tmenu.type = _tmenu.PageParam.Template || _tmenu.type |
| | | _tmenu.OpenType = _tmenu.PageParam.OpenType |
| | | } |
| | | |
| | | if (_tmenu.type === 'NewPage') { |
| | | _tmenu.src = _tmenu.PageParam.url |
| | | if (this.props.memberLevel < 20) { // 会员等级大于等于20时,有编辑权限 |
| | | _tmenu.forbidden = true |
| | | } |
| | | if (_tmenu.src.indexOf('paramsmain/') > -1) { |
| | | try { |
| | | let _url = _tmenu.src.split('paramsmain/')[0] + 'paramsmain/' |
| | | let _param = JSON.parse(window.decodeURIComponent(window.atob(_tmenu.src.split('paramsmain/')[1]))) |
| | | _param.UserID = sessionStorage.getItem('UserID') |
| | | _param.LoginUID = sessionStorage.getItem('LoginUID') |
| | | _param.User_Name = sessionStorage.getItem('User_Name') |
| | | _tmenu.src = _url + window.btoa(window.encodeURIComponent(JSON.stringify(_param))) |
| | | } catch { |
| | | console.warn('菜单参数解析错误!') |
| | | } |
| | | } |
| | | } else { |
| | | // 打开新页面链接 |
| | | _tmenu.src = '#/paramsmain/' + window.btoa(window.encodeURIComponent(JSON.stringify({ |
| | | ...msg, |
| | | SubMenu: _smenu.MenuID, |
| | | ThirdMenu: child.MenuID |
| | | }))) |
| | | } |
| | | |
| | | _tmenu.id = child.MenuID |
| | | _tmenu.MenuID = child.MenuID |
| | | _tmenu.MenuNo = child.MenuNo |
| | | _tmenu.MenuName = child.MenuName |
| | | _tmenu.text = child.MenuName |
| | | return _tmenu |
| | | }) |
| | | } |
| | | return _smenu |
| | | }) |
| | | |
| | | this.setState({ |
| | | subMenulist: menulist, |
| | | rootSubmenuKeys: result.data.map(item => item.ParentID), |
| | | openKeys: this.props.collapse ? [] : [parentID], |
| | | editMenu: this.props.editLevel === 'level3' && menulist.filter(menu => menu.MenuID === this.state.editMenu.MenuID)[0] |
| | | }) |
| | | if (tabId) { |
| | | let _menu = menulist.filter(menu => menu.MenuID === submenuId)[0] |
| | | let opentab = _menu && _menu.children.filter(tab => tab.MenuID === tabId)[0] |
| | | if (opentab) { |
| | | if (sessionStorage.getItem('MenuParam')) { |
| | | try { |
| | | let thParam = JSON.parse(sessionStorage.getItem('MenuParam')) |
| | | |
| | | if (tabId === thParam.ThirdMenu) { |
| | | delete thParam.ThirdMenu |
| | | opentab.param = thParam |
| | | } |
| | | } catch { |
| | | console.warn('菜单参数解析错误!') |
| | | } |
| | | sessionStorage.removeItem('MenuParam') |
| | | } |
| | | |
| | | opentab.selected = true |
| | | let home = this.props.tabviews[0] |
| | | home.selected = false |
| | | this.props.modifyTabview([home, opentab]) |
| | | } |
| | | } |
| | | } else { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: result.message, |
| | | duration: 5 |
| | | }) |
| | | } |
| | | this.setState({ |
| | | 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 = (type) => { |
| | | let menulist = SySMenuList[type] |
| | | enterManageView = () => { |
| | | let menulist = SySMenuList |
| | | |
| | | if (window.GLOB.systemType === 'production') { |
| | | menulist.forEach(menu => { |
| | |
| | | |
| | | let menu = JSON.parse(e.target.dataset.item) |
| | | |
| | | if (menu.OpenType === 'newpage') { |
| | | e.preventDefault() |
| | | window.open(menu.src) |
| | | } else if (menu.OpenType === 'NewPage') { |
| | | if (menu.OpenType === 'newpage' || menu.OpenType === 'NewPage') { |
| | | e.preventDefault() |
| | | window.open(menu.src) |
| | | } else if (menu.OpenType === 'blank') { |
| | |
| | | |
| | | UNSAFE_componentWillReceiveProps (nextProps) { |
| | | if (!is(fromJS(this.props.mainMenu), fromJS(nextProps.mainMenu)) && nextProps.mainMenu && nextProps.mainMenu.MenuID === 'systemManageView') { |
| | | this.enterManageView(nextProps.mainMenu.MenuID) |
| | | this.enterManageView() |
| | | } else if (!is(fromJS(this.props.mainMenu), fromJS(nextProps.mainMenu))) { |
| | | // 主菜单切换,请求2、3级菜单数据 |
| | | this.loadsubmenu(nextProps.mainMenu) |
| | |
| | | // 编辑二级菜单 |
| | | e.stopPropagation() |
| | | this.props.resetEditLevel('level2') |
| | | // 获取一级菜单列表 |
| | | Api.getSystemConfig({func: 'sPC_Get_MainMenu', debug: 'Y'}).then(res => { |
| | | this.setState({ |
| | | mainMenuList: res.data.map(item => { |
| | | return { |
| | | MenuID: item.MenuID, |
| | | text: item.MenuName |
| | | } |
| | | }) |
| | | }) |
| | | }) |
| | | } |
| | | |
| | | enterThrEdit = (e, menu) => { |
| | |
| | | } |
| | | |
| | | reload = () => { |
| | | this.loadsubmenu(this.props.mainMenu) |
| | | 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 = () => { |
| | |
| | | title={ |
| | | <span className={editShow && index === 0 ? 'edit-control' : ''}> |
| | | <Icon type={item.PageParam.Icon} /> |
| | | <span>{item.text}</span> |
| | | <span>{item.MenuName}</span> |
| | | </span> |
| | | } |
| | | > |
| | |
| | | {item.children.map(cell => { |
| | | return ( |
| | | <Menu.Item key={cell.MenuID}> |
| | | <a href={cell.src} id={cell.MenuID} data-item={JSON.stringify(cell)} onClick={this.changemenu.bind(this)}>{cell.text}</a> |
| | | <a href={cell.src} id={cell.MenuID} data-item={JSON.stringify(cell)} onClick={this.changemenu.bind(this)}>{cell.MenuName}</a> |
| | | </Menu.Item> |
| | | ) |
| | | })} |
| | |
| | | {this.props.editLevel === 'level2' ? |
| | | <EditSecMenu |
| | | menulist={this.state.subMenulist} |
| | | supMenuList={this.state.mainMenuList} |
| | | menuTree={this.props.menuTree} |
| | | supMenu={this.props.mainMenu} |
| | | reload={this.reload} |
| | | exitEdit={this.exitEdit} |
| | | /> : null |
| | | } |
| | | {this.props.editLevel === 'level3' && this.state.subMenulist && this.state.editMenu ? |
| | | {this.props.editLevel === 'level3' && this.state.editMenu ? |
| | | <EditThdMenu |
| | | menulist={this.state.editMenu.children} |
| | | supMenuList={this.state.subMenulist} |
| | |
| | | tabviews: state.tabviews, |
| | | collapse: state.collapse, |
| | | isiframe: state.isiframe, |
| | | mainMenu: state.selectedMainMenu, |
| | | 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)) |
| | | } |