index.ts 8.5 KB

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