File tree Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -98,8 +98,13 @@ const activeMenu = ref<string[]>([])
9898// 左侧的菜单
9999const leftMenus = ref <RouteRecordRaw []>([])
100100// 获取左侧菜单
101- const getLeftMenus = (key : string ) => {
102- const arr = searchTree (cloneMenuRoutes , (i ) => i .path === key , { children: ' children' })
101+ const getLeftMenus = (currentRoute ? : RouteRecordRaw , key ? : string ) => {
102+ // 优先从路由的 meta.activeMenu 获取key,如果没有则使用path
103+ const menuKey = currentRoute
104+ ? (currentRoute .meta ?.activeMenu as string ) || currentRoute .path
105+ : key || ' '
106+
107+ const arr = searchTree (cloneMenuRoutes , (i ) => i .path === menuKey , { children: ' children' })
103108 const rootPath = arr .length ? arr [0 ].path : ' '
104109 const obj = cloneMenuRoutes .find ((i ) => i .path === rootPath )
105110 activeMenu .value = obj ? [obj .path ] : [' ' ]
@@ -111,17 +116,17 @@ const onMenuItemClick = (key: string) => {
111116 window .open (key )
112117 return
113118 }
114- setTimeout (() => getLeftMenus (key ))
119+ setTimeout (() => getLeftMenus (undefined , key ))
115120 const obj = topMenus .value .find ((i ) => i .path === key )
116121 if (obj && obj .redirect === ' noRedirect' ) return
117122 router .push ({ path: key })
118123}
119124
120125watch (
121126 () => route .path ,
122- (newPath ) => {
127+ () => {
123128 nextTick (() => {
124- getLeftMenus (newPath )
129+ getLeftMenus (route )
125130 })
126131 },
127132 { immediate: true },
You can’t perform that action at this time.
0 commit comments