提交 | 用户 | 时间
|
820397
|
1 |
import { getAllParentPath } from '@/layout/components/Menu/src/helper' |
H |
2 |
import type { RouteMeta } from 'vue-router' |
|
3 |
import { isUrl } from '@/utils/is' |
|
4 |
import { cloneDeep } from 'lodash-es' |
|
5 |
|
|
6 |
export type TabMapTypes = { |
|
7 |
[key: string]: string[] |
|
8 |
} |
|
9 |
|
|
10 |
export const tabPathMap = reactive<TabMapTypes>({}) |
|
11 |
|
|
12 |
export const initTabMap = (routes: AppRouteRecordRaw[]) => { |
|
13 |
for (const v of routes) { |
|
14 |
const meta = (v.meta ?? {}) as RouteMeta |
|
15 |
if (!meta?.hidden) { |
|
16 |
tabPathMap[v.path] = [] |
|
17 |
} |
|
18 |
} |
|
19 |
} |
|
20 |
|
|
21 |
export const filterMenusPath = ( |
|
22 |
routes: AppRouteRecordRaw[], |
|
23 |
allRoutes: AppRouteRecordRaw[] |
|
24 |
): AppRouteRecordRaw[] => { |
|
25 |
const res: AppRouteRecordRaw[] = [] |
|
26 |
for (const v of routes) { |
|
27 |
let data: Nullable<AppRouteRecordRaw> = null |
|
28 |
const meta = (v.meta ?? {}) as RouteMeta |
|
29 |
if (!meta.hidden || meta.canTo) { |
|
30 |
const allParentPath = getAllParentPath<AppRouteRecordRaw>(allRoutes, v.path) |
|
31 |
|
|
32 |
const fullPath = isUrl(v.path) ? v.path : allParentPath.join('/') |
|
33 |
|
|
34 |
data = cloneDeep(v) |
|
35 |
data.path = fullPath |
|
36 |
if (v.children && data) { |
|
37 |
data.children = filterMenusPath(v.children, allRoutes) |
|
38 |
} |
|
39 |
|
|
40 |
if (data) { |
|
41 |
res.push(data) |
|
42 |
} |
|
43 |
|
|
44 |
if (allParentPath.length && Reflect.has(tabPathMap, allParentPath[0])) { |
|
45 |
tabPathMap[allParentPath[0]].push(fullPath) |
|
46 |
} |
|
47 |
} |
|
48 |
} |
|
49 |
|
|
50 |
return res |
|
51 |
} |