index.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
  2. import { sessionStorage } from '@/plugins/storage'
  3. import Bootstrap from './/bootstrap'
  4. import AnalysisRoutes from './analysis'
  5. import MonitorRoutes from './monitor'
  6. import MarkingRoutes from './marking'
  7. import ExampleRoutes from './example'
  8. import ExpertRoutes from './expert'
  9. import QualityRoutes from './quality'
  10. import AdminRoutes from './admin'
  11. import useMainStore from '@/store/main'
  12. export const routes: RouteRecordRaw[] = [
  13. ...Bootstrap,
  14. ...AnalysisRoutes,
  15. ...MonitorRoutes,
  16. ...MarkingRoutes,
  17. ...ExpertRoutes,
  18. ...QualityRoutes,
  19. ...AdminRoutes,
  20. {
  21. name: 'Error',
  22. path: '/:path(.*)*',
  23. component: () => import('@/modules/error/404.vue'),
  24. },
  25. ]
  26. if (import.meta.env.DEV) {
  27. routes.unshift(...ExampleRoutes)
  28. }
  29. const router = createRouter({
  30. history: createWebHistory('/'),
  31. routes: routes,
  32. })
  33. const pageJumpsMap: any = {
  34. SubjectManage: ['StructManage'],
  35. StructManage: ['EditStruct'],
  36. // ExamManage: ['EditExam'],
  37. AnalysisStatistics: ['AnalysisViewMarked'],
  38. AnalysisPersonnelStatistics: ['MarkingAssess', 'AnalysisPersonnelStatisticsMarker'],
  39. AnalysisGroupMonitoring: ['AnalysisGroupDetail'],
  40. MarkingInquiry: ['MarkingInquiryResult'],
  41. QualitySelfCheck: ['QualitySelfCheckDetail'],
  42. }
  43. const keepAliveJupms = (from: any, to: any) => {
  44. const mStore = useMainStore()
  45. if (from.name in pageJumpsMap) {
  46. if (pageJumpsMap[from.name].includes(to.name)) {
  47. mStore.setKeepAliveViews(from.name)
  48. } else {
  49. mStore.cutKeepAliveViews(from.name)
  50. }
  51. }
  52. }
  53. router.beforeEach(async (to, from, next) => {
  54. keepAliveJupms(from, to)
  55. const mainStore = useMainStore()
  56. if (to.name === 'Login') {
  57. mainStore.setLockScreen(false)
  58. }
  59. if (
  60. !mainStore.myUserInfo &&
  61. sessionStorage.get('LOGIN_RESULT') &&
  62. !['Login', 'CheckExam', 'InitCreateExam', 'InitUserName'].includes(String(to.name))
  63. ) {
  64. await mainStore.getMyUserInfo()
  65. }
  66. if (
  67. sessionStorage.get('LOGIN_RESULT') &&
  68. !['Bootstrap', 'Login', 'InitUserName', 'CheckExam', 'InitCreateExam', 'ChangePassword'].includes(
  69. to.name?.toString() || ''
  70. ) &&
  71. mainStore.myUserInfo?.passwordWeak
  72. ) {
  73. console.log('to:', to)
  74. next({ name: 'ChangePassword', query: { redirectPath: encodeURIComponent(to.fullPath) } })
  75. } else if (to.meta?.auth === false || to.name === 'Login' || sessionStorage.get('LOGIN_RESULT')) {
  76. next()
  77. } else {
  78. // next({ name: 'Login' })
  79. next()
  80. }
  81. })
  82. export default router