router.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import Vue from "vue";
  2. import Router from "vue-router";
  3. import PortalRoutes from "./modules/portal/routes/routes";
  4. import BasicRoutes from "./modules/basic/routes/routes";
  5. import examworkRoutes from "./modules/examwork/routes/routes";
  6. import MarklRoutes from "./modules/marking/routes/routes";
  7. import QuestionsRoutes from "./modules/questions/routes/routes";
  8. import OeRoutes from "./modules/oe/routes/routes";
  9. import PrintRoutes from "./modules/print/routes/routes";
  10. import ReportsRoutes from "./modules/reports/routes/routes";
  11. import { CORE_API } from "@/constants/constants.js";
  12. // ignore NavigationDuplicated. https://github.com/vuejs/vue-router/issues/2881
  13. const originalPush = Router.prototype.push;
  14. Router.prototype.push = function push(location, onResolve, onReject) {
  15. if (onResolve || onReject)
  16. return originalPush.call(this, location, onResolve, onReject);
  17. try {
  18. return originalPush.call(this, location).catch(err => err);
  19. } catch (error) {
  20. console.log(error);
  21. }
  22. };
  23. // end ignore
  24. Vue.use(Router);
  25. let router = new Router({
  26. mode: "history",
  27. base: "/admin",
  28. routes: [
  29. ...PortalRoutes,
  30. ...BasicRoutes,
  31. ...examworkRoutes,
  32. ...MarklRoutes,
  33. ...QuestionsRoutes,
  34. ...OeRoutes,
  35. ...PrintRoutes,
  36. ...ReportsRoutes
  37. ]
  38. });
  39. router.beforeEach((to, from, next) => {
  40. if (to.path) {
  41. window._hmt.push(["_trackPageview", "/admin" + to.fullPath]);
  42. }
  43. if (to.path.includes("/preview_paper/")) {
  44. next();
  45. return;
  46. }
  47. if (!to.meta.privilegeCodes) {
  48. next();
  49. } else {
  50. let params = new URLSearchParams();
  51. params.append("privilegeCodes", to.meta.privilegeCodes);
  52. Vue.prototype.$httpWithMsg
  53. .post(CORE_API + "/rolePrivilege/checkPrivileges?" + params)
  54. .then(response => {
  55. if (Object.values(response.data).includes(true)) {
  56. next();
  57. } else {
  58. Vue.prototype.$alert("没有权限访问!", "提示");
  59. next(false);
  60. }
  61. });
  62. }
  63. });
  64. export default router;