index.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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. path: '/free_license/:org_id',
  75. meta: { title: '教材授权' },
  76. component: () => import('@/views/org_manager/FreeLicense.vue'),
  77. beforeEnter: (to, form, next) => {
  78. beforeRouterPopedom(1000001, next);
  79. }
  80. }
  81. ]
  82. },
  83. {
  84. path: '/account_manager',
  85. component: Layout,
  86. meta: { title: '账户管理' },
  87. redirect: { name: 'AccountManager' },
  88. children: [
  89. {
  90. path: 'index',
  91. name: 'AccountManager',
  92. component: () => import('@/views/account_manager'),
  93. beforeEnter: (to, form, next) => {
  94. beforeRouterPopedom(1000002, next);
  95. }
  96. }
  97. ]
  98. },
  99. {
  100. path: '/teacher_manager',
  101. component: Layout,
  102. meta: { title: '机构教师' },
  103. redirect: { name: 'TeacherManager' },
  104. children: [
  105. {
  106. path: 'index',
  107. name: 'TeacherManager',
  108. component: () => import('@/views/teacher_manager'),
  109. beforeEnter: (to, form, next) => {
  110. beforeRouterPopedom(1000003, next);
  111. }
  112. }
  113. ]
  114. },
  115. {
  116. path: '/student_manager',
  117. component: Layout,
  118. meta: { title: '机构学生' },
  119. redirect: { name: 'StudentManager' },
  120. children: [
  121. {
  122. path: 'index',
  123. name: 'StudentManager',
  124. component: () => import('@/views/student_manager'),
  125. beforeEnter: (to, form, next) => {
  126. beforeRouterPopedom(1000003, next);
  127. }
  128. }
  129. ]
  130. },
  131. {
  132. path: '/vocabulary',
  133. component: Layout,
  134. meta: { title: '多语言词汇' },
  135. redirect: '/vocabulary/index',
  136. children: [
  137. {
  138. path: 'index',
  139. component: () => import('@/views/vocabulary/index')
  140. },
  141. {
  142. path: '/vocabDetail',
  143. component: () => import('@/views/vocabulary/vocabDetail')
  144. }
  145. ]
  146. },
  147. {
  148. path: '/uploadList',
  149. component: Layout,
  150. meta: { title: '文件静态资源' },
  151. redirect: '/upload/uploadList',
  152. children: [
  153. {
  154. path: '/upload/uploadList',
  155. component: () => import('@/views/upload/uploadList')
  156. },
  157. {
  158. path: '/uploadDetail',
  159. component: () => import('@/views/upload/uploadDetail'),
  160. meta: { title: '文件详情' }
  161. }
  162. ]
  163. },
  164. {
  165. path: '/settings',
  166. component: Layout,
  167. meta: { title: '系统配置' },
  168. redirect: '/settings/index/LiveRoomConfig',
  169. children: [
  170. {
  171. path: 'index',
  172. component: () => import('@/views/settings'),
  173. children: [
  174. {
  175. path: 'LiveRoomConfig',
  176. meta: {
  177. name: 'LiveRoomConfig'
  178. },
  179. components: {
  180. // 命名视图
  181. configure: () => import('@/views/settings/configure/LiveRoomConfig.vue')
  182. }
  183. },
  184. {
  185. path: 'SXYZFConfig',
  186. meta: {
  187. name: 'SXYZFConfig'
  188. },
  189. components: {
  190. configure: () => import('@/views/settings/configure/SXYZFConfig.vue')
  191. }
  192. },
  193. {
  194. path: 'MailboxConfig',
  195. meta: {
  196. name: 'MailboxConfig'
  197. },
  198. components: {
  199. configure: () => import('@/views/settings/configure/MailboxConfig.vue')
  200. }
  201. },
  202. {
  203. path: 'ShareConfig',
  204. meta: {
  205. name: 'ShareConfig'
  206. },
  207. components: {
  208. configure: () => import('@/views/settings/configure/ShareConfig.vue')
  209. }
  210. },
  211. {
  212. path: 'SpeechEngine',
  213. meta: {
  214. name: 'SpeechEngine'
  215. },
  216. components: {
  217. configure: () => import('@/views/settings/configure/SpeechEngine.vue')
  218. }
  219. }
  220. ]
  221. }
  222. ]
  223. },
  224. {
  225. path: '/quota',
  226. component: Layout,
  227. meta: { title: '配额管理', path: '/quota' },
  228. redirect: '/quota/index',
  229. children: [
  230. {
  231. path: 'index',
  232. component: () => import('@/views/quota')
  233. },
  234. {
  235. path: 'usageRecord/:orgId/:orgName',
  236. component: () => import('@/views/quota/UsageRecord.vue'),
  237. meta: { title: '' },
  238. props: true,
  239. beforeEnter: ({ meta, params }, from, next) => {
  240. meta.title = params.orgName;
  241. next();
  242. }
  243. },
  244. {
  245. path: 'liveDetail/:orgId/:taskId/:orgName',
  246. component: () => import('@/views/quota/LiveDetail.vue'),
  247. meta: { title: '' },
  248. props: true,
  249. beforeEnter: ({ meta, params }, from, next) => {
  250. meta.title = params.orgName;
  251. next();
  252. }
  253. }
  254. ]
  255. },
  256. {
  257. path: '/oboc',
  258. component: Layout,
  259. meta: { title: '教材链接', path: '/oboc' },
  260. redirect: '/oboc/index',
  261. children: [
  262. {
  263. path: 'index',
  264. component: () => import('@/views/oboc')
  265. }
  266. ]
  267. },
  268. {
  269. path: '/log',
  270. component: Layout,
  271. meta: { title: '操作日志' },
  272. redirect: '/log/index',
  273. children: [
  274. {
  275. path: 'index',
  276. component: () => import('@/views/log/index.vue')
  277. }
  278. ]
  279. },
  280. {
  281. path: '*',
  282. redirect: '/404'
  283. }
  284. ];
  285. const createRouter = () =>
  286. new VueRouter({
  287. // mode: 'history',
  288. scrollBehavior: () => ({ y: 0 }),
  289. routes
  290. });
  291. const router = createRouter();
  292. // 重置路由
  293. export function resetRouter() {
  294. const newRouter = createRouter();
  295. router.matcher = newRouter.matcher;
  296. }
  297. export default router;