feat(权限): 优化角色和用户详情页的权限列表显示
- ViewRole 页面优化: - 使用 HTML 格式按模块分组显示权限 - 每个模块使用 Emoji 图标标识(📄 文档管理、⚙️ 系统设置等) - 模块名称加粗显示,权限操作用顿号分隔 - 模块之间使用空行分隔,更加清晰 - super-admin 角色显示特殊说明 - ViewUser 页面优化: - 所有权限:显示用户拥有的全部权限(角色+直接) - 直接权限:单独显示直接分配的权限 - 同样使用 Emoji 图标和分组显示 - 使用 HTML 格式提升可读性 优化后的显示效果: 📄 文档管理:查看详情、创建、编辑、删除、下载 ⚙️ 系统设置:查看详情、编辑 更加直观、易读,用户可以快速了解权限分布情况
This commit is contained in:
@@ -65,27 +65,25 @@ class ViewRole extends ViewRecord
|
|||||||
|
|
||||||
Infolists\Components\Section::make('权限列表')
|
Infolists\Components\Section::make('权限列表')
|
||||||
->schema([
|
->schema([
|
||||||
Infolists\Components\RepeatableEntry::make('permissions')
|
Infolists\Components\TextEntry::make('grouped_permissions')
|
||||||
->label('')
|
->label('')
|
||||||
->schema([
|
->getStateUsing(function ($record) {
|
||||||
Infolists\Components\TextEntry::make('name')
|
// 按模块分组权限
|
||||||
->label('权限')
|
$permissions = $record->permissions;
|
||||||
->badge()
|
|
||||||
->formatStateUsing(function (string $state): string {
|
if ($permissions->isEmpty()) {
|
||||||
// 格式化权限名称
|
return '该角色暂无权限';
|
||||||
$parts = explode('.', $state);
|
}
|
||||||
$module = $parts[0] ?? '';
|
|
||||||
$action = $parts[1] ?? '';
|
|
||||||
|
|
||||||
$moduleNames = [
|
$moduleNames = [
|
||||||
'document' => '文档管理',
|
'document' => '📄 文档管理',
|
||||||
'system-setting' => '系统设置',
|
'system-setting' => '⚙️ 系统设置',
|
||||||
'activity-log' => '操作日志',
|
'activity-log' => '📋 操作日志',
|
||||||
'terminal' => '终端管理',
|
'terminal' => '🖥️ 终端管理',
|
||||||
'sop-template' => 'SOP模板',
|
'sop-template' => '📝 SOP模板',
|
||||||
'group' => '分组管理',
|
'group' => '👥 分组管理',
|
||||||
'user' => '用户管理',
|
'user' => '👤 用户管理',
|
||||||
'role' => '角色管理',
|
'role' => '🛡️ 角色管理',
|
||||||
];
|
];
|
||||||
|
|
||||||
$actionNames = [
|
$actionNames = [
|
||||||
@@ -101,15 +99,31 @@ class ViewRole extends ViewRecord
|
|||||||
'archive' => '归档',
|
'archive' => '归档',
|
||||||
];
|
];
|
||||||
|
|
||||||
$moduleName = $moduleNames[$module] ?? $module;
|
$grouped = $permissions->groupBy(function ($permission) {
|
||||||
$actionName = $actionNames[$action] ?? $action;
|
return explode('.', $permission->name)[0];
|
||||||
|
});
|
||||||
|
|
||||||
return "{$moduleName} - {$actionName}";
|
$result = [];
|
||||||
}),
|
foreach ($grouped as $module => $perms) {
|
||||||
])
|
$moduleName = $moduleNames[$module] ?? $module;
|
||||||
->columns(3)
|
$actions = $perms->map(function ($perm) use ($actionNames) {
|
||||||
->grid(3),
|
$action = explode('.', $perm->name)[1] ?? '';
|
||||||
|
return $actionNames[$action] ?? $action;
|
||||||
|
})->join('、');
|
||||||
|
|
||||||
|
$result[] = "<strong>{$moduleName}</strong>:{$actions}";
|
||||||
|
}
|
||||||
|
|
||||||
|
return implode('<br><br>', $result);
|
||||||
|
})
|
||||||
|
->html()
|
||||||
|
->columnSpanFull(),
|
||||||
])
|
])
|
||||||
|
->description(fn ($record) =>
|
||||||
|
$record->name === 'super-admin'
|
||||||
|
? 'super-admin 角色拥有系统所有权限'
|
||||||
|
: '该角色拥有以下权限'
|
||||||
|
)
|
||||||
->collapsible(),
|
->collapsible(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,12 +72,12 @@ class ViewUser extends ViewRecord
|
|||||||
->schema([
|
->schema([
|
||||||
Infolists\Components\TextEntry::make('all_permissions')
|
Infolists\Components\TextEntry::make('all_permissions')
|
||||||
->label('所有权限')
|
->label('所有权限')
|
||||||
->state(function ($record) {
|
->getStateUsing(function ($record) {
|
||||||
// 获取所有权限(角色权限 + 直接权限)
|
// 获取所有权限(角色权限 + 直接权限)
|
||||||
$permissions = $record->getAllPermissions();
|
$permissions = $record->getAllPermissions();
|
||||||
|
|
||||||
if ($permissions->isEmpty()) {
|
if ($permissions->isEmpty()) {
|
||||||
return '无权限';
|
return '该用户暂无权限';
|
||||||
}
|
}
|
||||||
|
|
||||||
// 按模块分组
|
// 按模块分组
|
||||||
@@ -86,77 +86,99 @@ class ViewUser extends ViewRecord
|
|||||||
});
|
});
|
||||||
|
|
||||||
$moduleNames = [
|
$moduleNames = [
|
||||||
'document' => '文档管理',
|
'document' => '📄 文档管理',
|
||||||
'sop' => 'SOP模板',
|
'system-setting' => '⚙️ 系统设置',
|
||||||
'terminal' => '终端管理',
|
'activity-log' => '📋 操作日志',
|
||||||
'user' => '用户管理',
|
'terminal' => '🖥️ 终端管理',
|
||||||
'role' => '角色管理',
|
'sop-template' => '📝 SOP模板',
|
||||||
'group' => '分组管理',
|
'group' => '👥 分组管理',
|
||||||
'system' => '系统设置',
|
'user' => '👤 用户管理',
|
||||||
'activity' => '操作日志',
|
'role' => '🛡️ 角色管理',
|
||||||
];
|
];
|
||||||
|
|
||||||
$actionNames = [
|
$actionNames = [
|
||||||
'view' => '查看',
|
'viewAny' => '查看列表',
|
||||||
|
'view' => '查看详情',
|
||||||
'create' => '创建',
|
'create' => '创建',
|
||||||
'update' => '编辑',
|
'update' => '编辑',
|
||||||
'delete' => '删除',
|
'delete' => '删除',
|
||||||
|
'download' => '下载',
|
||||||
'export' => '导出',
|
'export' => '导出',
|
||||||
'import' => '导入',
|
'sync' => '同步',
|
||||||
'publish' => '发布',
|
'publish' => '发布',
|
||||||
'archive' => '归档',
|
'archive' => '归档',
|
||||||
'download' => '下载',
|
|
||||||
'sync' => '同步',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
$result = [];
|
$result = [];
|
||||||
foreach ($grouped as $module => $perms) {
|
foreach ($grouped as $module => $perms) {
|
||||||
$moduleName = $moduleNames[$module] ?? $module;
|
$moduleName = $moduleNames[$module] ?? $module;
|
||||||
$actions = $perms->map(function ($perm) use ($actionNames) {
|
$actions = $perms->map(function ($perm) use ($actionNames) {
|
||||||
$parts = explode('.', $perm->name);
|
$action = explode('.', $perm->name)[1] ?? '';
|
||||||
$action = $parts[1] ?? '';
|
|
||||||
return $actionNames[$action] ?? $action;
|
return $actionNames[$action] ?? $action;
|
||||||
})->join('、');
|
})->join('、');
|
||||||
$result[] = "{$moduleName}:{$actions}";
|
|
||||||
|
$result[] = "<strong>{$moduleName}</strong>:{$actions}";
|
||||||
}
|
}
|
||||||
|
|
||||||
return implode("\n", $result);
|
return implode('<br><br>', $result);
|
||||||
})
|
})
|
||||||
->columnSpanFull()
|
->html()
|
||||||
->placeholder('无权限'),
|
->columnSpanFull(),
|
||||||
|
|
||||||
Infolists\Components\TextEntry::make('direct_permissions')
|
Infolists\Components\TextEntry::make('direct_permissions')
|
||||||
->label('直接权限')
|
->label('直接权限(仅显示直接分配的权限)')
|
||||||
->state(function ($record) {
|
->getStateUsing(function ($record) {
|
||||||
$permissions = $record->permissions;
|
$permissions = $record->permissions;
|
||||||
|
|
||||||
if ($permissions->isEmpty()) {
|
if ($permissions->isEmpty()) {
|
||||||
return '无直接权限';
|
return '无直接权限';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 按模块分组
|
||||||
|
$grouped = $permissions->groupBy(function ($permission) {
|
||||||
|
return explode('.', $permission->name)[0];
|
||||||
|
});
|
||||||
|
|
||||||
|
$moduleNames = [
|
||||||
|
'document' => '📄 文档管理',
|
||||||
|
'system-setting' => '⚙️ 系统设置',
|
||||||
|
'activity-log' => '📋 操作日志',
|
||||||
|
'terminal' => '🖥️ 终端管理',
|
||||||
|
'sop-template' => '📝 SOP模板',
|
||||||
|
'group' => '👥 分组管理',
|
||||||
|
'user' => '👤 用户管理',
|
||||||
|
'role' => '🛡️ 角色管理',
|
||||||
|
];
|
||||||
|
|
||||||
$actionNames = [
|
$actionNames = [
|
||||||
'view' => '查看',
|
'viewAny' => '查看列表',
|
||||||
|
'view' => '查看详情',
|
||||||
'create' => '创建',
|
'create' => '创建',
|
||||||
'update' => '编辑',
|
'update' => '编辑',
|
||||||
'delete' => '删除',
|
'delete' => '删除',
|
||||||
|
'download' => '下载',
|
||||||
'export' => '导出',
|
'export' => '导出',
|
||||||
'import' => '导入',
|
'sync' => '同步',
|
||||||
'publish' => '发布',
|
'publish' => '发布',
|
||||||
'archive' => '归档',
|
'archive' => '归档',
|
||||||
'download' => '下载',
|
|
||||||
'sync' => '同步',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
return $permissions->map(function ($perm) use ($actionNames) {
|
$result = [];
|
||||||
$parts = explode('.', $perm->name);
|
foreach ($grouped as $module => $perms) {
|
||||||
$action = $parts[1] ?? '';
|
$moduleName = $moduleNames[$module] ?? $module;
|
||||||
|
$actions = $perms->map(function ($perm) use ($actionNames) {
|
||||||
|
$action = explode('.', $perm->name)[1] ?? '';
|
||||||
return $actionNames[$action] ?? $action;
|
return $actionNames[$action] ?? $action;
|
||||||
})->join('、');
|
})->join('、');
|
||||||
|
|
||||||
|
$result[] = "<strong>{$moduleName}</strong>:{$actions}";
|
||||||
|
}
|
||||||
|
|
||||||
|
return implode('<br><br>', $result);
|
||||||
})
|
})
|
||||||
->badge()
|
->html()
|
||||||
->color('info')
|
|
||||||
->columnSpanFull()
|
->columnSpanFull()
|
||||||
->placeholder('无直接权限'),
|
->color('info'),
|
||||||
]),
|
]),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user