index.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import Vue from "vue";
  2. import Router from "vue-router";
  3. import { QUESTION_API } from "@/constants/constants.js";
  4. import Home from "../modules/portal/views/home/Home.vue";
  5. import portalRoutes from "../modules/portal/routes/routes";
  6. import {
  7. menuRoutes as qmenuRoutes,
  8. otherRoutes as qotherRoutes,
  9. } from "../modules/questions/routes/routes";
  10. import {
  11. menuRoutes as cmenuRoutes,
  12. otherRoutes as cotherRoutes,
  13. } from "../modules/card/router";
  14. import {
  15. menuRoutes as pmenuRoutes,
  16. otherRoutes as potherRoutes,
  17. } from "../modules/paper-export/router";
  18. // ignore NavigationDuplicated. https://github.com/vuejs/vue-router/issues/2881
  19. // const originalPush = Router.prototype.push;
  20. // Router.prototype.push = function push(location, onResolve, onReject) {
  21. // if (onResolve || onReject)
  22. // return originalPush.call(this, location, onResolve, onReject);
  23. // try {
  24. // return originalPush.call(this, location).catch((err) => err);
  25. // } catch (error) {
  26. // console.log(error);
  27. // }
  28. // };
  29. // end ignore
  30. Vue.use(Router);
  31. let router = new Router({
  32. mode: "history",
  33. base: "/admin",
  34. routes: [
  35. {
  36. path: "/home", //首页
  37. meta: { auth: false },
  38. component: Home,
  39. children: [...qmenuRoutes, ...cmenuRoutes, ...pmenuRoutes],
  40. },
  41. ...qotherRoutes,
  42. ...cotherRoutes,
  43. ...potherRoutes,
  44. ...portalRoutes,
  45. ],
  46. });
  47. router.beforeEach((to, from, next) => {
  48. if (to.path) {
  49. window._hmt.push(["_trackPageview", "/admin" + to.fullPath]);
  50. }
  51. if (to.path.includes("/preview_paper/")) {
  52. next();
  53. return;
  54. }
  55. if (!to.meta.privilegeCodes) {
  56. next();
  57. } else {
  58. let params = new URLSearchParams();
  59. params.append("privilegeCodes", to.meta.privilegeCodes);
  60. Vue.prototype.$httpWithMsg
  61. .post(QUESTION_API + "/rolePrivilege/checkPrivileges?" + params)
  62. .then((response) => {
  63. if (Object.values(response.data).includes(true)) {
  64. next();
  65. } else {
  66. Vue.prototype.$alert("没有权限访问!", "提示");
  67. next(false);
  68. }
  69. });
  70. }
  71. });
  72. export default router;