index.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import Vue from 'vue'
  2. import VueRouter from 'vue-router'
  3. import Layout from '@/views/Layout.vue'
  4. Vue.use(VueRouter)
  5. const routes = [
  6. {
  7. path: '/login',
  8. name: 'Login',
  9. component: () => import('@/views/Login.vue')
  10. },
  11. {
  12. path: '/',
  13. component: Layout,
  14. redirect: '/dashboard',
  15. children: [
  16. {
  17. path: 'dashboard',
  18. name: 'Dashboard',
  19. component: () => import('@/views/Dashboard.vue'),
  20. meta: { title: '首页' }
  21. },
  22. {
  23. path: 'users',
  24. name: 'Users',
  25. component: () => import('@/views/Users.vue'),
  26. meta: { title: '用户管理' }
  27. },
  28. {
  29. path: 'families',
  30. name: 'Families',
  31. component: () => import('@/views/Families.vue'),
  32. meta: { title: '家庭管理' }
  33. },
  34. {
  35. path: 'children',
  36. name: 'Children',
  37. component: () => import('@/views/Children.vue'),
  38. meta: { title: '孩子管理' }
  39. },
  40. {
  41. path: 'tasks',
  42. name: 'Tasks',
  43. component: () => import('@/views/Tasks.vue'),
  44. meta: { title: '任务管理' }
  45. },
  46. {
  47. path: 'task-templates',
  48. name: 'TaskTemplates',
  49. component: () => import('@/views/TaskTemplates.vue'),
  50. meta: { title: '任务模板' }
  51. },
  52. {
  53. path: 'rewards',
  54. name: 'Rewards',
  55. component: () => import('@/views/Rewards.vue'),
  56. meta: { title: '奖励管理' }
  57. },
  58. {
  59. path: 'points',
  60. name: 'Points',
  61. component: () => import('@/views/Points.vue'),
  62. meta: { title: '积分管理' }
  63. },
  64. {
  65. path: 'package-audit',
  66. name: 'PackageAudit',
  67. component: () => import('@/views/PackageAudit.vue'),
  68. meta: { title: '套餐审核' }
  69. },
  70. {
  71. path: 'guide-packages',
  72. name: 'GuidePackages',
  73. component: () => import('@/views/GuidePackages.vue'),
  74. meta: { title: '指导师套餐' }
  75. }
  76. ]
  77. }
  78. ]
  79. const router = new VueRouter({
  80. mode: 'history',
  81. base: process.env.BASE_URL,
  82. routes
  83. })
  84. router.beforeEach((to, from, next) => {\n const token = localStorage.getItem('token')\n const role = localStorage.getItem('role')\n // authentication check\n if (to.path !== '/login' && !token) {\n return next('/login')\n }\n // teacher role protection for /guide* routes\n if (to.path.startsWith('/guide') && role !== 'teacher') {\n return next({ path: '/', replace: true })\n }\n return next()\n})
  85. export default router