index.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import Vue from 'vue';
  2. import VueRouter from 'vue-router';
  3. import store from '@/store/index';
  4. import { Notification } from 'element-ui';
  5. Vue.use(VueRouter);
  6. const routes = [
  7. {
  8. path: '/',
  9. name: 'frame',
  10. component: () => import('@/views/index.vue'),
  11. children: [
  12. {
  13. path: '/plan/index',
  14. name: 'plan_list',
  15. meta: { title: '计划', sub: '列表' },
  16. component: () => import('@/views/plan/index.vue'),
  17. },
  18. {
  19. path: '/plan/detail',
  20. name: 'plan_detail',
  21. meta: { title: '计划', sub: '详情' },
  22. component: () => import('@/views/plan/detail.vue'),
  23. },
  24. {
  25. path: '/plan/classes',
  26. name: 'plan_classes',
  27. meta: { title: '授课班级' },
  28. component: () => import('@/views/plan/classes.vue'),
  29. },
  30. {
  31. path: '/plan/name/list',
  32. name: 'plan_name_list',
  33. meta: { title: '授课班级' },
  34. component: () => import('@/views/plan/classes/name-list.vue'),
  35. },
  36. {
  37. path: '/plan/class/info',
  38. name: 'plan_class_info',
  39. meta: { title: '班级信息' },
  40. component: () => import('@/views/plan/classes/info.vue'),
  41. },
  42. {
  43. path: '/lesson/index',
  44. name: 'lesson_index',
  45. meta: { title: '课程信息' },
  46. component: () => import('@/views/lesson/index.vue'),
  47. },
  48. {
  49. path: '/task/index',
  50. name: 'task_index',
  51. meta: { title: '作业管理' },
  52. component: () => import('@/views/task/index.vue'),
  53. },
  54. {
  55. path: '/task/taskList',
  56. name: 'task_taskList',
  57. meta: { title: '学生作业列表' },
  58. component: () => import('@/views/task/taskList.vue'),
  59. },
  60. {
  61. path: '/task/taskDetail',
  62. name: 'task_taskDetail',
  63. meta: { title: '学生作业详情' },
  64. component: () => import('@/views/task/taskDetail.vue'),
  65. },
  66. {
  67. path: '/class/index',
  68. name: 'class_index',
  69. meta: { title: '班级信息' },
  70. component: () => import('@/views/class/index.vue'),
  71. },
  72. {
  73. path: '/class/classStuList',
  74. name: 'class_classStuList',
  75. meta: { title: '学生名单' },
  76. component: () => import('@/views/class/classStuList.vue'),
  77. },
  78. // 在线授课
  79. {
  80. path: '/teaching/index',
  81. name: 'teaching_index',
  82. meta: { title: '直播讲课' },
  83. component: () => import('@/views/teaching/index.vue'),
  84. },
  85. {
  86. path: '/teaching/detail',
  87. name: 'teaching_detail',
  88. meta: { title: '直播讲课信息', sub: '管理' },
  89. component: () => import('@/views/teaching/detail.vue'),
  90. },
  91. {
  92. path: '/teaching/live',
  93. name: 'teaching_live',
  94. meta: { title: '直播讲课', sub: '管理' },
  95. component: () => import('@/views/teaching/live.vue'),
  96. },
  97. {
  98. path: '/teaching/afterClass',
  99. name: 'teaching_afterClass',
  100. meta: { title: '课后答疑', sub: '管理' },
  101. component: () => import('@/views/teaching/afterClass.vue'),
  102. },
  103. {
  104. path: '/teaching/afterClassDetail',
  105. name: 'teaching_afterClassDetail',
  106. meta: { title: '课后答疑', sub: '管理' },
  107. component: () => import('@/views/teaching/afterClassDetail.vue'),
  108. },
  109. {
  110. path: '/teaching/afterClassList',
  111. name: 'teaching_afterClassList',
  112. meta: { title: '答疑列表', sub: '管理' },
  113. component: () => import('@/views/teaching/afterClassList.vue'),
  114. },
  115. ],
  116. },
  117. {
  118. path: '/login',
  119. name: 'login',
  120. meta: { title: '登录', sub: '管理' },
  121. component: () => import('@/views/register/login.vue'),
  122. },
  123. ];
  124. const router = new VueRouter({
  125. mode: 'history',
  126. base: process.env.NODE_ENV === 'development' ? '' : 'teacher',
  127. routes,
  128. });
  129. router.beforeEach((to, form, next) => {
  130. store.commit('setUser');
  131. store.dispatch('setting/checkCache');
  132. if (to.name === 'login') {
  133. next();
  134. return;
  135. }
  136. let user = store.state.user;
  137. if (user) {
  138. if (user.type == process.env.VUE_APP_USER_TYPE) {
  139. console.log('已登录');
  140. next();
  141. } else {
  142. Notification({
  143. title: '请重新登陆',
  144. message: `原因:非当前端用户,需要重新登陆`,
  145. type: 'warning',
  146. });
  147. console.warn('非当前端用户,需要重新登陆');
  148. next({ name: 'login' });
  149. }
  150. }
  151. //下面是没登录的情况,需要跳转页面到用户未登录页
  152. else next({ name: 'login' });
  153. });
  154. export default router;