index.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. import { getToken } from "@/auth/auth";
  2. import { isNil } from "lodash-es";
  3. import Vue from "vue";
  4. import VueRouter from "vue-router";
  5. import Home from "../views/Home/Home.vue";
  6. import Layout from "@/views/Layout/Layout.vue";
  7. import invigilation from "./invigilation";
  8. // ignore NavigationDuplicated. https://github.com/vuejs/vue-router/issues/2881
  9. const originalPush = VueRouter.prototype.push;
  10. VueRouter.prototype.push = function push(location, onResolve, onReject) {
  11. if (onResolve || onReject)
  12. return originalPush.call(this, location, onResolve, onReject);
  13. try {
  14. return originalPush.call(this, location).catch((err) => err);
  15. } catch (error) {
  16. console.log(error);
  17. }
  18. };
  19. // end ignore
  20. Vue.use(VueRouter);
  21. // function propsValidator(route, component) {
  22. // const props = { ...route.params };
  23. // Object.entries(props).map(([key, prop]) => {
  24. // console.log(prop, key);
  25. // if (!(prop instanceof component.props[key].type)) {
  26. // props[key] = component.props[key].type(prop);
  27. // }
  28. // });
  29. // return props;
  30. // }
  31. /** @type {import("vue-router").RouteConfig[]} */
  32. const routes = [
  33. { path: "/", redirect: { name: "Login" } },
  34. {
  35. path: "/",
  36. name: "Index",
  37. redirect: { name: "Login" },
  38. },
  39. {
  40. path: "/home",
  41. component: Layout,
  42. children: [
  43. {
  44. path: "",
  45. name: "Home",
  46. component: Home,
  47. },
  48. ],
  49. },
  50. {
  51. path: "/system",
  52. name: "System",
  53. component: Layout,
  54. children: [
  55. {
  56. path: "user",
  57. name: "UserManagement",
  58. component: () =>
  59. import(
  60. /* webpackChunkName: "system" */ "../features/system/UserManagement/UserManagement.vue"
  61. ),
  62. },
  63. {
  64. path: "org",
  65. name: "OrgManagement",
  66. component: () =>
  67. import(
  68. /* webpackChunkName: "system" */ "../features/system/OrgManagement/OrgManagement.vue"
  69. ),
  70. },
  71. {
  72. path: "statistics",
  73. name: "DataCountManagement",
  74. component: () =>
  75. import(
  76. /* webpackChunkName: "system" */ "../features/system/DataStatistics/DataStatistics.vue"
  77. ),
  78. },
  79. {
  80. path: "black-list",
  81. name: "BlackListManagement",
  82. component: () =>
  83. import(
  84. /* webpackChunkName: "system" */ "../features/system/BlackList/BlackList.vue"
  85. ),
  86. },
  87. {
  88. path: "system-notice",
  89. name: "SystemNotifyManagement",
  90. component: () =>
  91. import(
  92. /* webpackChunkName: "system" */ "../features/system/SystemNotice/SystemNotice.vue"
  93. ),
  94. },
  95. {
  96. path: "system-config",
  97. name: "SysConfigManagement",
  98. component: () =>
  99. import(
  100. /* webpackChunkName: "system" */ "../features/system/SystemConfig/SystemConfig.vue"
  101. ),
  102. },
  103. ],
  104. },
  105. {
  106. path: "/exam",
  107. name: "Exam",
  108. component: Layout,
  109. children: [
  110. {
  111. path: "list",
  112. name: "ExamManagement",
  113. component: () =>
  114. import(
  115. /* webpackChunkName: "exam" */ "../features/examwork/ExamManagement/ExamManagement.vue"
  116. ),
  117. },
  118. {
  119. path: "edit/:id?",
  120. name: "ExamEdit",
  121. component: () =>
  122. import(
  123. /* webpackChunkName: "exam" */ "../features/examwork/ExamManagement/ExamEdit.vue"
  124. ),
  125. meta: {
  126. relate: "ExamManagement",
  127. },
  128. },
  129. {
  130. path: ":examId/activity",
  131. name: "ActivityManagement",
  132. component: () =>
  133. import(
  134. /* webpackChunkName: "exam" */ "../features/examwork/ActivityManagement/ActivityManagement.vue"
  135. ),
  136. meta: {
  137. relate: "ExamManagement",
  138. },
  139. },
  140. {
  141. path: ":examId/activity/new",
  142. name: "ActivityEdit",
  143. component: () =>
  144. import(
  145. /* webpackChunkName: "exam" */ "../features/examwork/ActivityManagement/ActivityEdit.vue"
  146. ),
  147. meta: {
  148. relate: "ExamManagement",
  149. },
  150. },
  151. {
  152. path: "activity/:activityId/audio",
  153. name: "ActivityAudioManagement",
  154. component: () =>
  155. import(
  156. /* webpackChunkName: "exam" */ "../features/examwork/ActivityManagement/ActivityAudioManagement.vue"
  157. ),
  158. meta: {
  159. relate: "ExamManagement",
  160. },
  161. },
  162. {
  163. path: "examstudent",
  164. name: "ExamStudentManagement",
  165. component: () =>
  166. import(
  167. /* webpackChunkName: "exam" */ "../features/examwork/ExamStudentManagement/ExamStudentManagement.vue"
  168. ),
  169. },
  170. {
  171. path: "examstudent/import",
  172. name: "ExamStudentImport",
  173. component: () =>
  174. import(
  175. /* webpackChunkName: "exam" */ "../features/examwork/ExamStudentImport/ExamStudentImport.vue"
  176. ),
  177. },
  178. {
  179. path: "course",
  180. name: "CourseManagement",
  181. component: () =>
  182. import(
  183. /* webpackChunkName: "exam" */ "../features/examwork/CourseManagement/CourseManagement.vue"
  184. ),
  185. },
  186. {
  187. path: "student",
  188. name: "StudentManagement",
  189. component: () =>
  190. import(
  191. /* webpackChunkName: "exam" */ "../features/examwork/StudentManagement/StudentManagement.vue"
  192. ),
  193. },
  194. {
  195. path: "student-track-record/:examRecordId",
  196. name: "StudentTrackRecord",
  197. component: () =>
  198. import(
  199. /* webpackChunkName: "exam" */ "../features/examwork/StudentManagement/StudentTrackRecord.vue"
  200. ),
  201. meta: {
  202. relate: "StudentManagement",
  203. },
  204. },
  205. {
  206. path: "invigilate",
  207. name: "InvigilateManagement",
  208. component: () =>
  209. import(
  210. /* webpackChunkName: "exam" */ "../features/examwork/InvigilateManagement/InvigilateManagement.vue"
  211. ),
  212. },
  213. {
  214. path: "student-exam-detail",
  215. name: "StudentExamDetail",
  216. component: () =>
  217. import(
  218. /* webpackChunkName: "exam" */ "../features/examwork/StudentExamDetail/StudentExamDetail.vue"
  219. ),
  220. },
  221. {
  222. path: "task",
  223. name: "ImportExportTask",
  224. component: () =>
  225. import(
  226. /* webpackChunkName: "exam" */ "../features/examwork/ImportExportTask/ImportExportTask.vue"
  227. ),
  228. },
  229. {
  230. path: "markresult",
  231. name: "MarkResultManagement",
  232. component: () =>
  233. import(
  234. /* webpackChunkName: "exam" */ "../features/examwork/MarkResultManagement/MarkResultManagement.vue"
  235. ),
  236. },
  237. ],
  238. },
  239. {
  240. path: "/exam/student-monitor-record",
  241. name: "StudentMonitorRecord",
  242. component: () =>
  243. import(
  244. /* webpackChunkName: "record" */ "../features/examwork/StudentManagement/StudentMonitorRecord.vue"
  245. ),
  246. },
  247. {
  248. path: "/invigilation",
  249. name: "Invigilation",
  250. component: Layout,
  251. children: [...invigilation],
  252. },
  253. {
  254. path: "/download",
  255. name: "Download",
  256. component: () =>
  257. import(
  258. /* webpackChunkName: "download" */ "../features/download/Download.vue"
  259. ),
  260. },
  261. {
  262. path: "/login",
  263. name: "Login",
  264. component: () =>
  265. import(/* webpackChunkName: "Login" */ "../features/Login/Login.vue"),
  266. },
  267. {
  268. path: "*",
  269. name: "404",
  270. component: () =>
  271. import(/* webpackChunkName: "default" */ "../views/404.vue"),
  272. },
  273. ];
  274. const router = new VueRouter({
  275. mode: "history",
  276. base: process.env.VUE_APP_ROUTER_PATH,
  277. routes,
  278. });
  279. // FIXME: router.route 添加 auth,代表是否需要认证。
  280. // FIXME: roles. 根据roles来授权。
  281. // FIXME: 在Login页面,验证通过后,返回redirectTo 页面。
  282. router.beforeEach((to, from, next) => {
  283. if (to.path) {
  284. window._hmt.push(["_trackPageview", to.fullPath]);
  285. }
  286. const token = getToken();
  287. if (isNil(token) && to.path.includes("/login") === false) {
  288. router.push("/login?redirectTo=" + encodeURI(to.fullPath));
  289. next(false);
  290. } else {
  291. next();
  292. }
  293. });
  294. export default router;