Blame view

Yi.Vben5.Vue3/apps/backend-mock/api/system/menu/path-exists.ts 772 Bytes
515fceeb   “wangming”   框架初始化
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
  import { verifyAccessToken } from '~/utils/jwt-utils';
  import { MOCK_MENU_LIST } from '~/utils/mock-data';
  import { unAuthorizedResponse } from '~/utils/response';
  
  const pathMap: Record<string, any> = { '/': 0 };
  
  function getPaths(menus: any[]) {
    menus.forEach((menu) => {
      pathMap[menu.path] = String(menu.id);
      if (menu.children) {
        getPaths(menu.children);
      }
    });
  }
  getPaths(MOCK_MENU_LIST);
  
  export default eventHandler(async (event) => {
    const userinfo = verifyAccessToken(event);
    if (!userinfo) {
      return unAuthorizedResponse(event);
    }
    const { id, path } = getQuery(event);
  
    return (path as string) in pathMap &&
      (!id || pathMap[path as string] !== String(id))
      ? useResponseSuccess(true)
      : useResponseSuccess(false);
  });