index.ts 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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: '/template-management',
  115. name: 'Template Management',
  116. component: () => import('../views/TemplateManagement')
  117. },
  118. {
  119. path: '/create-report-template',
  120. name: 'Create Report Template',
  121. component: () => import('../views/TemplateManagement/src/components/CreateReportTemplate')
  122. },
  123. {
  124. path: '/system-message',
  125. name: 'System Message',
  126. component: () => import('../views/SystemMessage')
  127. },
  128. {
  129. path: '/system-message-detail',
  130. name: 'System Message Detail',
  131. meta: {
  132. breadName: 'Detail',
  133. activeMenu: '/system-message'
  134. },
  135. component: () => import('../views/SystemMessage/src/components/SystemMessageDetail.vue')
  136. },
  137. {
  138. path: '/SystemSettings',
  139. name: 'Monitoring Settings',
  140. component: () => import('../views/SystemSettings')
  141. },
  142. {
  143. path: '/SystemSettings',
  144. name: 'System Settings',
  145. component: () => import('../views/SystemSettings')
  146. },
  147. {
  148. path: '/SystemSettings/createnewrule',
  149. name: 'Create New Rule',
  150. component: () => import('../views/SystemSettings/src/components/CreateNewrule'),
  151. meta: {
  152. activeMenu: '/SystemSettings'
  153. }
  154. },
  155. {
  156. path: '/destination-delivery',
  157. name: 'Destination Delivery',
  158. component: () => import('../views/DestinationDelivery')
  159. },
  160. {
  161. path: '/destination-delivery/CreateNewBooking',
  162. name: 'Create New Booking',
  163. component: () => import('../views/DestinationDelivery/src/components/CreateNewBooking')
  164. },
  165. {
  166. path: '/destination-delivery/ConfiguRations',
  167. name: 'Configurations',
  168. component: () => import('../views/DestinationDelivery/src/components/ConfiguRations')
  169. },
  170. {
  171. path: '/destination-delivery/ConfiguRations/CreateNewRule',
  172. name: 'Destination Create New Rule',
  173. component: () => import('../views/DestinationDelivery/src/components/ConfiguRations/src/components/CreateNewRule.vue')
  174. },
  175. {
  176. path: '/destination-delivery/modify-booking',
  177. name: 'Modify Booking',
  178. component: () => import('../views/DestinationDelivery/src/components/ModifyBooking'),
  179. meta: {
  180. breadName: 'Modify Booking',
  181. activeMenu: '/destination-delivery'
  182. }
  183. }
  184. ]
  185. }
  186. ]
  187. })
  188. // * 路由拦截 beforeEach
  189. router.beforeEach(async (to, from, next) => {
  190. useBreadCrumb().setRouteList(to)
  191. const userStore = useUserStore()
  192. // 如果手动跳转登录页,清除登录信息
  193. if (to.path === '/login') {
  194. if (userStore.isLogin) {
  195. await userStore.logout()
  196. }
  197. sessionStorage.removeItem('trackingTablePageInfo')
  198. sessionStorage.removeItem('bookingTablePageInfo')
  199. }
  200. // 判断是否从systemMessage详情页跳转到systemMessage列表页,或者从systemMessage列表页跳转到systemMessage详情页
  201. if (
  202. !(
  203. from.name === 'System Message Detail' ||
  204. from.name === 'System Message' ||
  205. !from.name ||
  206. from.name === 'Tracking Detail'
  207. ) ||
  208. !(
  209. to.name === 'System Message' ||
  210. to.name === 'System Message Detail' ||
  211. to.name === 'Tracking Detail'
  212. )
  213. ) {
  214. sessionStorage.removeItem('activeCardTypeName')
  215. }
  216. // 未登录白名单
  217. const whiteList = ['/login', '/public-tracking', '/public-tracking/detail', '/reset-password']
  218. // 判断是否登录
  219. if (!whiteList.includes(to.path) && !userStore.isLogin) {
  220. const userStore = useUserStore()
  221. await userStore.logout()
  222. if (whiteList.includes(from.path)) {
  223. ElMessage.warning({
  224. message: 'Please log in to use this feature.',
  225. grouping: true
  226. })
  227. next(false)
  228. return
  229. } else {
  230. next('/login')
  231. }
  232. }
  233. next()
  234. })
  235. export default router