index.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import { createRouter, createWebHistory } from 'vue-router'
  2. import Temp404 from '@/views/global/temp/404.vue'
  3. import RouterView from '@/layout/router-view.vue'
  4. // @ts-ignore
  5. import Layout from '@/layout/index.vue'
  6. import { useMenuStore } from '@/stores'
  7. const routes = [
  8. { path: '/:pathMatch(.*)*', name: 'NotFound', component: Temp404 },
  9. {
  10. name: 'root',
  11. path: '/',
  12. component: Layout,
  13. redirect: '/home',
  14. children: [],
  15. },
  16. {
  17. name: 'home',
  18. path: '/home',
  19. component: () => import('@/views/study/home/index.vue'),
  20. meta: {
  21. isMenu: true,
  22. title: '首页',
  23. fa: 'fa-home',
  24. },
  25. },
  26. {
  27. name: 'chinese',
  28. path: '/chinese',
  29. component: () => import('@/views/study/chinese/index.vue'),
  30. meta: {
  31. isMenu: true,
  32. title: '语文',
  33. fa: 'fa-book',
  34. },
  35. },
  36. {
  37. name: 'chinese-question',
  38. path: '/chinese-question',
  39. component: () => import('@/views/study/chinese/question/index.vue'),
  40. meta: {
  41. root: 'chinese',
  42. title: '语文题目',
  43. },
  44. },
  45. {
  46. name: 'chinese-question-only',
  47. path: '/chinese-question-only',
  48. component: () => import('@/views/study/chinese/question/only.vue'),
  49. meta: {
  50. root: 'chinese',
  51. title: '语文题目',
  52. },
  53. },
  54. {
  55. name: 'math',
  56. path: '/math',
  57. component: () => import('@/views/study/chinese/index.vue'),
  58. meta: {
  59. isMenu: true,
  60. title: '数学',
  61. fa: 'fa-calculator',
  62. },
  63. },
  64. {
  65. name: 'english',
  66. path: '/english',
  67. component: () => import('@/views/study/chinese/index.vue'),
  68. meta: {
  69. isMenu: true,
  70. title: '英语',
  71. fa: 'fa-language',
  72. },
  73. },
  74. ]
  75. const router = createRouter({
  76. // @ts-ignore
  77. history: createWebHistory(import.meta.env.BASE_URL),
  78. routes,
  79. })
  80. router.beforeEach((to, from, next) => {
  81. next()
  82. document.getElementById('loader').style.display = 'none'
  83. })
  84. export const initRoutes = () => {
  85. const MenuStore = useMenuStore()
  86. return new Promise((resolve, reject) => {
  87. setTimeout(() => {
  88. MenuStore.initRoutes(MenuStore.mockApi)
  89. resolve(null)
  90. }, 2000)
  91. })
  92. }
  93. export default router