index.ts 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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: '/shipment/detail',
  46. name: 'Shipment Detail',
  47. component: () => import('../views/Tracking/src/components/TrackingDetail'),
  48. meta: {
  49. activeMenu: '/tracking'
  50. }
  51. },
  52. {
  53. path: '/tracking/add-vgm',
  54. name: 'Add VGM',
  55. component: () =>
  56. import('../views/Tracking/src/components/TrackingTable/src/components/VGMView.vue'),
  57. meta: {
  58. activeMenu: '/tracking'
  59. }
  60. },
  61. {
  62. path: '/public-tracking',
  63. name: 'Public Tracking',
  64. component: () => import('../views/Tracking/src/components/PublicTracking'),
  65. meta: {
  66. activeMenu: '/tracking'
  67. }
  68. },
  69. {
  70. path: '/public-tracking/detail',
  71. name: 'Public Tracking Detail',
  72. component: () =>
  73. import(
  74. '../views/Tracking/src/components/PublicTracking/src/components/PublicTrackingDetail.vue'
  75. ),
  76. meta: {
  77. activeMenu: '/tracking'
  78. }
  79. },
  80. {
  81. path: '/login',
  82. name: 'Login',
  83. component: () => import('../views/Login'),
  84. meta: {
  85. activeMenu: '/tracking'
  86. }
  87. },
  88. {
  89. path: '/reset-password',
  90. name: 'Reset Password',
  91. component: () => import('../views/Login/src/components/ChangePasswordCard.vue')
  92. },
  93. {
  94. path: '/Operationlog',
  95. name: 'Operationlog',
  96. component: () => import('../views/OperationLog')
  97. },
  98. {
  99. path: '/chat-log',
  100. name: 'Chat Log',
  101. component: () => import('../views/ChatLog')
  102. },
  103. {
  104. path: '/ai-api-log',
  105. name: 'AI API Log',
  106. component: () => import('../views/AIApiLog')
  107. },
  108. {
  109. path: '/PromptConfiguration',
  110. name: 'PromptConfiguration',
  111. component: () => import('../views/PromptConfiguration')
  112. },
  113. {
  114. path: '/system-message',
  115. name: 'System Message',
  116. component: () => import('../views/SystemMessage')
  117. },
  118. {
  119. path: '/system-message-detail',
  120. name: 'System Message Detail',
  121. meta: {
  122. breadName: 'Detail',
  123. activeMenu: '/system-message'
  124. },
  125. component: () => import('../views/SystemMessage/src/components/SystemMessageDetail.vue')
  126. },
  127. {
  128. path: '/SystemSettings',
  129. name: 'Monitoring Settings',
  130. component: () => import('../views/SystemSettings')
  131. },
  132. {
  133. path: '/SystemSettings',
  134. name: 'System Settings',
  135. component: () => import('../views/SystemSettings')
  136. },
  137. {
  138. path: '/SystemSettings/createnewrule',
  139. name: 'Create New Rule',
  140. component: () => import('../views/SystemSettings/src/components/CreateNewrule'),
  141. meta: {
  142. activeMenu: '/SystemSettings'
  143. }
  144. },
  145. {
  146. path: '/destination-delivery',
  147. name: 'Destination Delivery',
  148. component: () => import('../views/DestinationDelivery')
  149. },
  150. {
  151. path: '/destination-delivery/CreateNewBooking',
  152. name: 'Create New Booking',
  153. component: () => import('../views/DestinationDelivery/src/components/CreateNewBooking')
  154. },
  155. {
  156. path: '/destination-delivery/ConfiguRations',
  157. name: 'Configurations',
  158. component: () => import('../views/DestinationDelivery/src/components/ConfiguRations')
  159. },
  160. {
  161. path: '/destination-delivery/ConfiguRations/CreateNewRule',
  162. name: 'Destination Create New Rule',
  163. component: () => import('../views/DestinationDelivery/src/components/ConfiguRations/src/components/CreateNewRule.vue')
  164. },
  165. {
  166. path: '/destination-delivery/modify-booking',
  167. name: 'Modify Booking',
  168. component: () => import('../views/DestinationDelivery/src/components/ModifyBooking'),
  169. meta: {
  170. breadName: 'Modify Booking',
  171. activeMenu: '/destination-delivery'
  172. }
  173. }
  174. ]
  175. }
  176. ]
  177. })
  178. // * 路由拦截 beforeEach
  179. router.beforeEach(async (to, from, next) => {
  180. useBreadCrumb().setRouteList(to)
  181. const userStore = useUserStore()
  182. // 如果手动跳转登录页,清除登录信息
  183. if (to.path === '/login') {
  184. if (userStore.isLogin) {
  185. await userStore.logout()
  186. }
  187. sessionStorage.removeItem('trackingTablePageInfo')
  188. sessionStorage.removeItem('bookingTablePageInfo')
  189. }
  190. // 判断是否从systemMessage详情页跳转到systemMessage列表页,或者从systemMessage列表页跳转到systemMessage详情页
  191. if (
  192. !(
  193. from.name === 'System Message Detail' ||
  194. from.name === 'System Message' ||
  195. !from.name ||
  196. from.name === 'Tracking Detail'
  197. ) ||
  198. !(
  199. to.name === 'System Message' ||
  200. to.name === 'System Message Detail' ||
  201. to.name === 'Tracking Detail'
  202. )
  203. ) {
  204. sessionStorage.removeItem('activeCardTypeName')
  205. }
  206. // 未登录白名单
  207. const whiteList = ['/login', '/public-tracking', '/public-tracking/detail', '/reset-password']
  208. // 判断是否登录
  209. if (!whiteList.includes(to.path) && !userStore.isLogin) {
  210. const userStore = useUserStore()
  211. await userStore.logout()
  212. if (whiteList.includes(from.path)) {
  213. ElMessage.warning({
  214. message: 'Please log in to use this feature.',
  215. grouping: true
  216. })
  217. next(false)
  218. return
  219. } else {
  220. next('/login')
  221. }
  222. }
  223. next()
  224. })
  225. export default router