From 4c6deb49d34372c19e002bf20b84f841eef2cf62 Mon Sep 17 00:00:00 2001 From: zuiidea Date: Fri, 21 Apr 2017 10:47:55 +0800 Subject: [PATCH] fix menu open --- src/components/Layout/Menu.js | 20 ++++++++++++++++---- src/models/app.js | 1 - src/utils/menu.js | 7 ------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/components/Layout/Menu.js b/src/components/Layout/Menu.js index 520e305..b050659 100644 --- a/src/components/Layout/Menu.js +++ b/src/components/Layout/Menu.js @@ -7,12 +7,15 @@ import { arrayToTree } from '../../utils' const Menus = ({ siderFold, darkTheme, location, handleClickNavMenu, navOpenKeys, changeOpenKeys, menu }) => { // 生成树状 const menuTree = arrayToTree(menu.filter(_ => _.mpid !== -1), 'id', 'mpid') - + const levelMap = {} // 递归生成菜单 const getMenus = (menuTreeN, siderFoldN) => { return menuTreeN.map(item => { if (item.chindren) { + if (item.mpid) { + levelMap[item.id] = item.mpid + } return ( { - const map = { - '/navigation/navigation2': ['/navigation'], + let map = {} + const getParent = (index) => { + const result = [String(levelMap[index])] + if (levelMap[result[0]]) { + result.unshift(getParent(result[0])[0]) + } + return result + } + for (let index in levelMap) { + if ({}.hasOwnProperty.call(levelMap, index)) { + map[index] = getParent(index) + } } return map[key] || [] } diff --git a/src/models/app.js b/src/models/app.js index 78536a3..0dca356 100644 --- a/src/models/app.js +++ b/src/models/app.js @@ -133,7 +133,6 @@ export default { } }, handleNavOpenKeys (state, { payload: navOpenKeys }) { - console.log(navOpenKeys) return { ...state, ...navOpenKeys, diff --git a/src/utils/menu.js b/src/utils/menu.js index 9169872..e25cfac 100644 --- a/src/utils/menu.js +++ b/src/utils/menu.js @@ -130,13 +130,6 @@ module.exports = [ name: 'Test Navigation21', router: '/navigation/navigation2/navigation1', }, - { - id: 621, - bpid: 62, - mpid: 62, - name: 'Test Navigation21', - router: '/navigation/navigation2/navigation1', - }, { id: 622, bpid: 62,