route.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import { RouteRecordRaw } from 'vue-router';
  2. import { Session } from '/@/utils/storage';
  3. /**
  4. * 路由meta对象参数说明
  5. * meta: {
  6. * title: 菜单栏及 tagsView 栏、菜单搜索名称(国际化)
  7. * isLink: 是否超链接菜单,开启外链条件,`1、isLink: 链接地址不为空`
  8. * isHide: 是否隐藏此路由
  9. * isKeepAlive: 是否缓存组件状态
  10. * isAffix: 是否固定在 tagsView 栏上
  11. * isIframe: 是否内嵌窗口,开启条件,`1、isIframe:true 2、isLink:链接地址不为空`
  12. * roles: 当前路由权限标识,取角色管理。控制路由显示、隐藏。超级管理员:admin 普通角色:common
  13. * icon: 菜单、tagsView 图标,阿里:加 `iconfont xxx`,fontawesome:加 `fa xxx`
  14. * }
  15. */
  16. /**
  17. * 定义动态路由
  18. * 前端添加路由,请在顶级节点的 `children 数组` 里添加
  19. * @description 未开启 isRequestRoutes 为 true 时使用(前端控制路由),开启时第一个顶级 children 的路由将被替换成接口请求回来的路由数据
  20. * @description 各字段请查看 `/@/views/system/menu/component/addMenu.vue 下的 ruleForm`
  21. * @returns 返回路由菜单数据
  22. */
  23. function getDynamicRoutes(): Array<RouteRecordRaw> {
  24. // 获取用户信息
  25. const userInfo = Session.get('userInfo');
  26. // 如果用户名是 platform_admin,返回空数组(不显示任何路由)
  27. if (userInfo && userInfo.username === 'platform_admin') {
  28. return [];
  29. }
  30. // 正常情况下返回标准路由配置
  31. return [
  32. {
  33. path: '/',
  34. name: '/',
  35. component: () => import('/@/layout/index.vue'),
  36. redirect: '/home',
  37. meta: {
  38. isKeepAlive: true,
  39. },
  40. children: [],
  41. }
  42. ];
  43. }
  44. export const dynamicRoutes: Array<RouteRecordRaw> = getDynamicRoutes();
  45. /**
  46. * 定义404、401界面
  47. * @link 参考:https://next.router.vuejs.org/zh/guide/essentials/history-mode.html#netlify
  48. */
  49. export const notFoundAndNoPower = [
  50. {
  51. path: '/:path(.*)*',
  52. name: 'notFound',
  53. component: () => import('/@/views/system/error/404.vue'),
  54. meta: {
  55. title: 'message.staticRoutes.notFound',
  56. isHide: true,
  57. },
  58. },
  59. {
  60. path: '/401',
  61. name: 'noPower',
  62. component: () => import('/@/views/system/error/401.vue'),
  63. meta: {
  64. title: 'message.staticRoutes.noPower',
  65. isHide: true,
  66. },
  67. },
  68. ];
  69. /**
  70. * 定义静态路由(默认路由)
  71. * 此路由不要动,前端添加路由的话,请在 `dynamicRoutes 数组` 中添加
  72. * @description 前端控制直接改 dynamicRoutes 中的路由,后端控制不需要修改,请求接口路由数据时,会覆盖 dynamicRoutes 第一个顶级 children 的内容(全屏,不包含 layout 中的路由出口)
  73. * @returns 返回路由菜单数据
  74. */
  75. export const staticRoutes: Array<RouteRecordRaw> = [
  76. {
  77. path: '/login',
  78. name: 'login',
  79. component: () => import('/@/views/system/login/index.vue'),
  80. meta: {
  81. title: '登录',
  82. },
  83. },
  84. {
  85. path: '/superlogin',
  86. name: 'superlogin',
  87. component: () => import('/@/views/system/login/superIndex.vue'),
  88. meta: {
  89. title: '登录',
  90. },
  91. },
  92. {
  93. path: '/demo',
  94. name: 'demo',
  95. component: () => import('/@/views/system/demo/index.vue'),
  96. meta: {
  97. title: 'message.router.personal'
  98. },
  99. }
  100. ];