MCPcopy Create free account
hub / github.com/baiwumm/react-admin / access

Function access

Xmw_web/src/access.ts:9–37  ·  view source on GitHub ↗
(initialState: InitialStateTypes | undefined)

Source from the content-addressed store, hash-verified

7import type { InitialStateTypes } from '@/utils/types'
8
9export default function access(initialState: InitialStateTypes | undefined) {
10 // 获取按钮权限集合
11 const { Permissions, RouteMenu } = initialState ?? {};
12 /**
13 * @description: 获取当前所有路由
14 * @author: 白雾茫茫丶
15 */
16 const getRouteNames = (tree = RouteMenu): string[] => {
17 // 收集当前层级的所有 name 属性
18 let result: string[] = []
19 // 遍历收集
20 forEach(tree, (node: API.MENUMANAGEMENT) => {
21 result.push(node.name);
22 if (node?.routes?.length) {
23 result = result.concat(getRouteNames(node.routes));
24 }
25 });
26 return result
27 }
28 return {
29 // 判断是否有操作权限
30 operationPermission: (data: string) => Permissions ? Permissions.includes(data) : false,
31 // 判断是否有权限访问菜单
32 adminRouteFilter: (route: any) => {
33 const allRouteNames = getRouteNames()
34 return allRouteNames.includes(route.name)
35 },
36 };
37}

Callers

nothing calls this directly

Calls 1

getRouteNamesFunction · 0.85

Tested by

no test coverage detected