web-base-pc/src/permission.js

38 lines
849 B
JavaScript
Raw Normal View History

2025-03-23 09:23:38 +08:00
/*
* @Descripttion:
* @version:
2025-03-23 09:23:38 +08:00
* @Author: kBank
* @Date: 2023-01-10 09:59:30
*/
import router from "./router";
import store from "./store";
import { getToken } from "@/util/auth";
2025-03-23 09:23:38 +08:00
const whiteList = ["/login", "/bfPay", "/hfPay", "/freeLogin"];
2025-03-23 09:23:38 +08:00
router.beforeEach((to, from, next) => {
if (getToken()) {
if (whiteList.indexOf(to.path) !== -1) {
next();
2025-03-23 09:23:38 +08:00
} else {
if (!store.getters.userInfo.memberCode) {
store
.dispatch("GetInfo")
.then(() => {
next();
})
.catch(() => {
next(`/login?redirect=${to.fullPath}`);
});
2025-03-23 09:23:38 +08:00
} else {
next();
2025-03-23 09:23:38 +08:00
}
}
} else {
if (whiteList.indexOf(to.path) !== -1) {
next();
2025-03-23 09:23:38 +08:00
} else {
next(`/login?redirect=${to.fullPath}`); // 否则全部重定向到登录页
2025-03-23 09:23:38 +08:00
}
}
});