router.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. Vue.use(Router);
  13. let router = new Router({
  14. mode: "history",
  15. base: "/admin",
  16. routes: [
  17. ...PortalRoutes,
  18. ...BasicRoutes,
  19. ...examworkRoutes,
  20. ...MarklRoutes,
  21. ...QuestionsRoutes,
  22. ...OeRoutes,
  23. ...PrintRoutes,
  24. ...ReportsRoutes
  25. ]
  26. });
  27. router.beforeEach((to, from, next) => {
  28. if (to.path) {
  29. window._hmt.push(["_trackPageview", "/admin" + to.fullPath]);
  30. }
  31. if (to.path.includes("/preview_paper/")) {
  32. next();
  33. return;
  34. }
  35. if (!to.meta.privilegeCodes) {
  36. next();
  37. } else {
  38. let params = new URLSearchParams();
  39. params.append("privilegeCodes", to.meta.privilegeCodes);
  40. Vue.prototype.$httpWithMsg
  41. .post(CORE_API + "/rolePrivilege/checkPrivileges?" + params)
  42. .then(response => {
  43. if (Object.values(response.data).includes(true)) {
  44. next();
  45. } else {
  46. Vue.prototype.$alert("没有权限访问!", "提示");
  47. next(false);
  48. }
  49. });
  50. }
  51. });
  52. export default router;