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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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