index.ts 8.0 KB

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