index.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. import Vue from 'vue';
  2. import VueRouter from 'vue-router';
  3. import login from '@/views/login';
  4. import Layout from '@/layouts';
  5. import store from '@/store';
  6. import NProgress from 'nprogress';
  7. import { Message } from 'element-ui';
  8. Vue.use(VueRouter);
  9. function isHasPopedom(code) {
  10. return store.state.user.popedom_code_list.indexOf(code) !== -1;
  11. }
  12. function jumpURL() {
  13. if (isHasPopedom(1000001)) {
  14. return '/org_manager';
  15. }
  16. if (isHasPopedom(1000002)) {
  17. return '/account_manager/index';
  18. }
  19. if (isHasPopedom(1000003)) {
  20. return '/teacher_manager/index';
  21. }
  22. return '/login';
  23. }
  24. // 路由独享的守卫的权限控制
  25. function beforeRouterPopedom(code, next) {
  26. if (isHasPopedom(code)) {
  27. next();
  28. } else {
  29. Message({
  30. type: 'warning',
  31. message: '无权限'
  32. });
  33. store.dispatch('user/signOut');
  34. next('/login');
  35. NProgress.done();
  36. }
  37. }
  38. const routes = [
  39. {
  40. path: '/login',
  41. component: login
  42. },
  43. {
  44. path: '/jump',
  45. redirect: () => jumpURL()
  46. },
  47. {
  48. path: '/404',
  49. component: () => import('@/views/404')
  50. },
  51. {
  52. path: '/',
  53. component: Layout,
  54. redirect: { name: 'OrgManager' },
  55. meta: { title: '机构管理', path: '/org_manager' },
  56. children: [
  57. {
  58. path: '/org_manager',
  59. name: 'OrgManager',
  60. component: () => import('@/views/org_manager'),
  61. beforeEnter: (to, form, next) => {
  62. beforeRouterPopedom(1000001, next);
  63. }
  64. },
  65. {
  66. path: '/add_org',
  67. meta: { title: '创建机构' },
  68. component: () => import('@/views/org_manager/AddOrg'),
  69. beforeEnter: (to, form, next) => {
  70. beforeRouterPopedom(1000001, next);
  71. }
  72. }
  73. ]
  74. },
  75. {
  76. path: '/account_manager',
  77. component: Layout,
  78. meta: { title: '账户管理' },
  79. redirect: { name: 'AccountManager' },
  80. children: [
  81. {
  82. path: '/account_manager/index',
  83. name: 'AccountManager',
  84. component: () => import('@/views/account_manager'),
  85. beforeEnter: (to, form, next) => {
  86. beforeRouterPopedom(1000002, next);
  87. }
  88. }
  89. ]
  90. },
  91. {
  92. path: '/teacher_manager',
  93. component: Layout,
  94. meta: { title: '机构教师' },
  95. redirect: { name: 'TeacherManager' },
  96. children: [
  97. {
  98. path: '/teacher_manager/index',
  99. name: 'TeacherManager',
  100. component: () => import('@/views/teacher_manager'),
  101. beforeEnter: (to, form, next) => {
  102. beforeRouterPopedom(1000003, next);
  103. }
  104. }
  105. ]
  106. },
  107. {
  108. path: '/student_manager',
  109. component: Layout,
  110. meta: { title: '机构学生' },
  111. redirect: { name: 'StudentManager' },
  112. children: [
  113. {
  114. path: '/student_manager/index',
  115. name: 'StudentManager',
  116. component: () => import('@/views/student_manager'),
  117. beforeEnter: (to, form, next) => {
  118. beforeRouterPopedom(1000003, next);
  119. }
  120. }
  121. ]
  122. },
  123. {
  124. path: '/vocabulary',
  125. component: Layout,
  126. meta: { title: '多语言词汇' },
  127. redirect: '/vocabulary/index',
  128. children: [
  129. {
  130. path: '/vocabulary/index',
  131. component: () => import('@/views/vocabulary/index')
  132. },
  133. {
  134. path: '/vocabDetail',
  135. component: () => import('@/views/vocabulary/vocabDetail')
  136. }
  137. ]
  138. },
  139. {
  140. path: '/uploadList',
  141. component: Layout,
  142. meta: { title: '文件静态资源' },
  143. redirect: '/upload/uploadList',
  144. children: [
  145. {
  146. path: '/upload/uploadList',
  147. component: () => import('@/views/upload/uploadList')
  148. },
  149. {
  150. path: '/uploadDetail',
  151. component: () => import('@/views/upload/uploadDetail'),
  152. meta: { title: '文件详情' }
  153. }
  154. ]
  155. },
  156. {
  157. path: '/settings',
  158. component: Layout,
  159. meta: { title: '系统配置' },
  160. redirect: '/settings/index/LiveRoomConfig',
  161. children: [
  162. {
  163. path: '/settings/index',
  164. component: () => import('@/views/settings'),
  165. children: [
  166. {
  167. path: 'LiveRoomConfig',
  168. meta: {
  169. name: 'LiveRoomConfig'
  170. },
  171. components: {
  172. // 命名视图
  173. configure: () => import('@/views/settings/configure/LiveRoomConfig.vue')
  174. }
  175. },
  176. {
  177. path: 'SXYZFConfig',
  178. meta: {
  179. name: 'SXYZFConfig'
  180. },
  181. components: {
  182. configure: () => import('@/views/settings/configure/SXYZFConfig.vue')
  183. }
  184. }
  185. ]
  186. }
  187. ]
  188. },
  189. {
  190. path: '/quota',
  191. component: Layout,
  192. meta: { title: '配额管理', path: '/quota' },
  193. redirect: '/quota/index',
  194. children: [
  195. {
  196. path: 'index',
  197. component: () => import('@/views/quota')
  198. },
  199. {
  200. path: 'usageRecord/:orgId/:orgName',
  201. component: () => import('@/views/quota/UsageRecord.vue'),
  202. meta: { title: '' },
  203. props: true,
  204. beforeEnter: ({ meta, params }, from, next) => {
  205. meta.title = params.orgName;
  206. next();
  207. }
  208. },
  209. {
  210. path: 'liveDetail/:taskId/:orgName',
  211. component: () => import('@/views/quota/LiveDetail.vue'),
  212. meta: { title: '' },
  213. props: true,
  214. beforeEnter: ({ meta, params }, from, next) => {
  215. meta.title = params.orgName;
  216. next();
  217. }
  218. }
  219. ]
  220. },
  221. {
  222. path: '*',
  223. redirect: '/404'
  224. }
  225. ];
  226. const createRouter = () =>
  227. new VueRouter({
  228. // mode: 'history',
  229. scrollBehavior: () => ({ y: 0 }),
  230. routes
  231. });
  232. const router = createRouter();
  233. // 重置路由
  234. export function resetRouter() {
  235. const newRouter = createRouter();
  236. router.matcher = newRouter.matcher;
  237. }
  238. export default router;