fix: 1. 修复角色权限管理报错误提示的问题
This commit is contained in:
@@ -55,41 +55,14 @@ function getDataScopeLabel(scope: string): string {
|
||||
// ClientLoader - 加载初始数据
|
||||
export async function clientLoader({ request }: ClientLoaderFunctionArgs) {
|
||||
// ==================== 权限校验 ====================
|
||||
// 检查用户是否有provincial_admin权限
|
||||
try {
|
||||
const userInfo = localStorage.getItem('user_info');
|
||||
|
||||
if (!userInfo) {
|
||||
// 未登录,重定向到登录页
|
||||
window.location.href = '/login';
|
||||
throw new Error('未登录');
|
||||
}
|
||||
|
||||
const user = JSON.parse(userInfo);
|
||||
|
||||
// 检查角色或权限
|
||||
// provincial_admin 角色拥有完整的RBAC管理权限
|
||||
const hasPermission =
|
||||
user.role === 'provincial_admin' ||
|
||||
user.role_key === 'provincial_admin' ||
|
||||
(user.permissions && Array.isArray(user.permissions) && user.permissions.includes('system:rbac:manage'));
|
||||
|
||||
if (!hasPermission) {
|
||||
// 无权限,显示错误提示
|
||||
console.warn('⚠️ 权限不足:需要省级管理员权限或system:rbac:manage权限');
|
||||
toastService.error('权限不足,需要省级管理员权限');
|
||||
|
||||
// 返回空数据,但不阻止页面渲染(可以显示友好的无权限提示)
|
||||
return {
|
||||
roles: [],
|
||||
routes: [],
|
||||
users: [],
|
||||
noPermission: true
|
||||
};
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('权限检查失败:', error);
|
||||
}
|
||||
// 不在这里做权限检查,因为路由权限已经在 root.tsx 中检查过了
|
||||
// 如果用户能访问到这个页面,说明已经通过了路由权限检查
|
||||
//
|
||||
// 原有的客户端权限检查逻辑已移除,统一使用 root.tsx 的路由权限控制
|
||||
// 这样可以避免:
|
||||
// 1. 路由权限通过但页面权限不通过的冲突
|
||||
// 2. localStorage.user_info 数据不完整导致的误判
|
||||
// 3. 重复的权限检查逻辑
|
||||
|
||||
// ==================== 加载数据 ====================
|
||||
try {
|
||||
@@ -102,16 +75,14 @@ export async function clientLoader({ request }: ClientLoaderFunctionArgs) {
|
||||
return {
|
||||
roles,
|
||||
routes,
|
||||
users,
|
||||
noPermission: false
|
||||
users
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("加载数据失败:", error);
|
||||
return {
|
||||
roles: [],
|
||||
routes: [],
|
||||
users: [],
|
||||
noPermission: false
|
||||
users: []
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1105,22 +1076,26 @@ export default function RolePermissions() {
|
||||
);
|
||||
}
|
||||
|
||||
// 检查是否有权限(通过角色列表是否为空判断)
|
||||
// 注意:这是一个简单的权限检查,实际应该从loader返回的noPermission字段判断
|
||||
const noPermission = roles.length === 0 && routes.length === 0 && users.length === 0 && !loading;
|
||||
// ==================== 权限检查移除说明 ====================
|
||||
// 原有的客户端权限检查已移除,统一使用 root.tsx 的路由权限控制
|
||||
// 如果用户能访问到这个页面,说明已经通过了路由权限检查
|
||||
// 不再显示"无权限"提示页面
|
||||
|
||||
// 无权限提示页面
|
||||
if (noPermission) {
|
||||
// 如果数据为空,可能是数据加载失败,显示友好的空状态提示
|
||||
const hasNoData = roles.length === 0 && routes.length === 0 && users.length === 0 && !loading;
|
||||
|
||||
// 数据加载失败提示(不是权限问题)
|
||||
if (hasNoData) {
|
||||
return (
|
||||
<div className="role-permissions-page">
|
||||
<Card className="no-permission-card">
|
||||
<Card className="no-data-card">
|
||||
<div className="empty-state" style={{ padding: '80px 40px' }}>
|
||||
<i className="ri-shield-cross-line" style={{ fontSize: '96px', color: '#dcdfe6' }}></i>
|
||||
<i className="ri-database-2-line" style={{ fontSize: '96px', color: '#dcdfe6' }}></i>
|
||||
<h2 style={{ fontSize: '24px', fontWeight: 600, color: '#303133', marginTop: '24px', marginBottom: '12px' }}>
|
||||
权限不足
|
||||
暂无数据
|
||||
</h2>
|
||||
<p style={{ fontSize: '16px', color: '#606266', marginBottom: '32px' }}>
|
||||
您没有访问角色权限管理的权限,需要 <strong>省级管理员</strong> 角色或 <strong>system:rbac:manage</strong> 权限
|
||||
系统中暂无角色、路由或用户数据,请稍后重试或联系管理员
|
||||
</p>
|
||||
<div style={{ display: 'flex', gap: '12px', justifyContent: 'center' }}>
|
||||
<Button type="default" icon="ri-arrow-left-line" onClick={() => window.history.back()}>
|
||||
|
||||
Reference in New Issue
Block a user