index.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. import Vue from 'vue'
  2. import VueRouter from 'vue-router'
  3. import Layout from '@/views/Layout.vue'
  4. import { isAllowed, defaultPath } from '@/config/menu-roles.js'
  5. Vue.use(VueRouter)
  6. const routes = [
  7. {
  8. path: '/login',
  9. name: 'Login',
  10. component: () => import('@/views/Login.vue'),
  11. meta: { title: '登录' }
  12. },
  13. {
  14. path: '/screen',
  15. name: 'Screen',
  16. component: () => import('@/views/Screen.vue'),
  17. meta: { title: '课程现场投屏' }
  18. },
  19. {
  20. path: '/',
  21. component: Layout,
  22. redirect: '/dashboard',
  23. children: [
  24. {
  25. path: 'dashboard',
  26. name: 'Dashboard',
  27. component: () => import('@/views/Dashboard.vue'),
  28. meta: { title: '概览' }
  29. },
  30. {
  31. path: 'courses',
  32. name: 'Courses',
  33. component: () => import('@/views/Courses.vue'),
  34. meta: { title: '课程管理' }
  35. },
  36. {
  37. path: 'modules',
  38. name: 'Modules',
  39. component: () => import('@/views/Modules.vue'),
  40. meta: { title: '模块管理' }
  41. },
  42. {
  43. path: 'classes',
  44. name: 'Classes',
  45. component: () => import('@/views/Classes.vue'),
  46. meta: { title: '班级管理' }
  47. },
  48. {
  49. path: 'salons',
  50. name: 'Salons',
  51. component: () => import('@/views/Salons.vue'),
  52. meta: { title: '沙龙管理' }
  53. },
  54. {
  55. path: 'members',
  56. name: 'Members',
  57. component: () => import('@/views/Members.vue'),
  58. meta: { title: '会员台账' }
  59. },
  60. {
  61. path: 'enrollments',
  62. name: 'Enrollments',
  63. component: () => import('@/views/Enrollments.vue'),
  64. meta: { title: '报名管理' }
  65. },
  66. {
  67. path: 'orders',
  68. name: 'Orders',
  69. component: () => import('@/views/Orders.vue'),
  70. meta: { title: '订单管理' }
  71. },
  72. {
  73. path: 'group-orders',
  74. name: 'GroupOrders',
  75. component: () => import('@/views/GroupOrders.vue'),
  76. meta: { title: '团报管理' }
  77. },
  78. {
  79. path: 'cases',
  80. name: 'Cases',
  81. component: () => import('@/views/Cases.vue'),
  82. meta: { title: '案例管理' }
  83. },
  84. {
  85. path: 'groups',
  86. name: 'Groups',
  87. component: () => import('@/views/Groups.vue'),
  88. meta: { title: '分组管理' }
  89. },
  90. {
  91. path: 'invites',
  92. name: 'Invites',
  93. component: () => import('@/views/Invites.vue'),
  94. meta: { title: '转介绍漏斗' }
  95. },
  96. {
  97. path: 'materials',
  98. name: 'Materials',
  99. component: () => import('@/views/Materials.vue'),
  100. meta: { title: '课前资料' }
  101. },
  102. {
  103. path: 'users',
  104. name: 'Users',
  105. component: () => import('@/views/Users.vue'),
  106. meta: { title: '学员管理' }
  107. },
  108. {
  109. path: 'review/submissions',
  110. name: 'Submissions',
  111. component: () => import('@/views/Submissions.vue'),
  112. meta: { title: '成果审核' }
  113. },
  114. {
  115. path: 'review/cards',
  116. name: 'Cards',
  117. component: () => import('@/views/Cards.vue'),
  118. meta: { title: '教学卡评分' }
  119. },
  120. {
  121. path: 'review/roadmaps',
  122. name: 'Roadmaps',
  123. component: () => import('@/views/Roadmaps.vue'),
  124. meta: { title: '路演评审' }
  125. },
  126. {
  127. path: 'scoreboard',
  128. name: 'Scoreboard',
  129. component: () => import('@/views/Scoreboard.vue'),
  130. meta: { title: '积分榜' }
  131. },
  132. {
  133. path: 'manual-score',
  134. name: 'ManualScore',
  135. component: () => import('@/views/ManualScore.vue'),
  136. meta: { title: '人工加减分' }
  137. },
  138. {
  139. path: 'stats',
  140. name: 'Stats',
  141. component: () => import('@/views/Stats.vue'),
  142. meta: { title: '统计' }
  143. }
  144. ]
  145. }
  146. ]
  147. const router = new VueRouter({
  148. mode: 'history',
  149. base: process.env.BASE_URL,
  150. routes
  151. })
  152. router.beforeEach(function (to, from, next) {
  153. document.title = (to.meta && to.meta.title ? to.meta.title + ' - ' : '') + '爱伴·AI之旅 管理后台'
  154. var token = localStorage.getItem('token')
  155. if (to.path === '/login') {
  156. if (token) {
  157. return next('/dashboard')
  158. }
  159. return next()
  160. }
  161. if (!token) {
  162. return next('/login')
  163. }
  164. // 角色越权检查:非授权菜单访问 → 重定向到该角色默认页
  165. var role = localStorage.getItem('role') || 'admin'
  166. if (!isAllowed(role, to.path)) {
  167. return next(defaultPath(role))
  168. }
  169. next()
  170. })
  171. // Suppress navigation guard redirect errors
  172. var originalPush = VueRouter.prototype.push
  173. VueRouter.prototype.push = function push(location) {
  174. return originalPush.call(this, location).catch(function (err) { return err })
  175. }
  176. export default router