feat(权限): 优化权限列表显示方式,按功能模块分组
- RoleResource: 使用 Tabs 组件按模块分组显示权限 - 每个模块一个标签页,带有对应的图标 - 权限名称简化为操作名称(如:查看详情、创建、编辑等) - 支持批量选择和取消选择 - super-admin 角色的权限不可修改 - UserResource: 同样使用 Tabs 组件优化直接权限显示 - 与角色权限保持一致的显示风格 - 更清晰地展示权限的模块归属 - 添加 getPermissionTabs() 方法统一生成权限标签页 - 模块包括:文档管理、系统设置、操作日志、终端管理、SOP模板、分组管理、用户管理、角色管理 优化后的界面更加清晰易用,用户可以快速找到需要的权限模块
This commit is contained in:
@@ -35,6 +35,76 @@ class RoleResource extends Resource
|
|||||||
return auth()->user()?->can('role.viewAny') ?? false;
|
return auth()->user()?->can('role.viewAny') ?? false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取权限分组标签页
|
||||||
|
*/
|
||||||
|
protected static function getPermissionTabs(): array
|
||||||
|
{
|
||||||
|
// 模块名称和图标映射
|
||||||
|
$moduleConfig = [
|
||||||
|
'document' => ['name' => '文档管理', 'icon' => 'heroicon-o-document-text'],
|
||||||
|
'system-setting' => ['name' => '系统设置', 'icon' => 'heroicon-o-cog-6-tooth'],
|
||||||
|
'activity-log' => ['name' => '操作日志', 'icon' => 'heroicon-o-clipboard-document-list'],
|
||||||
|
'terminal' => ['name' => '终端管理', 'icon' => 'heroicon-o-computer-desktop'],
|
||||||
|
'sop-template' => ['name' => 'SOP模板', 'icon' => 'heroicon-o-document-text'],
|
||||||
|
'group' => ['name' => '分组管理', 'icon' => 'heroicon-o-user-group'],
|
||||||
|
'user' => ['name' => '用户管理', 'icon' => 'heroicon-o-users'],
|
||||||
|
'role' => ['name' => '角色管理', 'icon' => 'heroicon-o-shield-check'],
|
||||||
|
];
|
||||||
|
|
||||||
|
// 操作名称映射
|
||||||
|
$actionNames = [
|
||||||
|
'viewAny' => '查看列表',
|
||||||
|
'view' => '查看详情',
|
||||||
|
'create' => '创建',
|
||||||
|
'update' => '编辑',
|
||||||
|
'delete' => '删除',
|
||||||
|
'download' => '下载',
|
||||||
|
'export' => '导出',
|
||||||
|
'sync' => '同步',
|
||||||
|
'publish' => '发布',
|
||||||
|
'archive' => '归档',
|
||||||
|
];
|
||||||
|
|
||||||
|
// 按模块分组权限
|
||||||
|
$groupedPermissions = Permission::all()
|
||||||
|
->groupBy(function ($permission) {
|
||||||
|
return explode('.', $permission->name)[0];
|
||||||
|
});
|
||||||
|
|
||||||
|
$tabs = [];
|
||||||
|
|
||||||
|
foreach ($groupedPermissions as $module => $permissions) {
|
||||||
|
$config = $moduleConfig[$module] ?? ['name' => $module, 'icon' => 'heroicon-o-square-3-stack-3d'];
|
||||||
|
|
||||||
|
// 构建该模块的权限选项
|
||||||
|
$options = $permissions->mapWithKeys(function ($permission) use ($actionNames) {
|
||||||
|
$action = explode('.', $permission->name)[1] ?? '';
|
||||||
|
$actionName = $actionNames[$action] ?? $action;
|
||||||
|
return [$permission->name => $actionName];
|
||||||
|
})->toArray();
|
||||||
|
|
||||||
|
$tabs[] = Forms\Components\Tabs\Tab::make($config['name'])
|
||||||
|
->icon($config['icon'])
|
||||||
|
->schema([
|
||||||
|
Forms\Components\CheckboxList::make('permissions')
|
||||||
|
->label('')
|
||||||
|
->relationship('permissions', 'name')
|
||||||
|
->options($options)
|
||||||
|
->columns(2)
|
||||||
|
->bulkToggleable()
|
||||||
|
->disabled(fn (?Role $record): bool => $record?->name === 'super-admin')
|
||||||
|
->helperText(fn (?Role $record): string =>
|
||||||
|
$record?->name === 'super-admin'
|
||||||
|
? 'super-admin 角色拥有所有权限,不可修改'
|
||||||
|
: '选择该模块的权限'
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $tabs;
|
||||||
|
}
|
||||||
|
|
||||||
public static function form(Form $form): Form
|
public static function form(Form $form): Form
|
||||||
{
|
{
|
||||||
return $form
|
return $form
|
||||||
@@ -67,61 +137,9 @@ class RoleResource extends Resource
|
|||||||
|
|
||||||
Forms\Components\Section::make('权限配置')
|
Forms\Components\Section::make('权限配置')
|
||||||
->schema([
|
->schema([
|
||||||
Forms\Components\CheckboxList::make('permissions')
|
Forms\Components\Tabs::make('权限分组')
|
||||||
->label('权限')
|
->tabs(self::getPermissionTabs())
|
||||||
->relationship('permissions', 'name')
|
->columnSpanFull(),
|
||||||
->options(function () {
|
|
||||||
return Permission::all()
|
|
||||||
->groupBy(function ($permission) {
|
|
||||||
// 按模块分组(取权限名称的第一部分)
|
|
||||||
return explode('.', $permission->name)[0];
|
|
||||||
})
|
|
||||||
->map(function ($permissions, $module) {
|
|
||||||
// 模块名称映射
|
|
||||||
$moduleNames = [
|
|
||||||
'document' => '文档管理',
|
|
||||||
'system-setting' => '系统设置',
|
|
||||||
'activity-log' => '操作日志',
|
|
||||||
'terminal' => '终端管理',
|
|
||||||
'sop-template' => 'SOP模板',
|
|
||||||
'group' => '分组管理',
|
|
||||||
'user' => '用户管理',
|
|
||||||
'role' => '角色管理',
|
|
||||||
];
|
|
||||||
|
|
||||||
$moduleName = $moduleNames[$module] ?? $module;
|
|
||||||
|
|
||||||
return $permissions->pluck('name', 'name')
|
|
||||||
->mapWithKeys(function ($name) use ($moduleName) {
|
|
||||||
// 操作名称映射
|
|
||||||
$action = explode('.', $name)[1] ?? '';
|
|
||||||
$actionNames = [
|
|
||||||
'viewAny' => '查看列表',
|
|
||||||
'view' => '查看详情',
|
|
||||||
'create' => '创建',
|
|
||||||
'update' => '编辑',
|
|
||||||
'delete' => '删除',
|
|
||||||
'download' => '下载',
|
|
||||||
'export' => '导出',
|
|
||||||
'sync' => '同步',
|
|
||||||
'publish' => '发布',
|
|
||||||
'archive' => '归档',
|
|
||||||
];
|
|
||||||
|
|
||||||
$actionName = $actionNames[$action] ?? $action;
|
|
||||||
$label = "{$moduleName} - {$actionName}";
|
|
||||||
|
|
||||||
return [$name => $label];
|
|
||||||
});
|
|
||||||
})
|
|
||||||
->flatten()
|
|
||||||
->toArray();
|
|
||||||
})
|
|
||||||
->columns(3)
|
|
||||||
->searchable()
|
|
||||||
->bulkToggleable()
|
|
||||||
->helperText('选择该角色拥有的权限')
|
|
||||||
->disabled(fn (?Role $record): bool => $record?->name === 'super-admin'),
|
|
||||||
])
|
])
|
||||||
->description('配置角色的权限,super-admin 角色拥有所有权限且不可修改'),
|
->description('配置角色的权限,super-admin 角色拥有所有权限且不可修改'),
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -35,6 +35,71 @@ class UserResource extends Resource
|
|||||||
return auth()->user()?->can('user.view') ?? false;
|
return auth()->user()?->can('user.view') ?? false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取权限分组标签页
|
||||||
|
*/
|
||||||
|
protected static function getPermissionTabs(): array
|
||||||
|
{
|
||||||
|
// 模块名称和图标映射
|
||||||
|
$moduleConfig = [
|
||||||
|
'document' => ['name' => '文档管理', 'icon' => 'heroicon-o-document-text'],
|
||||||
|
'system-setting' => ['name' => '系统设置', 'icon' => 'heroicon-o-cog-6-tooth'],
|
||||||
|
'activity-log' => ['name' => '操作日志', 'icon' => 'heroicon-o-clipboard-document-list'],
|
||||||
|
'terminal' => ['name' => '终端管理', 'icon' => 'heroicon-o-computer-desktop'],
|
||||||
|
'sop-template' => ['name' => 'SOP模板', 'icon' => 'heroicon-o-document-text'],
|
||||||
|
'group' => ['name' => '分组管理', 'icon' => 'heroicon-o-user-group'],
|
||||||
|
'user' => ['name' => '用户管理', 'icon' => 'heroicon-o-users'],
|
||||||
|
'role' => ['name' => '角色管理', 'icon' => 'heroicon-o-shield-check'],
|
||||||
|
];
|
||||||
|
|
||||||
|
// 操作名称映射
|
||||||
|
$actionNames = [
|
||||||
|
'viewAny' => '查看列表',
|
||||||
|
'view' => '查看详情',
|
||||||
|
'create' => '创建',
|
||||||
|
'update' => '编辑',
|
||||||
|
'delete' => '删除',
|
||||||
|
'download' => '下载',
|
||||||
|
'export' => '导出',
|
||||||
|
'sync' => '同步',
|
||||||
|
'publish' => '发布',
|
||||||
|
'archive' => '归档',
|
||||||
|
];
|
||||||
|
|
||||||
|
// 按模块分组权限
|
||||||
|
$groupedPermissions = \Spatie\Permission\Models\Permission::all()
|
||||||
|
->groupBy(function ($permission) {
|
||||||
|
return explode('.', $permission->name)[0];
|
||||||
|
});
|
||||||
|
|
||||||
|
$tabs = [];
|
||||||
|
|
||||||
|
foreach ($groupedPermissions as $module => $permissions) {
|
||||||
|
$config = $moduleConfig[$module] ?? ['name' => $module, 'icon' => 'heroicon-o-square-3-stack-3d'];
|
||||||
|
|
||||||
|
// 构建该模块的权限选项
|
||||||
|
$options = $permissions->mapWithKeys(function ($permission) use ($actionNames) {
|
||||||
|
$action = explode('.', $permission->name)[1] ?? '';
|
||||||
|
$actionName = $actionNames[$action] ?? $action;
|
||||||
|
return [$permission->name => $actionName];
|
||||||
|
})->toArray();
|
||||||
|
|
||||||
|
$tabs[] = Forms\Components\Tabs\Tab::make($config['name'])
|
||||||
|
->icon($config['icon'])
|
||||||
|
->schema([
|
||||||
|
Forms\Components\CheckboxList::make('permissions')
|
||||||
|
->label('')
|
||||||
|
->relationship('permissions', 'name')
|
||||||
|
->options($options)
|
||||||
|
->columns(2)
|
||||||
|
->bulkToggleable()
|
||||||
|
->helperText('选择该模块的直接权限(会叠加到角色权限之上)'),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $tabs;
|
||||||
|
}
|
||||||
|
|
||||||
public static function form(Form $form): Form
|
public static function form(Form $form): Form
|
||||||
{
|
{
|
||||||
return $form
|
return $form
|
||||||
@@ -86,53 +151,9 @@ class UserResource extends Resource
|
|||||||
Forms\Components\Section::make('直接权限')
|
Forms\Components\Section::make('直接权限')
|
||||||
->description('为用户分配额外的权限,这些权限会叠加到角色权限之上')
|
->description('为用户分配额外的权限,这些权限会叠加到角色权限之上')
|
||||||
->schema([
|
->schema([
|
||||||
Forms\Components\CheckboxList::make('permissions')
|
Forms\Components\Tabs::make('权限分组')
|
||||||
->label('权限列表')
|
->tabs(self::getPermissionTabs())
|
||||||
->relationship('permissions', 'name')
|
->columnSpanFull(),
|
||||||
->columns(3)
|
|
||||||
->gridDirection('row')
|
|
||||||
->options(function () {
|
|
||||||
return \Spatie\Permission\Models\Permission::all()
|
|
||||||
->groupBy(function ($permission) {
|
|
||||||
return explode('.', $permission->name)[0];
|
|
||||||
})
|
|
||||||
->map(function ($permissions, $module) {
|
|
||||||
$moduleNames = [
|
|
||||||
'document' => '文档管理',
|
|
||||||
'sop' => 'SOP模板',
|
|
||||||
'terminal' => '终端管理',
|
|
||||||
'user' => '用户管理',
|
|
||||||
'role' => '角色管理',
|
|
||||||
'group' => '分组管理',
|
|
||||||
'system' => '系统设置',
|
|
||||||
'activity' => '操作日志',
|
|
||||||
];
|
|
||||||
return $permissions->pluck('name', 'name')
|
|
||||||
->mapWithKeys(function ($name) use ($moduleNames) {
|
|
||||||
$parts = explode('.', $name);
|
|
||||||
$module = $parts[0];
|
|
||||||
$action = $parts[1] ?? '';
|
|
||||||
$actionNames = [
|
|
||||||
'view' => '查看',
|
|
||||||
'create' => '创建',
|
|
||||||
'update' => '编辑',
|
|
||||||
'delete' => '删除',
|
|
||||||
'export' => '导出',
|
|
||||||
'import' => '导入',
|
|
||||||
'publish' => '发布',
|
|
||||||
'archive' => '归档',
|
|
||||||
'download' => '下载',
|
|
||||||
'sync' => '同步',
|
|
||||||
];
|
|
||||||
$label = ($moduleNames[$module] ?? $module) . ' - ' . ($actionNames[$action] ?? $action);
|
|
||||||
return [$name => $label];
|
|
||||||
});
|
|
||||||
})
|
|
||||||
->flatten()
|
|
||||||
->toArray();
|
|
||||||
})
|
|
||||||
->searchable()
|
|
||||||
->bulkToggleable(),
|
|
||||||
])
|
])
|
||||||
->collapsible()
|
->collapsible()
|
||||||
->collapsed(),
|
->collapsed(),
|
||||||
|
|||||||
Reference in New Issue
Block a user