feat: 产品菜单路由权限
This commit is contained in:
@ -5,6 +5,8 @@
|
||||
import type { Router } from 'vue-router';
|
||||
import NProgress from 'nprogress';
|
||||
import { goUserLogin } from '@/utils/user';
|
||||
// import router from '@/router';
|
||||
import { checkRoutePermission } from '@/permission/permission';
|
||||
|
||||
import { useUserStore } from '@/stores/modules/user';
|
||||
|
||||
@ -13,15 +15,25 @@ export default function setupUserLoginInfoGuard(router: Router) {
|
||||
NProgress.start();
|
||||
const userStore = useUserStore();
|
||||
|
||||
const routeName = to?.name as string;
|
||||
const requiresAuth = to?.meta?.requiresAuth || false;
|
||||
const isLogin = !!userStore.isLogin;
|
||||
const requireLogin = to?.meta?.requireLogin || false;
|
||||
|
||||
if (requiresAuth && !isLogin) {
|
||||
if (requireLogin && !userStore.isLogin) {
|
||||
goUserLogin();
|
||||
next();
|
||||
return;
|
||||
}
|
||||
|
||||
if (requiresAuth) {
|
||||
const hasPermission = checkRoutePermission(routeName);
|
||||
if (!hasPermission) {
|
||||
AMessage.error('您没有权限访问该页面');
|
||||
next('/');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
router.afterEach((to) => {
|
||||
|
||||
Reference in New Issue
Block a user