优化更新

This commit is contained in:
2026-02-09 22:51:11 +08:00
parent 9939680942
commit adf7457502
12 changed files with 695 additions and 298 deletions

View File

@@ -55,31 +55,48 @@ class AuthSeeder extends Seeder
private function createPermissions(): void
{
$permissions = [
// 系统管理
// 首页顶级菜单
[
'name' => '系统管理',
'code' => 'system',
'title' => '首页',
'name' => 'home',
'type' => 'menu',
'parent_id' => 0,
'route' => '/system',
'component' => 'Layout',
'path' => '/home',
'component' => null,
'meta' => json_encode([
'icon' => 'Setting',
'icon' => 'Dashboard',
'hidden' => false,
'hiddenBreadcrumb' => false,
'affix' => null,
'affix' => true,
]),
'sort' => 1,
'status' => 1,
],
// 用户管理
// 仪表盘
[
'name' => '用户管理',
'code' => 'system.users',
'title' => '仪表盘',
'name' => 'home.dashboard',
'type' => 'menu',
'parent_id' => 0,
'route' => '/system/users',
'component' => 'system/users/index',
'parent_id' => 0, // 稍后更新为首页菜单的ID
'path' => '/dashboard',
'component' => 'home/index',
'meta' => json_encode([
'icon' => 'DataLine',
'hidden' => false,
'hiddenBreadcrumb' => false,
'affix' => true,
]),
'sort' => 1,
'status' => 1,
],
// 个人中心
[
'title' => '个人中心',
'name' => 'home.profile',
'type' => 'menu',
'parent_id' => 0, // 稍后更新为首页菜单的ID
'path' => '/ucenter',
'component' => 'ucenter/index',
'meta' => json_encode([
'icon' => 'User',
'hidden' => false,
@@ -89,77 +106,143 @@ class AuthSeeder extends Seeder
'status' => 1,
],
[
'name' => '查看用户',
'code' => 'system.users.view',
'title' => '查看个人信息',
'name' => 'home.profile.view',
'type' => 'button',
'parent_id' => 0,
'route' => 'admin.users.index',
'parent_id' => 0, // 稍后更新为个人中心菜单的ID
'path' => null,
'component' => null,
'meta' => null,
'sort' => 1,
'status' => 1,
],
[
'name' => '创建用户',
'code' => 'system.users.create',
'title' => '编辑个人信息',
'name' => 'home.profile.update',
'type' => 'button',
'parent_id' => 0,
'route' => 'admin.users.store',
'parent_id' => 0, // 稍后更新为个人中心菜单的ID
'path' => null,
'component' => null,
'meta' => null,
'sort' => 2,
'status' => 1,
],
[
'name' => '编辑用户',
'code' => 'system.users.update',
'title' => '修改密码',
'name' => 'home.profile.change-password',
'type' => 'button',
'parent_id' => 0, // 稍后更新为个人中心菜单的ID
'path' => null,
'component' => null,
'meta' => null,
'sort' => 3,
'status' => 1,
],
// 权限顶级菜单
[
'title' => '权限',
'name' => 'auth',
'type' => 'menu',
'parent_id' => 0,
'route' => 'admin.users.update',
'path' => '/auth',
'component' => null,
'meta' => json_encode([
'icon' => 'User',
'hidden' => false,
'hiddenBreadcrumb' => false,
]),
'sort' => 2,
'status' => 1,
],
// 用户管理
[
'title' => '用户管理',
'name' => 'auth.users',
'type' => 'menu',
'parent_id' => 0, // 稍后更新为权限菜单的ID
'path' => '/auth/users',
'component' => 'auth/users/index',
'meta' => json_encode([
'icon' => 'UserOutlined',
'hidden' => false,
'hiddenBreadcrumb' => false,
]),
'sort' => 1,
'status' => 1,
],
[
'title' => '查看用户',
'name' => 'auth.users.view',
'type' => 'button',
'parent_id' => 0, // 稍后更新为用户管理菜单的ID
'path' => 'admin.users.index',
'component' => null,
'meta' => null,
'sort' => 1,
'status' => 1,
],
[
'title' => '创建用户',
'name' => 'auth.users.create',
'type' => 'button',
'parent_id' => 0, // 稍后更新为用户管理菜单的ID
'path' => 'admin.users.store',
'component' => null,
'meta' => null,
'sort' => 2,
'status' => 1,
],
[
'title' => '编辑用户',
'name' => 'auth.users.update',
'type' => 'button',
'parent_id' => 0, // 稍后更新为用户管理菜单的ID
'path' => 'admin.users.update',
'component' => null,
'meta' => null,
'sort' => 3,
'status' => 1,
],
[
'name' => '删除用户',
'code' => 'system.users.delete',
'title' => '删除用户',
'name' => 'auth.users.delete',
'type' => 'button',
'parent_id' => 0,
'route' => 'admin.users.destroy',
'parent_id' => 0, // 稍后更新为用户管理菜单的ID
'path' => 'admin.users.destroy',
'component' => null,
'meta' => null,
'sort' => 4,
'status' => 1,
],
[
'name' => '批量删除用户',
'code' => 'system.users.batch-delete',
'title' => '批量删除用户',
'name' => 'auth.users.batch-delete',
'type' => 'button',
'parent_id' => 0,
'route' => 'admin.users.batch-delete',
'parent_id' => 0, // 稍后更新为用户管理菜单的ID
'path' => 'admin.users.batch-delete',
'component' => null,
'meta' => null,
'sort' => 5,
'status' => 1,
],
[
'name' => '导出用户',
'code' => 'system.users.export',
'title' => '导出用户',
'name' => 'auth.users.export',
'type' => 'button',
'parent_id' => 0,
'route' => 'admin.users.export',
'parent_id' => 0, // 稍后更新为用户管理菜单的ID
'path' => 'admin.users.export',
'component' => null,
'meta' => null,
'sort' => 6,
'status' => 1,
],
[
'name' => '导入用户',
'code' => 'system.users.import',
'title' => '导入用户',
'name' => 'auth.users.import',
'type' => 'button',
'parent_id' => 0,
'route' => 'admin.users.import',
'parent_id' => 0, // 稍后更新为用户管理菜单的ID
'path' => 'admin.users.import',
'component' => null,
'meta' => null,
'sort' => 7,
@@ -167,81 +250,81 @@ class AuthSeeder extends Seeder
],
// 角色管理
[
'name' => '角色管理',
'code' => 'system.roles',
'title' => '角色管理',
'name' => 'auth.roles',
'type' => 'menu',
'parent_id' => 0,
'route' => '/system/roles',
'component' => 'system/roles/index',
'parent_id' => 0, // 稍后更新为权限菜单的ID
'path' => '/auth/roles',
'component' => 'auth/roles/index',
'meta' => json_encode([
'icon' => 'UserFilled',
'hidden' => false,
'hiddenBreadcrumb' => false,
]),
'sort' => 3,
'sort' => 2,
'status' => 1,
],
[
'name' => '查看角色',
'code' => 'system.roles.view',
'title' => '查看角色',
'name' => 'auth.roles.view',
'type' => 'button',
'parent_id' => 0,
'route' => 'admin.roles.index',
'parent_id' => 0, // 稍后更新为角色管理菜单的ID
'path' => 'admin.roles.index',
'component' => null,
'meta' => null,
'sort' => 1,
'status' => 1,
],
[
'name' => '创建角色',
'code' => 'system.roles.create',
'title' => '创建角色',
'name' => 'auth.roles.create',
'type' => 'button',
'parent_id' => 0,
'route' => 'admin.roles.store',
'parent_id' => 0, // 稍后更新为角色管理菜单的ID
'path' => 'admin.roles.store',
'component' => null,
'meta' => null,
'sort' => 2,
'status' => 1,
],
[
'name' => '编辑角色',
'code' => 'system.roles.update',
'title' => '编辑角色',
'name' => 'auth.roles.update',
'type' => 'button',
'parent_id' => 0,
'route' => 'admin.roles.update',
'parent_id' => 0, // 稍后更新为角色管理菜单的ID
'path' => 'admin.roles.update',
'component' => null,
'meta' => null,
'sort' => 3,
'status' => 1,
],
[
'name' => '删除角色',
'code' => 'system.roles.delete',
'title' => '删除角色',
'name' => 'auth.roles.delete',
'type' => 'button',
'parent_id' => 0,
'route' => 'admin.roles.destroy',
'parent_id' => 0, // 稍后更新为角色管理菜单的ID
'path' => 'admin.roles.destroy',
'component' => null,
'meta' => null,
'sort' => 4,
'status' => 1,
],
[
'name' => '批量删除角色',
'code' => 'system.roles.batch-delete',
'title' => '批量删除角色',
'name' => 'auth.roles.batch-delete',
'type' => 'button',
'parent_id' => 0,
'route' => 'admin.roles.batch-delete',
'parent_id' => 0, // 稍后更新为角色管理菜单的ID
'path' => 'admin.roles.batch-delete',
'component' => null,
'meta' => null,
'sort' => 5,
'status' => 1,
],
[
'name' => '分配权限',
'code' => 'system.roles.assign-permissions',
'title' => '分配权限',
'name' => 'auth.roles.assign-permissions',
'type' => 'button',
'parent_id' => 0,
'route' => 'admin.roles.assign-permissions',
'parent_id' => 0, // 稍后更新为角色管理菜单的ID
'path' => 'admin.roles.assign-permissions',
'component' => null,
'meta' => null,
'sort' => 6,
@@ -249,70 +332,70 @@ class AuthSeeder extends Seeder
],
// 权限管理
[
'name' => '权限管理',
'code' => 'system.permissions',
'title' => '权限管理',
'name' => 'auth.permissions',
'type' => 'menu',
'parent_id' => 0,
'route' => '/system/permissions',
'component' => 'system/permissions/index',
'parent_id' => 0, // 稍后更新为权限菜单的ID
'path' => '/auth/permissions',
'component' => 'auth/permissions/index',
'meta' => json_encode([
'icon' => 'Lock',
'hidden' => false,
'hiddenBreadcrumb' => false,
]),
'sort' => 4,
'sort' => 3,
'status' => 1,
],
[
'name' => '查看权限',
'code' => 'system.permissions.view',
'title' => '查看权限',
'name' => 'auth.permissions.view',
'type' => 'button',
'parent_id' => 0,
'route' => 'admin.permissions.index',
'parent_id' => 0, // 稍后更新为权限管理菜单的ID
'path' => 'admin.permissions.index',
'component' => null,
'meta' => null,
'sort' => 1,
'status' => 1,
],
[
'name' => '创建权限',
'code' => 'system.permissions.create',
'title' => '创建权限',
'name' => 'auth.permissions.create',
'type' => 'button',
'parent_id' => 0,
'route' => 'admin.permissions.store',
'parent_id' => 0, // 稍后更新为权限管理菜单的ID
'path' => 'admin.permissions.store',
'component' => null,
'meta' => null,
'sort' => 2,
'status' => 1,
],
[
'name' => '编辑权限',
'code' => 'system.permissions.update',
'title' => '编辑权限',
'name' => 'auth.permissions.update',
'type' => 'button',
'parent_id' => 0,
'route' => 'admin.permissions.update',
'parent_id' => 0, // 稍后更新为权限管理菜单的ID
'path' => 'admin.permissions.update',
'component' => null,
'meta' => null,
'sort' => 3,
'status' => 1,
],
[
'name' => '删除权限',
'code' => 'system.permissions.delete',
'title' => '删除权限',
'name' => 'auth.permissions.delete',
'type' => 'button',
'parent_id' => 0,
'route' => 'admin.permissions.destroy',
'parent_id' => 0, // 稍后更新为权限管理菜单的ID
'path' => 'admin.permissions.destroy',
'component' => null,
'meta' => null,
'sort' => 4,
'status' => 1,
],
[
'name' => '批量删除权限',
'code' => 'system.permissions.batch-delete',
'title' => '批量删除权限',
'name' => 'auth.permissions.batch-delete',
'type' => 'button',
'parent_id' => 0,
'route' => 'admin.permissions.batch-delete',
'parent_id' => 0, // 稍后更新为权限管理菜单的ID
'path' => 'admin.permissions.batch-delete',
'component' => null,
'meta' => null,
'sort' => 5,
@@ -320,70 +403,70 @@ class AuthSeeder extends Seeder
],
// 部门管理
[
'name' => '部门管理',
'code' => 'system.departments',
'title' => '部门管理',
'name' => 'auth.departments',
'type' => 'menu',
'parent_id' => 0,
'route' => '/system/departments',
'component' => 'system/departments/index',
'parent_id' => 0, // 稍后更新为权限菜单的ID
'path' => '/auth/departments',
'component' => 'auth/departments/index',
'meta' => json_encode([
'icon' => 'OfficeBuilding',
'hidden' => false,
'hiddenBreadcrumb' => false,
]),
'sort' => 5,
'sort' => 4,
'status' => 1,
],
[
'name' => '查看部门',
'code' => 'system.departments.view',
'title' => '查看部门',
'name' => 'auth.departments.view',
'type' => 'button',
'parent_id' => 0,
'route' => 'admin.departments.index',
'parent_id' => 0, // 稍后更新为部门管理菜单的ID
'path' => 'admin.departments.index',
'component' => null,
'meta' => null,
'sort' => 1,
'status' => 1,
],
[
'name' => '创建部门',
'code' => 'system.departments.create',
'title' => '创建部门',
'name' => 'auth.departments.create',
'type' => 'button',
'parent_id' => 0,
'route' => 'admin.departments.store',
'parent_id' => 0, // 稍后更新为部门管理菜单的ID
'path' => 'admin.departments.store',
'component' => null,
'meta' => null,
'sort' => 2,
'status' => 1,
],
[
'name' => '编辑部门',
'code' => 'system.departments.update',
'title' => '编辑部门',
'name' => 'auth.departments.update',
'type' => 'button',
'parent_id' => 0,
'route' => 'admin.departments.update',
'parent_id' => 0, // 稍后更新为部门管理菜单的ID
'path' => 'admin.departments.update',
'component' => null,
'meta' => null,
'sort' => 3,
'status' => 1,
],
[
'name' => '删除部门',
'code' => 'system.departments.delete',
'title' => '删除部门',
'name' => 'auth.departments.delete',
'type' => 'button',
'parent_id' => 0,
'route' => 'admin.departments.destroy',
'parent_id' => 0, // 稍后更新为部门管理菜单的ID
'path' => 'admin.departments.destroy',
'component' => null,
'meta' => null,
'sort' => 4,
'status' => 1,
],
[
'name' => '批量删除部门',
'code' => 'system.departments.batch-delete',
'title' => '批量删除部门',
'name' => 'auth.departments.batch-delete',
'type' => 'button',
'parent_id' => 0,
'route' => 'admin.departments.batch-delete',
'parent_id' => 0, // 稍后更新为部门管理菜单的ID
'path' => 'admin.departments.batch-delete',
'component' => null,
'meta' => null,
'sort' => 5,
@@ -394,6 +477,181 @@ class AuthSeeder extends Seeder
foreach ($permissions as $permission) {
Permission::create($permission);
}
// 更新parent_id
$this->updateParentIds();
}
/**
* 更新parent_id建立层级关系
*/
private function updateParentIds(): void
{
$permissions = Permission::all();
// 获取顶级菜单ID
$homeMenu = $permissions->where('name', 'home')->first();
$authMenu = $permissions->where('name', 'auth')->first();
// 获取首页子菜单ID
$dashboardMenu = $permissions->where('name', 'home.dashboard')->first();
$profileMenu = $permissions->where('name', 'home.profile')->first();
// 获取权限子菜单ID
$usersMenu = $permissions->where('name', 'auth.users')->first();
$rolesMenu = $permissions->where('name', 'auth.roles')->first();
$permissionsMenu = $permissions->where('name', 'auth.permissions')->first();
$departmentsMenu = $permissions->where('name', 'auth.departments')->first();
// 更新首页子菜单的parent_id
if ($homeMenu) {
if ($dashboardMenu) {
$dashboardMenu->update(['parent_id' => $homeMenu->id]);
}
if ($profileMenu) {
$profileMenu->update(['parent_id' => $homeMenu->id]);
}
}
// 更新权限子菜单的parent_id
if ($authMenu) {
if ($usersMenu) {
$usersMenu->update(['parent_id' => $authMenu->id]);
}
if ($rolesMenu) {
$rolesMenu->update(['parent_id' => $authMenu->id]);
}
if ($permissionsMenu) {
$permissionsMenu->update(['parent_id' => $authMenu->id]);
}
if ($departmentsMenu) {
$departmentsMenu->update(['parent_id' => $authMenu->id]);
}
}
// 更新按钮权限的parent_id - 首页部分
$profileViewBtn = $permissions->where('name', 'home.profile.view')->first();
$profileUpdateBtn = $permissions->where('name', 'home.profile.update')->first();
$profilePasswordBtn = $permissions->where('name', 'home.profile.change-password')->first();
if ($profileMenu) {
if ($profileViewBtn) {
$profileViewBtn->update(['parent_id' => $profileMenu->id]);
}
if ($profileUpdateBtn) {
$profileUpdateBtn->update(['parent_id' => $profileMenu->id]);
}
if ($profilePasswordBtn) {
$profilePasswordBtn->update(['parent_id' => $profileMenu->id]);
}
}
// 更新按钮权限的parent_id - 用户管理
$userViewBtn = $permissions->where('name', 'auth.users.view')->first();
$userCreateBtn = $permissions->where('name', 'auth.users.create')->first();
$userUpdateBtn = $permissions->where('name', 'auth.users.update')->first();
$userDeleteBtn = $permissions->where('name', 'auth.users.delete')->first();
$userBatchDeleteBtn = $permissions->where('name', 'auth.users.batch-delete')->first();
$userExportBtn = $permissions->where('name', 'auth.users.export')->first();
$userImportBtn = $permissions->where('name', 'auth.users.import')->first();
if ($usersMenu) {
if ($userViewBtn) {
$userViewBtn->update(['parent_id' => $usersMenu->id]);
}
if ($userCreateBtn) {
$userCreateBtn->update(['parent_id' => $usersMenu->id]);
}
if ($userUpdateBtn) {
$userUpdateBtn->update(['parent_id' => $usersMenu->id]);
}
if ($userDeleteBtn) {
$userDeleteBtn->update(['parent_id' => $usersMenu->id]);
}
if ($userBatchDeleteBtn) {
$userBatchDeleteBtn->update(['parent_id' => $usersMenu->id]);
}
if ($userExportBtn) {
$userExportBtn->update(['parent_id' => $usersMenu->id]);
}
if ($userImportBtn) {
$userImportBtn->update(['parent_id' => $usersMenu->id]);
}
}
// 更新按钮权限的parent_id - 角色管理
$roleViewBtn = $permissions->where('name', 'auth.roles.view')->first();
$roleCreateBtn = $permissions->where('name', 'auth.roles.create')->first();
$roleUpdateBtn = $permissions->where('name', 'auth.roles.update')->first();
$roleDeleteBtn = $permissions->where('name', 'auth.roles.delete')->first();
$roleBatchDeleteBtn = $permissions->where('name', 'auth.roles.batch-delete')->first();
$roleAssignBtn = $permissions->where('name', 'auth.roles.assign-permissions')->first();
if ($rolesMenu) {
if ($roleViewBtn) {
$roleViewBtn->update(['parent_id' => $rolesMenu->id]);
}
if ($roleCreateBtn) {
$roleCreateBtn->update(['parent_id' => $rolesMenu->id]);
}
if ($roleUpdateBtn) {
$roleUpdateBtn->update(['parent_id' => $rolesMenu->id]);
}
if ($roleDeleteBtn) {
$roleDeleteBtn->update(['parent_id' => $rolesMenu->id]);
}
if ($roleBatchDeleteBtn) {
$roleBatchDeleteBtn->update(['parent_id' => $rolesMenu->id]);
}
if ($roleAssignBtn) {
$roleAssignBtn->update(['parent_id' => $rolesMenu->id]);
}
}
// 更新按钮权限的parent_id - 权限管理
$permViewBtn = $permissions->where('name', 'auth.permissions.view')->first();
$permCreateBtn = $permissions->where('name', 'auth.permissions.create')->first();
$permUpdateBtn = $permissions->where('name', 'auth.permissions.update')->first();
$permDeleteBtn = $permissions->where('name', 'auth.permissions.delete')->first();
$permBatchDeleteBtn = $permissions->where('name', 'auth.permissions.batch-delete')->first();
if ($permissionsMenu) {
if ($permViewBtn) {
$permViewBtn->update(['parent_id' => $permissionsMenu->id]);
}
if ($permCreateBtn) {
$permCreateBtn->update(['parent_id' => $permissionsMenu->id]);
}
if ($permUpdateBtn) {
$permUpdateBtn->update(['parent_id' => $permissionsMenu->id]);
}
if ($permDeleteBtn) {
$permDeleteBtn->update(['parent_id' => $permissionsMenu->id]);
}
if ($permBatchDeleteBtn) {
$permBatchDeleteBtn->update(['parent_id' => $permissionsMenu->id]);
}
}
// 更新按钮权限的parent_id - 部门管理
$deptViewBtn = $permissions->where('name', 'auth.departments.view')->first();
$deptCreateBtn = $permissions->where('name', 'auth.departments.create')->first();
$deptUpdateBtn = $permissions->where('name', 'auth.departments.update')->first();
$deptDeleteBtn = $permissions->where('name', 'auth.departments.delete')->first();
$deptBatchDeleteBtn = $permissions->where('name', 'auth.departments.batch-delete')->first();
if ($departmentsMenu) {
if ($deptViewBtn) {
$deptViewBtn->update(['parent_id' => $departmentsMenu->id]);
}
if ($deptCreateBtn) {
$deptCreateBtn->update(['parent_id' => $departmentsMenu->id]);
}
if ($deptUpdateBtn) {
$deptUpdateBtn->update(['parent_id' => $departmentsMenu->id]);
}
if ($deptDeleteBtn) {
$deptDeleteBtn->update(['parent_id' => $departmentsMenu->id]);
}
if ($deptBatchDeleteBtn) {
$deptBatchDeleteBtn->update(['parent_id' => $departmentsMenu->id]);
}
}
}
/**