permission.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import router from "./router";
  2. import { getCookie } from "@/utills/auth"; // getToken from cookie
  3. import { Base64 } from "js-base64";
  4. const whiteList = ["/login", "/logout"]; // 不重定向白名单
  5. import store from "@/store";
  6. router.beforeEach((to, from, next) => {
  7. // if (getCookie("authToken")) {
  8. // if (to.path == "/login") {
  9. // next({ path: "/home" });
  10. // } else {
  11. // if (store.getters.roles.length === 0) {
  12. // // 判断当前用户是否已拉取完user_info信息
  13. // store
  14. // .dispatch("user/GetInfo")
  15. // .then(async () => {
  16. // let permissions = store.getters.permissions;
  17. // let accessRoutes = [];
  18. // accessRoutes = await store.dispatch(
  19. // "routes/setRoutes",
  20. // permissions
  21. // );
  22. // accessRoutes?.forEach((item) => {
  23. // router.addRoute(item);
  24. // });
  25. // next({ ...to, replace: true });
  26. // })
  27. // .catch((err) => {});
  28. // } else {
  29. // next();
  30. // }
  31. // }
  32. // } else if (whiteList.indexOf(to.path) !== -1) {
  33. // next();
  34. // } else {
  35. // next(`/login?redirect=${to.fullPath}`);
  36. // }
  37. next();
  38. //有token或在免登录白名单,直接放行
  39. // if (getCookie("iamAccessToken")) {
  40. // if (!store.state.userInfo) {
  41. // //获取用户资料
  42. // const result1 = store.dispatch("getUserInfo");
  43. // //获取菜单
  44. // const result2 = store.dispatch("getmenuList");
  45. // next();
  46. // } else {
  47. // next();
  48. // }
  49. // // next();//放行
  50. // } else if (whiteList.indexOf(to.path) !== -1) {
  51. // next(); //放行
  52. // } else {
  53. // removeImsCookie();
  54. // store.state.userInfo = null;
  55. // const mode = process.env.VUE_APP_LOGIN_MODE;
  56. // if (mode == 1) {
  57. // let base64Url = Base64.encode(process.env.VUE_APP_REDIRECT_URL);
  58. // window.location.href =
  59. // process.env.VUE_APP_UNIFIED_LOGIN + "&redirect_url=" + base64Url;
  60. // } else {
  61. // // router.push('/login');
  62. // next("/login");
  63. // }
  64. // }
  65. });
  66. router.afterEach((to, from, next) => {});