1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- import router from "./router";
- import { getCookie } from "@/utills/auth"; // getToken from cookie
- import { Base64 } from "js-base64";
- const whiteList = ["/login", "/logout"]; // 不重定向白名单
- import store from "@/store";
- router.beforeEach((to, from, next) => {
- // if (getCookie("authToken")) {
- // if (to.path == "/login") {
- // next({ path: "/home" });
- // } else {
- // if (store.getters.roles.length === 0) {
- // // 判断当前用户是否已拉取完user_info信息
- // store
- // .dispatch("user/GetInfo")
- // .then(async () => {
- // let permissions = store.getters.permissions;
- // let accessRoutes = [];
- // accessRoutes = await store.dispatch(
- // "routes/setRoutes",
- // permissions
- // );
- // accessRoutes?.forEach((item) => {
- // router.addRoute(item);
- // });
- // next({ ...to, replace: true });
- // })
- // .catch((err) => {});
- // } else {
- // next();
- // }
- // }
- // } else if (whiteList.indexOf(to.path) !== -1) {
- // next();
- // } else {
- // next(`/login?redirect=${to.fullPath}`);
- // }
- next();
- //有token或在免登录白名单,直接放行
- // if (getCookie("iamAccessToken")) {
- // if (!store.state.userInfo) {
- // //获取用户资料
- // const result1 = store.dispatch("getUserInfo");
- // //获取菜单
- // const result2 = store.dispatch("getmenuList");
- // next();
- // } else {
- // next();
- // }
- // // next();//放行
- // } else if (whiteList.indexOf(to.path) !== -1) {
- // next(); //放行
- // } else {
- // removeImsCookie();
- // store.state.userInfo = null;
- // const mode = process.env.VUE_APP_LOGIN_MODE;
- // if (mode == 1) {
- // let base64Url = Base64.encode(process.env.VUE_APP_REDIRECT_URL);
- // window.location.href =
- // process.env.VUE_APP_UNIFIED_LOGIN + "&redirect_url=" + base64Url;
- // } else {
- // // router.push('/login');
- // next("/login");
- // }
- // }
- });
- router.afterEach((to, from, next) => {});
|