feat(@vben/web-antd): 优化权限管理

This commit is contained in:
Kven 2025-05-11 10:46:55 +08:00
parent dcda8635f5
commit 7f0a6a07c8
7 changed files with 14 additions and 3 deletions

View File

@ -74,7 +74,6 @@ function setupAccessGuard(router: Router) {
// 没有访问权限,跳转登录页面
if (to.fullPath !== LOGIN_PATH) {
console.log('没有访问权限,请登录');
return {
path: LOGIN_PATH,
// 如不需要,直接删除 query
@ -96,11 +95,13 @@ function setupAccessGuard(router: Router) {
// 生成路由表
// 当前登录用户拥有的角色标识列表
const userInfo = userStore.userInfo || (await authStore.fetchUserInfo());
const userRoles = userInfo.roles ?? [];
// const userRoles = userInfo.roles ?? [];
// permissions Keven自定义
const permissions = userInfo.permissions ?? [];
// 生成菜单和路由
const { accessibleMenus, accessibleRoutes } = await generateAccess({
roles: userRoles,
roles: permissions,
router,
// 则会在菜单中显示但是访问会被重定向到403
routes: accessRoutes,

View File

@ -9,6 +9,7 @@ const routes: RouteRecordRaw[] = [
icon: 'mdi:home',
title: '首页',
order: -1,
authority: ['dashboard'],
},
},
];

View File

@ -11,6 +11,7 @@ const routes: RouteRecordRaw[] = [
icon: SvgPPT,
title: 'PPT自动生成',
order: 3,
authority: ['dify:workflow:run'],
},
},
];

View File

@ -11,6 +11,7 @@ const routes: RouteRecordRaw[] = [
icon: SvgSpider,
title: '数据爬取',
order: 1,
authority: ['dify:server:init'],
},
},
];

View File

@ -10,6 +10,7 @@ const routes: RouteRecordRaw[] = [
icon: IconSystem,
title: '系统管理',
order: 4,
authority: ['system'],
},
children: [
{
@ -19,6 +20,7 @@ const routes: RouteRecordRaw[] = [
meta: {
icon: EosRole,
title: '角色管理',
authority: ['system:role'],
},
},
{
@ -28,6 +30,7 @@ const routes: RouteRecordRaw[] = [
meta: {
icon: RiDept,
title: '部门管理',
authority: ['system:dept'],
},
},
{
@ -37,6 +40,7 @@ const routes: RouteRecordRaw[] = [
meta: {
icon: MdiUser,
title: '用户管理',
authority: ['system:user'],
},
},
],

View File

@ -11,6 +11,7 @@ const routes: RouteRecordRaw[] = [
icon: SvgWord,
title: 'Word自动生成',
order: 2,
authority: ['dify:chat:send'],
},
},
];

View File

@ -51,6 +51,8 @@ export const useAuthStore = defineStore('auth', () => {
realName: user.username,
username: user.username,
roles: [user.role.name],
// permissions Keven自定义
permissions: user.permissions,
homePath: '/home',
token: csrf.token,
};