Showing
3 changed files
with
33 additions
and
2 deletions
@@ -33,6 +33,7 @@ | @@ -33,6 +33,7 @@ | ||
33 | import { openWindow } from '/@/utils'; | 33 | import { openWindow } from '/@/utils'; |
34 | 34 | ||
35 | import { useOpenKeys } from './useOpenKeys'; | 35 | import { useOpenKeys } from './useOpenKeys'; |
36 | + import { useMenuActiveFix } from '/@/hooks/business/useMenuActiveFix'; | ||
36 | export default defineComponent({ | 37 | export default defineComponent({ |
37 | name: 'SimpleMenu', | 38 | name: 'SimpleMenu', |
38 | components: { | 39 | components: { |
@@ -120,7 +121,10 @@ | @@ -120,7 +121,10 @@ | ||
120 | isClickGo.value = false; | 121 | isClickGo.value = false; |
121 | return; | 122 | return; |
122 | } | 123 | } |
123 | - const path = (route || unref(currentRoute)).path; | 124 | + console.log(route); |
125 | + | ||
126 | + let { flag, path } = useMenuActiveFix(route || unref(currentRoute)); | ||
127 | + path = flag ? path : (route || unref(currentRoute)).path; | ||
124 | 128 | ||
125 | menuState.activeName = path; | 129 | menuState.activeName = path; |
126 | 130 |
@@ -29,7 +29,6 @@ export function useOpenKeys( | @@ -29,7 +29,6 @@ export function useOpenKeys( | ||
29 | return; | 29 | return; |
30 | } | 30 | } |
31 | const keys = getAllParentPath(menuList, path); | 31 | const keys = getAllParentPath(menuList, path); |
32 | - | ||
33 | if (!unref(accordion)) { | 32 | if (!unref(accordion)) { |
34 | menuState.openNames = uniq([...menuState.openNames, ...keys]); | 33 | menuState.openNames = uniq([...menuState.openNames, ...keys]); |
35 | } else { | 34 | } else { |
src/hooks/business/useMenuActiveFix.ts
0 → 100644
1 | +import { RouteLocationNormalizedLoaded } from 'vue-router'; | ||
2 | + | ||
3 | +const menuMap = new Map(); | ||
4 | + | ||
5 | +menuMap.set('/visual/board/detail/:boardId/:boardName?', '/visual/board'); | ||
6 | + | ||
7 | +export const useMenuActiveFix = (route: RouteLocationNormalizedLoaded) => { | ||
8 | + let flag = false; | ||
9 | + let path; | ||
10 | + | ||
11 | + const matchPath = route.matched.map((item) => item.path); | ||
12 | + const needFixMenus: string[] = Array.from(menuMap.keys()); | ||
13 | + | ||
14 | + for (const item of matchPath) { | ||
15 | + for (const menu of needFixMenus) { | ||
16 | + if (menu === item) { | ||
17 | + flag = true; | ||
18 | + path = menuMap.get(menu); | ||
19 | + break; | ||
20 | + } | ||
21 | + } | ||
22 | + } | ||
23 | + | ||
24 | + return { | ||
25 | + flag, | ||
26 | + path, | ||
27 | + }; | ||
28 | +}; |