后台管理 登陆权限问题解决
This commit is contained in:
@@ -198,18 +198,26 @@ const router = createRouter({
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
document.title = `${to.meta.title} | ${settings.siteTitle}`;
|
||||
const role = localStorage.getItem('ms_username');
|
||||
const username = localStorage.getItem('ms_username');
|
||||
const role = localStorage.getItem('ms_role_id');
|
||||
const permiss = usePermissStore();
|
||||
if (!role && to.path !== '/login') {
|
||||
const currentUserPermiss = permiss[role as string];
|
||||
// console.log("currentUserPermiss", currentUserPermiss)
|
||||
if (!username && to.path !== '/login') {
|
||||
next({
|
||||
path: '/login',
|
||||
query: {
|
||||
redirectTo: router.currentRoute.value.path // window.location.href
|
||||
},
|
||||
});
|
||||
} else if (to.meta.permiss && !permiss.key.includes(to.meta.permiss)) {
|
||||
return
|
||||
} else if (
|
||||
to.meta.permiss &&
|
||||
!(currentUserPermiss && currentUserPermiss.includes(to.meta.permiss as string))
|
||||
) {
|
||||
// 如果没有权限,则进入403
|
||||
next('/403');
|
||||
return
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
|
Reference in New Issue
Block a user