index.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import { createRouter, createWebHistory } from 'vue-router'
  2. import { useUserStore } from '@/stores/modules/user'
  3. import { useBreadCrumb } from '@/stores/modules/breadCrumb'
  4. const router = createRouter({
  5. history: createWebHistory(`${import.meta.env.VITE_BASE_URL}`),
  6. routes: [
  7. {
  8. path: '/',
  9. name: 'Home',
  10. redirect: '/dashboard',
  11. component: () => import('../views/Layout'),
  12. children: [
  13. {
  14. path: '/dashboard',
  15. name: 'Dashboard',
  16. component: () => import('../views/Dashboard')
  17. },
  18. {
  19. path: '/booking',
  20. name: 'Booking',
  21. component: () => import('../views/Booking')
  22. },
  23. {
  24. path: '/booking/detail',
  25. name: 'Booking Detail',
  26. component: () => import('../views/Booking/src/components/BookingDetail'),
  27. meta: {
  28. activeMenu: '/booking'
  29. }
  30. },
  31. {
  32. path: '/tracking',
  33. name: 'Tracking',
  34. component: () => import('../views/Tracking')
  35. },
  36. {
  37. path: '/tracking/detail',
  38. name: 'Tracking Detail',
  39. component: () => import('../views/Tracking/src/components/TrackingDetail'),
  40. meta: {
  41. activeMenu: '/tracking'
  42. }
  43. },
  44. {
  45. path: '/tracking/add-vgm',
  46. name: 'Add VGM',
  47. component: () =>
  48. import('../views/Tracking/src/components/TrackingTable/src/components/VGMView.vue'),
  49. meta: {
  50. activeMenu: '/tracking'
  51. }
  52. },
  53. {
  54. path: '/public-tracking',
  55. name: 'Public Tracking',
  56. component: () => import('../views/Tracking/src/components/PublicTracking'),
  57. meta: {
  58. activeMenu: '/tracking'
  59. }
  60. },
  61. {
  62. path: '/public-tracking/detail',
  63. name: 'Public Tracking Detail',
  64. component: () =>
  65. import(
  66. '../views/Tracking/src/components/PublicTracking/src/components/PublicTrackingDetail.vue'
  67. ),
  68. meta: {
  69. activeMenu: '/tracking'
  70. }
  71. },
  72. {
  73. path: '/login',
  74. name: 'Login',
  75. component: () => import('../views/Login'),
  76. meta: {
  77. activeMenu: '/tracking'
  78. }
  79. },
  80. {
  81. path: '/reset-password',
  82. name: 'Reset Password',
  83. component: () => import('../views/Login/src/components/ChangePasswordCard.vue')
  84. },
  85. {
  86. path: '/Operationlog',
  87. name: 'Operationlog',
  88. component: () => import('../views/OperationLog')
  89. },
  90. {
  91. path: '/system-message',
  92. name: 'System Message',
  93. component: () => import('../views/SystemMessage')
  94. },
  95. {
  96. path: '/system-message-detail',
  97. name: 'System Message Detail',
  98. meta: {
  99. breadName: 'Detail'
  100. },
  101. component: () => import('../views/SystemMessage/src/components/SystemMessageDetail.vue')
  102. },
  103. {
  104. path: '/SystemSettings',
  105. name: 'Monitoring Settings',
  106. component: () => import('../views/SystemSettings')
  107. },
  108. {
  109. path: '/SystemSettings/createnewrule',
  110. name: 'Create New Rule',
  111. component: () => import('../views/SystemSettings/src/components/CreateNewrule'),
  112. meta: {
  113. activeMenu: '/SystemSettings'
  114. }
  115. }
  116. ]
  117. }
  118. ]
  119. })
  120. // * 路由拦截 beforeEach
  121. router.beforeEach(async (to, from, next) => {
  122. useBreadCrumb().setRouteList(to)
  123. const userStore = useUserStore()
  124. // 如果手动跳转登录页,清除登录信息
  125. if (to.path === '/login') {
  126. if (userStore.userInfo?.uname) {
  127. await userStore.logout()
  128. }
  129. sessionStorage.removeItem('trackingTablePageInfo')
  130. sessionStorage.removeItem('bookingTablePageInfo')
  131. }
  132. // 未登录白名单
  133. const whiteList = ['/login', '/public-tracking', '/public-tracking/detail', '/reset-password']
  134. // 判断是否登录
  135. if (!whiteList.includes(to.path) && !userStore.userInfo?.uname) {
  136. const userStore = useUserStore()
  137. await userStore.logout()
  138. if (whiteList.includes(from.path)) {
  139. ElMessage.warning({
  140. message: 'Please log in to use this feature.',
  141. grouping: true
  142. })
  143. next(false)
  144. return
  145. } else {
  146. next('/login')
  147. }
  148. }
  149. next()
  150. })
  151. export default router