menu.ts 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. import { resultSuccess, resultError, getRequestToken, requestParams } from '../_util';
  2. import { MockMethod } from 'vite-plugin-mock';
  3. import { createFakeUserList } from './user';
  4. // single
  5. const dashboardRoute = {
  6. path: '/dashboard',
  7. name: 'Dashboard',
  8. component: 'LAYOUT',
  9. redirect: '/dashboard/analysis',
  10. meta: {
  11. title: 'routes.dashboard.dashboard',
  12. hideChildrenInMenu: true,
  13. icon: 'bx:bx-home',
  14. },
  15. children: [
  16. {
  17. path: 'analysis',
  18. name: 'Analysis',
  19. component: '/dashboard/analysis/index',
  20. meta: {
  21. hideMenu: true,
  22. hideBreadcrumb: true,
  23. title: 'routes.dashboard.analysis',
  24. currentActiveMenu: '/dashboard',
  25. icon: 'bx:bx-home',
  26. },
  27. },
  28. {
  29. path: 'workbench',
  30. name: 'Workbench',
  31. component: '/dashboard/workbench/index',
  32. meta: {
  33. hideMenu: true,
  34. hideBreadcrumb: true,
  35. title: 'routes.dashboard.workbench',
  36. currentActiveMenu: '/dashboard',
  37. icon: 'bx:bx-home',
  38. },
  39. },
  40. ],
  41. };
  42. const backRoute = {
  43. path: 'back',
  44. name: 'PermissionBackDemo',
  45. meta: {
  46. title: 'routes.demo.permission.back',
  47. },
  48. children: [
  49. {
  50. path: 'page',
  51. name: 'BackAuthPage',
  52. component: '/demo/permission/back/index',
  53. meta: {
  54. title: 'routes.demo.permission.backPage',
  55. },
  56. },
  57. {
  58. path: 'btn',
  59. name: 'BackAuthBtn',
  60. component: '/demo/permission/back/Btn',
  61. meta: {
  62. title: 'routes.demo.permission.backBtn',
  63. },
  64. },
  65. ],
  66. };
  67. const authRoute = {
  68. path: '/permission',
  69. name: 'Permission',
  70. component: 'LAYOUT',
  71. redirect: '/permission/front/page',
  72. meta: {
  73. icon: 'carbon:user-role',
  74. title: 'routes.demo.permission.permission',
  75. },
  76. children: [backRoute],
  77. };
  78. const levelRoute = {
  79. path: '/level',
  80. name: 'Level',
  81. component: 'LAYOUT',
  82. redirect: '/level/menu1/menu1-1',
  83. meta: {
  84. icon: 'carbon:user-role',
  85. title: 'routes.demo.level.level',
  86. },
  87. children: [
  88. {
  89. path: 'menu1',
  90. name: 'Menu1Demo',
  91. meta: {
  92. title: 'Menu1',
  93. },
  94. children: [
  95. {
  96. path: 'menu1-1',
  97. name: 'Menu11Demo',
  98. meta: {
  99. title: 'Menu1-1',
  100. },
  101. children: [
  102. {
  103. path: 'menu1-1-1',
  104. name: 'Menu111Demo',
  105. component: '/demo/level/Menu111',
  106. meta: {
  107. title: 'Menu111',
  108. },
  109. },
  110. ],
  111. },
  112. {
  113. path: 'menu1-2',
  114. name: 'Menu12Demo',
  115. component: '/demo/level/Menu12',
  116. meta: {
  117. title: 'Menu1-2',
  118. },
  119. },
  120. ],
  121. },
  122. {
  123. path: 'menu2',
  124. name: 'Menu2Demo',
  125. component: '/demo/level/Menu2',
  126. meta: {
  127. title: 'Menu2',
  128. },
  129. },
  130. ],
  131. };
  132. const sysRoute = {
  133. path: '/system',
  134. name: 'System',
  135. component: 'LAYOUT',
  136. redirect: '/system/account',
  137. meta: {
  138. icon: 'ion:settings-outline',
  139. title: 'routes.demo.system.moduleName',
  140. },
  141. children: [
  142. {
  143. path: 'account',
  144. name: 'AccountManagement',
  145. meta: {
  146. title: 'routes.demo.system.account',
  147. ignoreKeepAlive: true,
  148. },
  149. component: '/demo/system/account/index',
  150. },
  151. {
  152. path: 'account_detail/:id',
  153. name: 'AccountDetail',
  154. meta: {
  155. hideMenu: true,
  156. title: 'routes.demo.system.account_detail',
  157. ignoreKeepAlive: true,
  158. showMenu: false,
  159. currentActiveMenu: '/system/account',
  160. },
  161. component: '/demo/system/account/AccountDetail',
  162. },
  163. {
  164. path: 'role',
  165. name: 'RoleManagement',
  166. meta: {
  167. title: 'routes.demo.system.role',
  168. ignoreKeepAlive: true,
  169. },
  170. component: '/demo/system/role/index',
  171. },
  172. {
  173. path: 'menu',
  174. name: 'MenuManagement',
  175. meta: {
  176. title: 'routes.demo.system.menu',
  177. ignoreKeepAlive: true,
  178. },
  179. component: '/demo/system/menu/index',
  180. },
  181. {
  182. path: 'dept',
  183. name: 'DeptManagement',
  184. meta: {
  185. title: 'routes.demo.system.dept',
  186. ignoreKeepAlive: true,
  187. },
  188. component: '/demo/system/dept/index',
  189. },
  190. {
  191. path: 'changePassword',
  192. name: 'ChangePassword',
  193. meta: {
  194. title: 'routes.demo.system.password',
  195. ignoreKeepAlive: true,
  196. },
  197. component: '/demo/system/password/index',
  198. },
  199. ],
  200. };
  201. const linkRoute = {
  202. path: '/link',
  203. name: 'Link',
  204. component: 'LAYOUT',
  205. meta: {
  206. icon: 'ion:tv-outline',
  207. title: 'routes.demo.iframe.frame',
  208. },
  209. children: [
  210. {
  211. path: 'doc',
  212. name: 'Doc',
  213. meta: {
  214. title: 'routes.demo.iframe.doc',
  215. frameSrc: 'https://vvbin.cn/doc-next/',
  216. },
  217. },
  218. {
  219. path: 'https://vvbin.cn/doc-next/',
  220. name: 'DocExternal',
  221. component: 'LAYOUT',
  222. meta: {
  223. title: 'routes.demo.iframe.docExternal',
  224. },
  225. },
  226. ],
  227. };
  228. export default [
  229. {
  230. url: '/basic-api/getMenuList',
  231. timeout: 1000,
  232. method: 'get',
  233. response: (request: requestParams) => {
  234. const token = getRequestToken(request);
  235. if (!token) {
  236. return resultError('Invalid token!');
  237. }
  238. const checkUser = createFakeUserList().find((item) => item.token === token);
  239. if (!checkUser) {
  240. return resultError('Invalid user token!');
  241. }
  242. const id = checkUser.userId;
  243. let menu: Object[];
  244. switch (id) {
  245. case '1':
  246. dashboardRoute.redirect = dashboardRoute.path + '/' + dashboardRoute.children[0].path;
  247. menu = [dashboardRoute, authRoute, levelRoute, sysRoute, linkRoute];
  248. break;
  249. case '2':
  250. dashboardRoute.redirect = dashboardRoute.path + '/' + dashboardRoute.children[1].path;
  251. menu = [dashboardRoute, authRoute, levelRoute, linkRoute];
  252. break;
  253. default:
  254. menu = [];
  255. }
  256. return resultSuccess(menu);
  257. },
  258. },
  259. ] as MockMethod[];