permission.js 926 B

1234567891011121314151617181920212223242526272829
  1. import router from "./router";
  2. import { getCookie } from "@/utils/auth"; // getToken from cookie
  3. const whiteList = ["/login", "/logout", '/check']; // 不重定向白名单
  4. import store from "@/store";
  5. router.beforeEach((to, from, next) => {
  6. document.title = `${to.meta.title} | 发电能力分析平台`;
  7. const token = getCookie("accessToken");
  8. // const role = sessionStorage.getItem("ms_chinesename");
  9. if (token) {
  10. if (to.path == "/login") {
  11. next("/");
  12. } else {
  13. if (store.getters.roles.length == 0) {
  14. store.dispatch("user/GetInfo").then(async () => {
  15. next();
  16. });
  17. } else {
  18. next();
  19. }
  20. }
  21. } else if (whiteList.indexOf(to.path) !== -1) {
  22. next();
  23. } else {
  24. next(`/login?redirect=${to.fullPath}`);
  25. }
  26. });
  27. router.afterEach((to, from, next) => {});