index.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import { createRouter, createWebHistory } from 'vue-router'
  2. import { defineAsyncComponent } from 'vue'
  3. // import Home from '@/views/Home.vue'
  4. // import HomeView from '@/views/HomeView.vue'
  5. //路由异步加载
  6. //主页框架
  7. const Home = () => import('@/views/Home.vue')
  8. //首页详细内容
  9. const HomeView = () => import('@/views/HomeView.vue')
  10. //科普内容
  11. const PopularizationScience = () => import('@/views/PopularizationScience.vue')
  12. const Community = () => import('@/views/Community.vue')
  13. // 组件异步懒加载方法
  14. // const _import = (path: string) =>
  15. // defineAsyncComponent(() => import(`../views/${path}.vue`))
  16. const routes = [
  17. {
  18. path: '/',
  19. name: 'home',
  20. // component: Home,
  21. component: Home,
  22. redirect: "/homeView",
  23. children: [{
  24. path: 'homeView',
  25. name: 'homeView',
  26. component: HomeView
  27. // component: _import('HomeView')
  28. },
  29. {
  30. path: 'popularizationScience',
  31. name: 'popularizationScience',
  32. component: PopularizationScience
  33. },
  34. {
  35. path: 'community',
  36. name: 'community',
  37. component: () => import('@/views/Community.vue')
  38. }, {
  39. path: 'plan',
  40. name: 'plan',
  41. component: () => import('@/views/Plan.vue')
  42. }, {
  43. path: 'testRecord',
  44. name: 'testRecord',
  45. component: () => import('@/views/TestRecord.vue')
  46. }, {
  47. path: 'report/:planId/:flag/:name',
  48. name: 'report',
  49. component: () => import('@/views/Report.vue')
  50. },
  51. {
  52. path: 'login',
  53. name: 'login',
  54. component: () => import('@/views/Login.vue')
  55. },
  56. {
  57. path: 'updatePas',
  58. name: 'updatePas',
  59. component: () => import('@/views/UpdatePas.vue')
  60. },
  61. {
  62. path: 'register',
  63. name: 'register',
  64. component: () => import('@/views/Register.vue')
  65. },
  66. {
  67. path: 'scale/:planId/:planName/:flag/:flagName/:isComplate',
  68. name: 'scale',
  69. component: () => import('@/views/Scale.vue')
  70. },
  71. //量表或认知任务详情页
  72. {
  73. path: 'scaleDetail/:planId/:planName/:flag/:type',
  74. name: 'scaleDetail',
  75. component: () => import('@/views/ScaleDetail.vue')
  76. },
  77. {
  78. path: 'scaleMid/:planId/:planName/:flag/:flagName/:num',
  79. name: 'scaleMid',
  80. component: () => import('@/views/ScaleMid.vue')//量表中间件
  81. },
  82. //认知任务
  83. {
  84. path: 'cognize/:planId/:planName/:flag/:type',
  85. name: 'cognize',
  86. component: () => import('@/views/Cognize.vue')
  87. }
  88. ]
  89. // component: HomeView
  90. },
  91. {
  92. path: '/cognizeGoNoGo/:currentType/:planId/:planName/:flag/:flagName/:num',
  93. name: 'cognizeGoNoGo',
  94. component: () => import('@/views/CognizeGoNoGo.vue')
  95. }, {
  96. path: '/cognizeFaceDot/:planId/:planName/:flag/:flagName/:formalTest',
  97. name: 'cognizeFaceDot',
  98. component: () => import('@/views/CognizeFaceDot.vue')
  99. }, {
  100. path: '/shapeIntuition_random/:planId/:planName/:flag/:flagName:/:formalTest',
  101. name: 'shapeIntuitionRandom',
  102. component: () => import('@/views/shapeIntuition_random.vue')
  103. },
  104. {
  105. path: '/ETBexperiment_new/:planId/:planName/:flag/:flagName:/:formalTest',
  106. name: 'ETBexperimentNew',
  107. component: () => import('@/views/ETBexperiment_new.vue')
  108. },
  109. {
  110. path: '/Stroop/:planId/:planName/:flag/:flagName:/:formalTest',
  111. name: 'Stroop',
  112. component: () => import('@/views/Stroop.vue')
  113. }
  114. ]
  115. const router = createRouter({
  116. // history: createWebHistory(import.meta.env.BASE_URL),
  117. history: createWebHistory("/highLevelIntellectual/"),
  118. //highLevelIntellectual
  119. // history: createWebHistory('/pc/'),
  120. routes
  121. })
  122. //页面滚动到最顶部
  123. router.beforeEach((to, from, next) => {
  124. window.scrollTo(0, 0);
  125. /** meta是定义路由时路由的属性 */
  126. if (to.meta.title) {
  127. (document as any).title = to.meta.title;
  128. }
  129. next();
  130. });
  131. export default router