A8000
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
3.9 KiB

8 months ago
8 months ago
8 months ago
  1. import { createRouter, createWebHistory } from 'vue-router'
  2. const routes = [
  3. {
  4. path: '/',
  5. redirect: '/index',
  6. },
  7. {
  8. path: '/index',
  9. component: () => import('@/pages/Index/Index.vue'),
  10. children: [
  11. {
  12. path: '/index',
  13. redirect: '/index/regular',
  14. },
  15. {
  16. path: 'regular', //常规
  17. component: () => import('@/pages/Index/Regular.vue'),
  18. children: [
  19. {
  20. path: '/index/regular',
  21. redirect: '/index/regular/consumables',
  22. },
  23. {
  24. path: 'consumables', //耗材,
  25. component: () => import('@/pages/Index/Regular/Consumables.vue'),
  26. },
  27. {
  28. path: 'test-tube', //试管,
  29. component: () => import('@/pages/Index/Regular/TestTube.vue'),
  30. },
  31. {
  32. path: 'running', //运行
  33. component: () => import('@/pages/Index/Regular/Running.vue'),
  34. },
  35. ],
  36. },
  37. {
  38. path: 'history',
  39. component: () => import('@/pages/Index/History.vue'),
  40. },
  41. {
  42. path: 'setting',
  43. component: () => import('@/pages/Index/Setting.vue'),
  44. meta: { requiresAuth: true, requiresAdmin: true }, // 需要登录和 Admin 权限
  45. children: [
  46. {
  47. path: '/index/setting',
  48. redirect: '/index/setting/device',
  49. },
  50. {
  51. path: 'device', //设备
  52. component: () => import('@/pages/Index/Settings/Device.vue'),
  53. },
  54. {
  55. path: 'users', //用户管理
  56. component: () => import('@/pages/Index/Settings/Users.vue'),
  57. },
  58. {
  59. path: 'version', //版本管理
  60. component: () => import('@/pages/Index/Settings/Version.vue'),
  61. },
  62. {
  63. path: 'lis', //LIS配置
  64. component: () => import('@/pages/Index/Settings/Lis.vue'),
  65. },
  66. ],
  67. },
  68. {
  69. path: 'emergency', //添加急诊页面
  70. component: () => import('@/pages/Index/Regular/Emergency.vue'),
  71. },
  72. {
  73. path: 'change-user', //编辑患者页面
  74. component: () => import('@/pages/Index/TestTube/ChangeUser.vue'),
  75. },
  76. ],
  77. },
  78. {
  79. path: '/login',
  80. component: () => import('@/pages/Login/Login.vue'),
  81. },
  82. //匹配任何找不到的路由,404兜底
  83. {
  84. path: '/notFound',
  85. component: () => import('@/pages/NotFound/NotFound.vue'),
  86. },
  87. ]
  88. const router = createRouter({
  89. history: createWebHistory(),
  90. routes,
  91. })
  92. function getCurrentUser() {
  93. const token = JSON.parse(sessionStorage.getItem('token')!)
  94. return token
  95. }
  96. // 路由守卫,检查本地 Token 是否存在
  97. // router.beforeEach((to, from, next) => {
  98. // console.log(from)
  99. // const token = sessionStorage.getItem('token')
  100. // if (!token && to.path !== '/login') {
  101. // next('/login') // 没有 token,重定向到登录页
  102. // } else if (token && to.path === '/login') {
  103. // next('/index') // 已有 token 且请求登录页,则跳转到主页
  104. // } else {
  105. // next() // 通过
  106. // }
  107. // })
  108. // 在 router/index.ts 中添加全局路由守卫
  109. // router.beforeEach((to, from, next) => {
  110. // console.log(from)
  111. // const user = getCurrentUser() // 获取当前用户
  112. // console.log(user)
  113. // // 判断目标路由是否需要权限检查
  114. // if (to.matched.some((record) => record.meta.requiresAuth)) {
  115. // // 如果没有登录,重定向到登录页面
  116. // if (!user) {
  117. // return next('/login') // 保存当前访问的路径,用于登录后重定向
  118. // }
  119. // // 判断是否需要 Admin 权限
  120. // if (
  121. // to.matched.some((record) => record.meta.requiresAdmin) &&
  122. // user.usrRole !== 'Admin'
  123. // ) {
  124. // return next({ path: '/notFound' }) // 权限不足,重定向到首页或者其他页面
  125. // }
  126. // }
  127. // // 如果没有问题,继续导航
  128. // next()
  129. // })
  130. export default router