_menu.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import { MockRequest, MockStatusError } from '@delon/mock';
  2. import { Menu } from '@delon/theme';
  3. import { deepCopy } from '@delon/util';
  4. const DATA: Menu[] = [
  5. {
  6. id: 1,
  7. parent_id: 0,
  8. text: '主导航',
  9. i18n: 'menu.main',
  10. group: true,
  11. hideInBreadcrumb: true,
  12. },
  13. {
  14. id: 2,
  15. parent_id: 1,
  16. text: '仪表盘',
  17. i18n: 'menu.dashboard',
  18. icon: 'dashboard',
  19. },
  20. {
  21. id: 3,
  22. parent_id: 2,
  23. text: '分析页',
  24. link: '/dashboard/analysis',
  25. i18n: 'menu.dashboard.analysis',
  26. },
  27. {
  28. id: 4,
  29. parent_id: 2,
  30. text: '监控页',
  31. link: '/dashboard/monitor',
  32. i18n: 'menu.dashboard.monitor',
  33. },
  34. {
  35. id: 5,
  36. parent_id: 2,
  37. text: '工作台',
  38. link: '/dashboard/workplace',
  39. i18n: 'menu.dashboard.workplace',
  40. },
  41. {
  42. id: 6,
  43. parent_id: 0,
  44. text: 'Pro',
  45. i18n: 'menu.pro',
  46. group: true,
  47. hideInBreadcrumb: true,
  48. },
  49. {
  50. id: 7,
  51. parent_id: 6,
  52. text: 'Form Page',
  53. i18n: 'menu.form',
  54. link: '/pro/form',
  55. icon: 'anticon anticon-edit',
  56. hideInBreadcrumb: true,
  57. },
  58. {
  59. id: 8,
  60. parent_id: 6,
  61. text: 'Basic Form',
  62. link: '/pro/form/basic-form',
  63. i18n: 'menu.form.basicform',
  64. shortcut: true,
  65. },
  66. {
  67. id: 9,
  68. parent_id: 6,
  69. text: 'Step Form',
  70. link: '/pro/form/step-form',
  71. i18n: 'menu.form.stepform',
  72. },
  73. ];
  74. function getIdx(id: number): number {
  75. id = +id;
  76. const idx = DATA.findIndex((w) => w.id === id);
  77. if (idx === -1) {
  78. throw new MockStatusError(404);
  79. }
  80. return idx;
  81. }
  82. export const MENUS = {
  83. '/menus': () => deepCopy(DATA),
  84. 'POST /menus': (req: MockRequest) => {
  85. const id = req.body.id || 0;
  86. if (id > 0) {
  87. const idx = getIdx(id);
  88. DATA[idx] = { ...DATA[idx], ...req.body };
  89. return { msg: 'ok', item: DATA[idx] };
  90. }
  91. const item = { ...req.body, id: DATA.sort((a, b) => b.id - a.id)[0].id + 1 };
  92. DATA.push(item);
  93. return { msg: 'ok', item };
  94. },
  95. 'DELETE /menus/:id': (req: MockRequest) => {
  96. const idx = getIdx(req.params.id || 0);
  97. DATA.splice(idx, 1);
  98. return { msg: 'ok' };
  99. },
  100. 'POST /menus/move': (req: MockRequest) => {
  101. const idx = getIdx(req.body.from || 0);
  102. DATA[idx].parent_id = req.body.to || 0;
  103. return { msg: 'ok', item: DATA[idx] };
  104. },
  105. };