menu.ts 6.0 KB

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