menu.controller.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { sleep } from '@/utils';
  2. import { Controller, Get, HttpCode, HttpStatus, Request } from '@nestjs/common';
  3. @Controller('menu')
  4. export class MenuController {
  5. /**
  6. * 获取用户所有菜单
  7. */
  8. @Get('getAll')
  9. @HttpCode(HttpStatus.OK)
  10. async getAll(@Request() req: Request) {
  11. // 模拟请求延迟
  12. await sleep(1000);
  13. // 请求用户的id
  14. const userId = req.user.id;
  15. // TODO: 改为表方式获取
  16. const dashboardMenus = [
  17. {
  18. component: 'BasicLayout',
  19. meta: {
  20. order: -1,
  21. title: 'page.dashboard.title',
  22. },
  23. name: 'Dashboard',
  24. path: '/',
  25. redirect: '/analytics',
  26. children: [
  27. {
  28. name: 'Analytics',
  29. path: '/analytics',
  30. component: '/dashboard/analytics/index',
  31. meta: {
  32. affixTab: true,
  33. title: 'page.dashboard.analytics',
  34. },
  35. },
  36. {
  37. name: 'Workspace',
  38. path: '/workspace',
  39. component: '/dashboard/workspace/index',
  40. meta: {
  41. title: 'page.dashboard.workspace',
  42. },
  43. },
  44. ],
  45. },
  46. ];
  47. const MOCK_MENUS = [
  48. {
  49. menus: [...dashboardMenus],
  50. userId: 0,
  51. },
  52. {
  53. menus: [...dashboardMenus],
  54. userId: 1,
  55. },
  56. ];
  57. return MOCK_MENUS.find((item) => item.userId === userId)?.menus ?? [];
  58. }
  59. }