index.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import { createRouter, createWebHistory } from 'vue-router'
  2. import { useUserStore } from '@/stores/modules/user'
  3. const router = createRouter({
  4. history: createWebHistory(`/new/`),
  5. routes: [
  6. {
  7. path: '/',
  8. name: 'Home',
  9. redirect: '/dashboard',
  10. component: () => import('../views/Layout'),
  11. children: [
  12. {
  13. path: '/dashboard',
  14. name: 'Dashboard',
  15. component: () => import('../views/Dashboard')
  16. },
  17. {
  18. path: '/booking',
  19. name: 'Booking',
  20. component: () => import('../views/Booking')
  21. },
  22. {
  23. path: '/booking/detail',
  24. name: 'Booking Detail',
  25. component: () => import('../views/Booking/src/components/BookingDetail'),
  26. meta: {
  27. activeMenu: '/booking'
  28. }
  29. },
  30. {
  31. path: '/tracking',
  32. name: 'Tracking',
  33. component: () => import('../views/Tracking')
  34. },
  35. {
  36. path: '/tracking/detail',
  37. name: 'Tracking Detail',
  38. component: () => import('../views/Tracking/src/components/TrackingDetail'),
  39. meta: {
  40. activeMenu: '/tracking'
  41. }
  42. },
  43. {
  44. path: '/tracking/add-vgm',
  45. name: 'Add VGM',
  46. component: () =>
  47. import('../views/Tracking/src/components/TrackingTable/src/components/VGMView.vue'),
  48. meta: {
  49. activeMenu: '/tracking'
  50. }
  51. },
  52. {
  53. path: '/public-tracking',
  54. name: 'Public Tracking',
  55. component: () => import('../views/Tracking/src/components/PublicTracking'),
  56. meta: {
  57. activeMenu: '/tracking'
  58. }
  59. },
  60. {
  61. path: '/public-tracking/detail',
  62. name: 'Public Tracking Detail',
  63. component: () =>
  64. import(
  65. '../views/Tracking/src/components/PublicTracking/src/components/PublicTrackingDetail.vue'
  66. ),
  67. meta: {
  68. activeMenu: '/tracking'
  69. }
  70. },
  71. {
  72. path: '/login',
  73. name: 'Login',
  74. component: () => import('../views/Login'),
  75. meta: {
  76. activeMenu: '/tracking'
  77. }
  78. },
  79. {
  80. path: '/reset-password',
  81. name: 'Reset Password',
  82. component: () => import('../views/Login/src/components/ChangePasswordCard.vue')
  83. },
  84. {
  85. path: '/Operationlog',
  86. name: 'Operationlog',
  87. component: () => import('../views/OperationLog')
  88. }
  89. ]
  90. }
  91. ]
  92. })
  93. // * 路由拦截 beforeEach
  94. router.beforeEach(async (to, from, next) => {
  95. // 未登录白名单
  96. const whiteList = ['/login', '/public-tracking', '/public-tracking/detail', '/reset-password']
  97. // 判断是否登录
  98. if (!whiteList.includes(to.path) && !localStorage.getItem('username')) {
  99. const userStore = useUserStore()
  100. userStore.clearUsername()
  101. if (whiteList.includes(from.path)) {
  102. ElMessage.warning('Please log in to use this feature.')
  103. next(false)
  104. return
  105. } else {
  106. next('/public-tracking')
  107. }
  108. }
  109. if (to.path === '/Login') {
  110. const userStore = useUserStore()
  111. userStore.clearUsername()
  112. }
  113. next()
  114. })
  115. export default router