优化更新

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
@@ -79,12 +79,11 @@ public function show($id)
public function store(Request $request) public function store(Request $request)
{ {
$validated = $request->validate([ $validated = $request->validate([
'name' => 'required|string|max:50', 'title' => 'required|string|max:50',
'code' => 'required|string|max:100|unique:auth_permissions,code', 'name' => 'required|string|max:100|unique:auth_permissions,name',
'type' => 'required|in:menu,api,button', 'type' => 'required|in:menu,api,button',
'route' => 'nullable|string|max:200', 'route' => 'nullable|string|max:200',
'component' => 'nullable|string|max:200', 'component' => 'nullable|string|max:200',
'icon' => 'nullable|string|max:50',
'parent_id' => 'nullable|integer|exists:auth_permissions,id', 'parent_id' => 'nullable|integer|exists:auth_permissions,id',
'sort' => 'nullable|integer|min:0', 'sort' => 'nullable|integer|min:0',
'status' => 'nullable|integer|in:0,1', 'status' => 'nullable|integer|in:0,1',
@@ -106,12 +105,11 @@ public function store(Request $request)
public function update(Request $request, $id) public function update(Request $request, $id)
{ {
$validated = $request->validate([ $validated = $request->validate([
'name' => 'nullable|string|max:50', 'title' => 'nullable|string|max:50',
'code' => 'nullable|string|max:100|unique:auth_permissions,code,' . $id, 'name' => 'nullable|string|max:100|unique:auth_permissions,name,' . $id,
'type' => 'nullable|in:menu,api,button', 'type' => 'nullable|in:menu,api,button',
'route' => 'nullable|string|max:200', 'route' => 'nullable|string|max:200',
'component' => 'nullable|string|max:200', 'component' => 'nullable|string|max:200',
'icon' => 'nullable|string|max:50',
'parent_id' => 'nullable|integer|exists:auth_permissions,id', 'parent_id' => 'nullable|integer|exists:auth_permissions,id',
'sort' => 'nullable|integer|min:0', 'sort' => 'nullable|integer|min:0',
'status' => 'nullable|integer|in:0,1', 'status' => 'nullable|integer|in:0,1',
+2 -2
View File
@@ -13,11 +13,11 @@ class Permission extends Model
protected $table = 'auth_permissions'; protected $table = 'auth_permissions';
protected $fillable = [ protected $fillable = [
'title',
'name', 'name',
'code',
'type', 'type',
'parent_id', 'parent_id',
'route', 'path',
'component', 'component',
'meta', 'meta',
'sort', 'sort',
+1 -1
View File
@@ -71,7 +71,7 @@ public function hasPermission(string $permissionCode): bool
{ {
foreach ($this->roles as $role) { foreach ($this->roles as $role) {
foreach ($role->permissions as $permission) { foreach ($role->permissions as $permission) {
if ($permission->code === $permissionCode) { if ($permission->name === $permissionCode) {
return true; return true;
} }
} }
+5 -4
View File
@@ -203,8 +203,9 @@ private function buildMenuTree($permissions, $parentId = 0): array
foreach ($permissions as $permission) { foreach ($permissions as $permission) {
if ($permission->parent_id == $parentId) { if ($permission->parent_id == $parentId) {
$node = [ $node = [
'path' => $permission->route, 'path' => $permission->path,
'name' => $permission->code, 'name' => $permission->name,
'title' => $permission->title,
'meta' => $permission->meta ? json_decode($permission->meta, true) : [], 'meta' => $permission->meta ? json_decode($permission->meta, true) : [],
]; ];
@@ -238,8 +239,8 @@ private function getUserPermissions(User $user): array
$permissions = []; $permissions = [];
foreach ($user->roles as $role) { foreach ($user->roles as $role) {
foreach ($role->permissions as $permission) { foreach ($role->permissions as $permission) {
if (!in_array($permission->code, $permissions)) { if (!in_array($permission->name, $permissions)) {
$permissions[] = $permission->code; $permissions[] = $permission->name;
} }
} }
} }
+6 -6
View File
@@ -30,10 +30,10 @@ public function getUserPermissions(int $userId): array
foreach ($role->permissions as $permission) { foreach ($role->permissions as $permission) {
$permissions[$permission->id] = [ $permissions[$permission->id] = [
'id' => $permission->id, 'id' => $permission->id,
'title' => $permission->title,
'name' => $permission->name, 'name' => $permission->name,
'code' => $permission->code,
'type' => $permission->type, 'type' => $permission->type,
'route' => $permission->route, 'path' => $permission->path,
]; ];
} }
} }
@@ -51,7 +51,7 @@ public function getUserPermissionCodes(int $userId): array
return Cache::remember($cacheKey, now()->addMinutes($this->cacheMinutes), function() use ($userId) { return Cache::remember($cacheKey, now()->addMinutes($this->cacheMinutes), function() use ($userId) {
$permissions = $this->getUserPermissions($userId); $permissions = $this->getUserPermissions($userId);
return array_column($permissions, 'code'); return array_column($permissions, 'name');
}); });
} }
@@ -112,8 +112,8 @@ public function getRolePermissions(int $roleId): array
return $role->permissions->map(function($permission) { return $role->permissions->map(function($permission) {
return [ return [
'id' => $permission->id, 'id' => $permission->id,
'title' => $permission->title,
'name' => $permission->name, 'name' => $permission->name,
'code' => $permission->code,
'type' => $permission->type, 'type' => $permission->type,
]; ];
})->toArray(); })->toArray();
@@ -195,10 +195,10 @@ protected function buildMenuTree(array $permissions, int $parentId = 0): array
if ($permission['parent_id'] == $parentId) { if ($permission['parent_id'] == $parentId) {
$node = [ $node = [
'id' => $permission['id'], 'id' => $permission['id'],
'title' => $permission['title'],
'name' => $permission['name'], 'name' => $permission['name'],
'code' => $permission['code'],
'type' => $permission['type'], 'type' => $permission['type'],
'route' => $permission['route'], 'path' => $permission['path'],
'component' => $permission['component'], 'component' => $permission['component'],
'meta' => json_decode($permission['meta'] ?? '{}', true), 'meta' => json_decode($permission['meta'] ?? '{}', true),
'sort' => $permission['sort'], 'sort' => $permission['sort'],
+23 -23
View File
@@ -18,8 +18,8 @@ public function getList(array $params): array
// 搜索条件 // 搜索条件
if (!empty($params['keyword'])) { if (!empty($params['keyword'])) {
$query->where(function ($q) use ($params) { $query->where(function ($q) use ($params) {
$q->where('name', 'like', '%' . $params['keyword'] . '%') $q->where('title', 'like', '%' . $params['keyword'] . '%')
->orWhere('code', 'like', '%' . $params['keyword'] . '%'); ->orWhere('name', 'like', '%' . $params['keyword'] . '%');
}); });
} }
@@ -109,15 +109,15 @@ public function getById(int $id): array
return [ return [
'id' => $permission->id, 'id' => $permission->id,
'title' => $permission->title,
'name' => $permission->name, 'name' => $permission->name,
'code' => $permission->code,
'type' => $permission->type, 'type' => $permission->type,
'parent_id' => $permission->parent_id, 'parent_id' => $permission->parent_id,
'parent' => $permission->parent ? [ 'parent' => $permission->parent ? [
'id' => $permission->parent->id, 'id' => $permission->parent->id,
'name' => $permission->parent->name, 'name' => $permission->parent->name,
] : null, ] : null,
'route' => $permission->route, 'path' => $permission->path,
'component' => $permission->component, 'component' => $permission->component,
'meta' => $permission->meta, 'meta' => $permission->meta,
'sort' => $permission->sort, 'sort' => $permission->sort,
@@ -132,17 +132,17 @@ public function getById(int $id): array
*/ */
public function create(array $data): Permission public function create(array $data): Permission
{ {
// 检查权限名称是否已存在 // 检查权限标题是否已存在
if (Permission::where('name', $data['name'])->exists()) { if (isset($data['title']) && Permission::where('title', $data['title'])->exists()) {
throw ValidationException::withMessages([ throw ValidationException::withMessages([
'name' => ['权限名称已存在'], 'title' => ['权限标题已存在'],
]); ]);
} }
// 检查权限编码是否已存在 // 检查权限编码是否已存在
if (Permission::where('code', $data['code'])->exists()) { if (Permission::where('name', $data['name'])->exists()) {
throw ValidationException::withMessages([ throw ValidationException::withMessages([
'code' => ['权限编码已存在'], 'name' => ['权限编码已存在'],
]); ]);
} }
@@ -157,11 +157,11 @@ public function create(array $data): Permission
} }
return Permission::create([ return Permission::create([
'title' => $data['title'],
'name' => $data['name'], 'name' => $data['name'],
'code' => $data['code'], 'type' => $data['type'] ?? 'menu',
'type' => $data['type'] ?? 'api',
'parent_id' => $data['parent_id'] ?? 0, 'parent_id' => $data['parent_id'] ?? 0,
'route' => $data['route'] ?? null, 'path' => $data['path'] ?? null,
'component' => $data['component'] ?? null, 'component' => $data['component'] ?? null,
'meta' => $data['meta'] ?? null, 'meta' => $data['meta'] ?? null,
'sort' => $data['sort'] ?? 0, 'sort' => $data['sort'] ?? 0,
@@ -182,20 +182,20 @@ public function update(int $id, array $data): Permission
]); ]);
} }
// 检查权限名称是否已被其他权限使用 // 检查权限标题是否已被其他权限使用
if (isset($data['name']) && $data['name'] !== $permission->name) { if (isset($data['title']) && $data['title'] !== $permission->title) {
if (Permission::where('name', $data['name'])->exists()) { if (Permission::where('title', $data['title'])->exists()) {
throw ValidationException::withMessages([ throw ValidationException::withMessages([
'name' => ['权限名称已存在'], 'title' => ['权限标题已存在'],
]); ]);
} }
} }
// 检查权限编码是否已被其他权限使用 // 检查权限编码是否已被其他权限使用
if (isset($data['code']) && $data['code'] !== $permission->code) { if (isset($data['name']) && $data['name'] !== $permission->name) {
if (Permission::where('code', $data['code'])->exists()) { if (Permission::where('name', $data['name'])->exists()) {
throw ValidationException::withMessages([ throw ValidationException::withMessages([
'code' => ['权限编码已存在'], 'name' => ['权限编码已存在'],
]); ]);
} }
} }
@@ -218,11 +218,11 @@ public function update(int $id, array $data): Permission
} }
$updateData = [ $updateData = [
'title' => $data['title'] ?? $permission->title,
'name' => $data['name'] ?? $permission->name, 'name' => $data['name'] ?? $permission->name,
'code' => $data['code'] ?? $permission->code,
'type' => $data['type'] ?? $permission->type, 'type' => $data['type'] ?? $permission->type,
'parent_id' => $data['parent_id'] ?? $permission->parent_id, 'parent_id' => $data['parent_id'] ?? $permission->parent_id,
'route' => $data['route'] ?? $permission->route, 'path' => $data['path'] ?? $permission->path,
'component' => $data['component'] ?? $permission->component, 'component' => $data['component'] ?? $permission->component,
'meta' => isset($data['meta']) ? $data['meta'] : $permission->meta, 'meta' => isset($data['meta']) ? $data['meta'] : $permission->meta,
'sort' => $data['sort'] ?? $permission->sort, 'sort' => $data['sort'] ?? $permission->sort,
@@ -305,10 +305,10 @@ private function buildTree($permissions, $parentId = 0): array
if ($permission->parent_id == $parentId) { if ($permission->parent_id == $parentId) {
$node = [ $node = [
'id' => $permission->id, 'id' => $permission->id,
'title' => $permission->title,
'name' => $permission->name, 'name' => $permission->name,
'code' => $permission->code,
'type' => $permission->type, 'type' => $permission->type,
'route' => $permission->route, 'path' => $permission->path,
'component' => $permission->component, 'component' => $permission->component,
'meta' => $permission->meta, 'meta' => $permission->meta,
'sort' => $permission->sort, 'sort' => $permission->sort,
+1 -1
View File
@@ -32,7 +32,7 @@
| |
*/ */
'listen_port' => env('LARAVELS_LISTEN_PORT', 8000), 'listen_port' => env('LARAVELS_LISTEN_PORT', 8080),
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
@@ -64,11 +64,11 @@ public function up(): void
// 权限表 // 权限表
Schema::create('auth_permissions', function (Blueprint $table) { Schema::create('auth_permissions', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('name', 100)->unique()->comment('权限名称'); $table->string('title', 100)->comment('权限标题');
$table->string('code', 100)->unique()->comment('权限编码'); $table->string('name', 100)->unique()->comment('权限编码');
$table->string('type', 20)->default('api')->comment('类型:api 菜单 按钮'); $table->string('type', 20)->default('menu')->comment('类型:api button menu url');
$table->unsignedBigInteger('parent_id')->default(0)->comment('父级ID'); $table->unsignedBigInteger('parent_id')->default(0)->comment('父级ID');
$table->string('route')->nullable()->comment('路由'); $table->string('path')->nullable()->comment('路由路径');
$table->string('component')->nullable()->comment('前端组件路径'); $table->string('component')->nullable()->comment('前端组件路径');
$table->json('meta')->nullable()->comment('元数据(隐藏菜单、面包屑等)'); $table->json('meta')->nullable()->comment('元数据(隐藏菜单、面包屑等)');
$table->integer('sort')->default(0)->comment('排序'); $table->integer('sort')->default(0)->comment('排序');
@@ -79,6 +79,7 @@ public function up(): void
$table->index('parent_id'); $table->index('parent_id');
$table->index('type'); $table->index('type');
$table->index('status'); $table->index('status');
$table->index('name');
}); });
// 用户角色关联表 // 用户角色关联表
+380 -122
View File
@@ -55,31 +55,48 @@ public function run(): void
private function createPermissions(): void private function createPermissions(): void
{ {
$permissions = [ $permissions = [
// 系统管理 // 首页顶级菜单
[ [
'name' => '系统管理', 'title' => '首页',
'code' => 'system', 'name' => 'home',
'type' => 'menu', 'type' => 'menu',
'parent_id' => 0, 'parent_id' => 0,
'route' => '/system', 'path' => '/home',
'component' => 'Layout', 'component' => null,
'meta' => json_encode([ 'meta' => json_encode([
'icon' => 'Setting', 'icon' => 'Dashboard',
'hidden' => false, 'hidden' => false,
'hiddenBreadcrumb' => false, 'hiddenBreadcrumb' => false,
'affix' => null, 'affix' => true,
]), ]),
'sort' => 1, 'sort' => 1,
'status' => 1, 'status' => 1,
], ],
// 用户管理 // 仪表盘
[ [
'name' => '用户管理', 'title' => '仪表盘',
'code' => 'system.users', 'name' => 'home.dashboard',
'type' => 'menu', 'type' => 'menu',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为首页菜单的ID
'route' => '/system/users', 'path' => '/dashboard',
'component' => 'system/users/index', '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([ 'meta' => json_encode([
'icon' => 'User', 'icon' => 'User',
'hidden' => false, 'hidden' => false,
@@ -89,77 +106,143 @@ private function createPermissions(): void
'status' => 1, 'status' => 1,
], ],
[ [
'name' => '查看用户', 'title' => '查看个人信息',
'code' => 'system.users.view', 'name' => 'home.profile.view',
'type' => 'button', 'type' => 'button',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为个人中心菜单的ID
'route' => 'admin.users.index', 'path' => null,
'component' => null, 'component' => null,
'meta' => null, 'meta' => null,
'sort' => 1, 'sort' => 1,
'status' => 1, 'status' => 1,
], ],
[ [
'name' => '创建用户', 'title' => '编辑个人信息',
'code' => 'system.users.create', 'name' => 'home.profile.update',
'type' => 'button', 'type' => 'button',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为个人中心菜单的ID
'route' => 'admin.users.store', 'path' => null,
'component' => null, 'component' => null,
'meta' => null, 'meta' => null,
'sort' => 2, 'sort' => 2,
'status' => 1, 'status' => 1,
], ],
[ [
'name' => '编辑用户', 'title' => '修改密码',
'code' => 'system.users.update', 'name' => 'home.profile.change-password',
'type' => 'button', 'type' => 'button',
'parent_id' => 0, // 稍后更新为个人中心菜单的ID
'path' => null,
'component' => null,
'meta' => null,
'sort' => 3,
'status' => 1,
],
// 权限顶级菜单
[
'title' => '权限',
'name' => 'auth',
'type' => 'menu',
'parent_id' => 0, '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, 'component' => null,
'meta' => null, 'meta' => null,
'sort' => 3, 'sort' => 3,
'status' => 1, 'status' => 1,
], ],
[ [
'name' => '删除用户', 'title' => '删除用户',
'code' => 'system.users.delete', 'name' => 'auth.users.delete',
'type' => 'button', 'type' => 'button',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为用户管理菜单的ID
'route' => 'admin.users.destroy', 'path' => 'admin.users.destroy',
'component' => null, 'component' => null,
'meta' => null, 'meta' => null,
'sort' => 4, 'sort' => 4,
'status' => 1, 'status' => 1,
], ],
[ [
'name' => '批量删除用户', 'title' => '批量删除用户',
'code' => 'system.users.batch-delete', 'name' => 'auth.users.batch-delete',
'type' => 'button', 'type' => 'button',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为用户管理菜单的ID
'route' => 'admin.users.batch-delete', 'path' => 'admin.users.batch-delete',
'component' => null, 'component' => null,
'meta' => null, 'meta' => null,
'sort' => 5, 'sort' => 5,
'status' => 1, 'status' => 1,
], ],
[ [
'name' => '导出用户', 'title' => '导出用户',
'code' => 'system.users.export', 'name' => 'auth.users.export',
'type' => 'button', 'type' => 'button',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为用户管理菜单的ID
'route' => 'admin.users.export', 'path' => 'admin.users.export',
'component' => null, 'component' => null,
'meta' => null, 'meta' => null,
'sort' => 6, 'sort' => 6,
'status' => 1, 'status' => 1,
], ],
[ [
'name' => '导入用户', 'title' => '导入用户',
'code' => 'system.users.import', 'name' => 'auth.users.import',
'type' => 'button', 'type' => 'button',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为用户管理菜单的ID
'route' => 'admin.users.import', 'path' => 'admin.users.import',
'component' => null, 'component' => null,
'meta' => null, 'meta' => null,
'sort' => 7, 'sort' => 7,
@@ -167,81 +250,81 @@ private function createPermissions(): void
], ],
// 角色管理 // 角色管理
[ [
'name' => '角色管理', 'title' => '角色管理',
'code' => 'system.roles', 'name' => 'auth.roles',
'type' => 'menu', 'type' => 'menu',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为权限菜单的ID
'route' => '/system/roles', 'path' => '/auth/roles',
'component' => 'system/roles/index', 'component' => 'auth/roles/index',
'meta' => json_encode([ 'meta' => json_encode([
'icon' => 'UserFilled', 'icon' => 'UserFilled',
'hidden' => false, 'hidden' => false,
'hiddenBreadcrumb' => false, 'hiddenBreadcrumb' => false,
]), ]),
'sort' => 3, 'sort' => 2,
'status' => 1, 'status' => 1,
], ],
[ [
'name' => '查看角色', 'title' => '查看角色',
'code' => 'system.roles.view', 'name' => 'auth.roles.view',
'type' => 'button', 'type' => 'button',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为角色管理菜单的ID
'route' => 'admin.roles.index', 'path' => 'admin.roles.index',
'component' => null, 'component' => null,
'meta' => null, 'meta' => null,
'sort' => 1, 'sort' => 1,
'status' => 1, 'status' => 1,
], ],
[ [
'name' => '创建角色', 'title' => '创建角色',
'code' => 'system.roles.create', 'name' => 'auth.roles.create',
'type' => 'button', 'type' => 'button',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为角色管理菜单的ID
'route' => 'admin.roles.store', 'path' => 'admin.roles.store',
'component' => null, 'component' => null,
'meta' => null, 'meta' => null,
'sort' => 2, 'sort' => 2,
'status' => 1, 'status' => 1,
], ],
[ [
'name' => '编辑角色', 'title' => '编辑角色',
'code' => 'system.roles.update', 'name' => 'auth.roles.update',
'type' => 'button', 'type' => 'button',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为角色管理菜单的ID
'route' => 'admin.roles.update', 'path' => 'admin.roles.update',
'component' => null, 'component' => null,
'meta' => null, 'meta' => null,
'sort' => 3, 'sort' => 3,
'status' => 1, 'status' => 1,
], ],
[ [
'name' => '删除角色', 'title' => '删除角色',
'code' => 'system.roles.delete', 'name' => 'auth.roles.delete',
'type' => 'button', 'type' => 'button',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为角色管理菜单的ID
'route' => 'admin.roles.destroy', 'path' => 'admin.roles.destroy',
'component' => null, 'component' => null,
'meta' => null, 'meta' => null,
'sort' => 4, 'sort' => 4,
'status' => 1, 'status' => 1,
], ],
[ [
'name' => '批量删除角色', 'title' => '批量删除角色',
'code' => 'system.roles.batch-delete', 'name' => 'auth.roles.batch-delete',
'type' => 'button', 'type' => 'button',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为角色管理菜单的ID
'route' => 'admin.roles.batch-delete', 'path' => 'admin.roles.batch-delete',
'component' => null, 'component' => null,
'meta' => null, 'meta' => null,
'sort' => 5, 'sort' => 5,
'status' => 1, 'status' => 1,
], ],
[ [
'name' => '分配权限', 'title' => '分配权限',
'code' => 'system.roles.assign-permissions', 'name' => 'auth.roles.assign-permissions',
'type' => 'button', 'type' => 'button',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为角色管理菜单的ID
'route' => 'admin.roles.assign-permissions', 'path' => 'admin.roles.assign-permissions',
'component' => null, 'component' => null,
'meta' => null, 'meta' => null,
'sort' => 6, 'sort' => 6,
@@ -249,70 +332,70 @@ private function createPermissions(): void
], ],
// 权限管理 // 权限管理
[ [
'name' => '权限管理', 'title' => '权限管理',
'code' => 'system.permissions', 'name' => 'auth.permissions',
'type' => 'menu', 'type' => 'menu',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为权限菜单的ID
'route' => '/system/permissions', 'path' => '/auth/permissions',
'component' => 'system/permissions/index', 'component' => 'auth/permissions/index',
'meta' => json_encode([ 'meta' => json_encode([
'icon' => 'Lock', 'icon' => 'Lock',
'hidden' => false, 'hidden' => false,
'hiddenBreadcrumb' => false, 'hiddenBreadcrumb' => false,
]), ]),
'sort' => 4, 'sort' => 3,
'status' => 1, 'status' => 1,
], ],
[ [
'name' => '查看权限', 'title' => '查看权限',
'code' => 'system.permissions.view', 'name' => 'auth.permissions.view',
'type' => 'button', 'type' => 'button',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为权限管理菜单的ID
'route' => 'admin.permissions.index', 'path' => 'admin.permissions.index',
'component' => null, 'component' => null,
'meta' => null, 'meta' => null,
'sort' => 1, 'sort' => 1,
'status' => 1, 'status' => 1,
], ],
[ [
'name' => '创建权限', 'title' => '创建权限',
'code' => 'system.permissions.create', 'name' => 'auth.permissions.create',
'type' => 'button', 'type' => 'button',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为权限管理菜单的ID
'route' => 'admin.permissions.store', 'path' => 'admin.permissions.store',
'component' => null, 'component' => null,
'meta' => null, 'meta' => null,
'sort' => 2, 'sort' => 2,
'status' => 1, 'status' => 1,
], ],
[ [
'name' => '编辑权限', 'title' => '编辑权限',
'code' => 'system.permissions.update', 'name' => 'auth.permissions.update',
'type' => 'button', 'type' => 'button',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为权限管理菜单的ID
'route' => 'admin.permissions.update', 'path' => 'admin.permissions.update',
'component' => null, 'component' => null,
'meta' => null, 'meta' => null,
'sort' => 3, 'sort' => 3,
'status' => 1, 'status' => 1,
], ],
[ [
'name' => '删除权限', 'title' => '删除权限',
'code' => 'system.permissions.delete', 'name' => 'auth.permissions.delete',
'type' => 'button', 'type' => 'button',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为权限管理菜单的ID
'route' => 'admin.permissions.destroy', 'path' => 'admin.permissions.destroy',
'component' => null, 'component' => null,
'meta' => null, 'meta' => null,
'sort' => 4, 'sort' => 4,
'status' => 1, 'status' => 1,
], ],
[ [
'name' => '批量删除权限', 'title' => '批量删除权限',
'code' => 'system.permissions.batch-delete', 'name' => 'auth.permissions.batch-delete',
'type' => 'button', 'type' => 'button',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为权限管理菜单的ID
'route' => 'admin.permissions.batch-delete', 'path' => 'admin.permissions.batch-delete',
'component' => null, 'component' => null,
'meta' => null, 'meta' => null,
'sort' => 5, 'sort' => 5,
@@ -320,70 +403,70 @@ private function createPermissions(): void
], ],
// 部门管理 // 部门管理
[ [
'name' => '部门管理', 'title' => '部门管理',
'code' => 'system.departments', 'name' => 'auth.departments',
'type' => 'menu', 'type' => 'menu',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为权限菜单的ID
'route' => '/system/departments', 'path' => '/auth/departments',
'component' => 'system/departments/index', 'component' => 'auth/departments/index',
'meta' => json_encode([ 'meta' => json_encode([
'icon' => 'OfficeBuilding', 'icon' => 'OfficeBuilding',
'hidden' => false, 'hidden' => false,
'hiddenBreadcrumb' => false, 'hiddenBreadcrumb' => false,
]), ]),
'sort' => 5, 'sort' => 4,
'status' => 1, 'status' => 1,
], ],
[ [
'name' => '查看部门', 'title' => '查看部门',
'code' => 'system.departments.view', 'name' => 'auth.departments.view',
'type' => 'button', 'type' => 'button',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为部门管理菜单的ID
'route' => 'admin.departments.index', 'path' => 'admin.departments.index',
'component' => null, 'component' => null,
'meta' => null, 'meta' => null,
'sort' => 1, 'sort' => 1,
'status' => 1, 'status' => 1,
], ],
[ [
'name' => '创建部门', 'title' => '创建部门',
'code' => 'system.departments.create', 'name' => 'auth.departments.create',
'type' => 'button', 'type' => 'button',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为部门管理菜单的ID
'route' => 'admin.departments.store', 'path' => 'admin.departments.store',
'component' => null, 'component' => null,
'meta' => null, 'meta' => null,
'sort' => 2, 'sort' => 2,
'status' => 1, 'status' => 1,
], ],
[ [
'name' => '编辑部门', 'title' => '编辑部门',
'code' => 'system.departments.update', 'name' => 'auth.departments.update',
'type' => 'button', 'type' => 'button',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为部门管理菜单的ID
'route' => 'admin.departments.update', 'path' => 'admin.departments.update',
'component' => null, 'component' => null,
'meta' => null, 'meta' => null,
'sort' => 3, 'sort' => 3,
'status' => 1, 'status' => 1,
], ],
[ [
'name' => '删除部门', 'title' => '删除部门',
'code' => 'system.departments.delete', 'name' => 'auth.departments.delete',
'type' => 'button', 'type' => 'button',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为部门管理菜单的ID
'route' => 'admin.departments.destroy', 'path' => 'admin.departments.destroy',
'component' => null, 'component' => null,
'meta' => null, 'meta' => null,
'sort' => 4, 'sort' => 4,
'status' => 1, 'status' => 1,
], ],
[ [
'name' => '批量删除部门', 'title' => '批量删除部门',
'code' => 'system.departments.batch-delete', 'name' => 'auth.departments.batch-delete',
'type' => 'button', 'type' => 'button',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为部门管理菜单的ID
'route' => 'admin.departments.batch-delete', 'path' => 'admin.departments.batch-delete',
'component' => null, 'component' => null,
'meta' => null, 'meta' => null,
'sort' => 5, 'sort' => 5,
@@ -394,6 +477,181 @@ private function createPermissions(): void
foreach ($permissions as $permission) { foreach ($permissions as $permission) {
Permission::create($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]);
}
}
} }
/** /**
+264 -125
View File
@@ -48,72 +48,88 @@ public function run(): void
private function createSystemPermissions(): void private function createSystemPermissions(): void
{ {
$permissions = [ $permissions = [
// 系统配置 // 系统顶级菜单
[ [
'name' => '系统配置', 'title' => '系统',
'code' => 'system.config', 'name' => 'system',
'type' => 'menu', 'type' => 'menu',
'parent_id' => 0, 'parent_id' => 0,
'route' => '/system/config', 'path' => '/system',
'component' => null,
'meta' => json_encode([
'icon' => 'Setting',
'hidden' => false,
'hiddenBreadcrumb' => false,
]),
'sort' => 3,
'status' => 1,
],
// 系统配置
[
'title' => '系统配置',
'name' => 'system.config',
'type' => 'menu',
'parent_id' => 0, // 稍后更新为系统菜单的ID
'path' => '/system/config',
'component' => 'system/config/index', 'component' => 'system/config/index',
'meta' => json_encode([ 'meta' => json_encode([
'icon' => 'SettingFilled', 'icon' => 'SettingFilled',
'hidden' => false, 'hidden' => false,
'hiddenBreadcrumb' => false, 'hiddenBreadcrumb' => false,
]), ]),
'sort' => 6, 'sort' => 1,
'status' => 1, 'status' => 1,
], ],
[ [
'name' => '查看配置', 'title' => '查看配置',
'code' => 'system.config.view', 'name' => 'system.config.view',
'type' => 'button', 'type' => 'button',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为系统配置菜单的ID
'route' => 'admin.config.index', 'path' => 'admin.config.index',
'component' => null, 'component' => null,
'meta' => null, 'meta' => null,
'sort' => 1, 'sort' => 1,
'status' => 1, 'status' => 1,
], ],
[ [
'name' => '创建配置', 'title' => '创建配置',
'code' => 'system.config.create', 'name' => 'system.config.create',
'type' => 'button', 'type' => 'button',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为系统配置菜单的ID
'route' => 'admin.config.store', 'path' => 'admin.config.store',
'component' => null, 'component' => null,
'meta' => null, 'meta' => null,
'sort' => 2, 'sort' => 2,
'status' => 1, 'status' => 1,
], ],
[ [
'name' => '编辑配置', 'title' => '编辑配置',
'code' => 'system.config.update', 'name' => 'system.config.update',
'type' => 'button', 'type' => 'button',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为系统配置菜单的ID
'route' => 'admin.config.update', 'path' => 'admin.config.update',
'component' => null, 'component' => null,
'meta' => null, 'meta' => null,
'sort' => 3, 'sort' => 3,
'status' => 1, 'status' => 1,
], ],
[ [
'name' => '删除配置', 'title' => '删除配置',
'code' => 'system.config.delete', 'name' => 'system.config.delete',
'type' => 'button', 'type' => 'button',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为系统配置菜单的ID
'route' => 'admin.config.destroy', 'path' => 'admin.config.destroy',
'component' => null, 'component' => null,
'meta' => null, 'meta' => null,
'sort' => 4, 'sort' => 4,
'status' => 1, 'status' => 1,
], ],
[ [
'name' => '批量删除配置', 'title' => '批量删除配置',
'code' => 'system.config.batch-delete', 'name' => 'system.config.batch-delete',
'type' => 'button', 'type' => 'button',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为系统配置菜单的ID
'route' => 'admin.config.batch-delete', 'path' => 'admin.config.batch-delete',
'component' => null, 'component' => null,
'meta' => null, 'meta' => null,
'sort' => 5, 'sort' => 5,
@@ -122,59 +138,59 @@ private function createSystemPermissions(): void
// 系统日志 // 系统日志
[ [
'name' => '系统日志', 'title' => '系统日志',
'code' => 'system.logs', 'name' => 'system.logs',
'type' => 'menu', 'type' => 'menu',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为系统菜单的ID
'route' => '/system/logs', 'path' => '/system/logs',
'component' => 'system/logs/index', 'component' => 'system/logs/index',
'meta' => json_encode([ 'meta' => json_encode([
'icon' => 'DocumentCopy', 'icon' => 'DocumentCopy',
'hidden' => false, 'hidden' => false,
'hiddenBreadcrumb' => false, 'hiddenBreadcrumb' => false,
]), ]),
'sort' => 7, 'sort' => 2,
'status' => 1, 'status' => 1,
], ],
[ [
'name' => '查看日志', 'title' => '查看日志',
'code' => 'system.logs.view', 'name' => 'system.logs.view',
'type' => 'button', 'type' => 'button',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为系统日志菜单的ID
'route' => 'admin.logs.index', 'path' => 'admin.logs.index',
'component' => null, 'component' => null,
'meta' => null, 'meta' => null,
'sort' => 1, 'sort' => 1,
'status' => 1, 'status' => 1,
], ],
[ [
'name' => '删除日志', 'title' => '删除日志',
'code' => 'system.logs.delete', 'name' => 'system.logs.delete',
'type' => 'button', 'type' => 'button',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为系统日志菜单的ID
'route' => 'admin.logs.destroy', 'path' => 'admin.logs.destroy',
'component' => null, 'component' => null,
'meta' => null, 'meta' => null,
'sort' => 2, 'sort' => 2,
'status' => 1, 'status' => 1,
], ],
[ [
'name' => '批量删除日志', 'title' => '批量删除日志',
'code' => 'system.logs.batch-delete', 'name' => 'system.logs.batch-delete',
'type' => 'button', 'type' => 'button',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为系统日志菜单的ID
'route' => 'admin.logs.batch-delete', 'path' => 'admin.logs.batch-delete',
'component' => null, 'component' => null,
'meta' => null, 'meta' => null,
'sort' => 3, 'sort' => 3,
'status' => 1, 'status' => 1,
], ],
[ [
'name' => '导出日志', 'title' => '导出日志',
'code' => 'system.logs.export', 'name' => 'system.logs.export',
'type' => 'button', 'type' => 'button',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为系统日志菜单的ID
'route' => 'admin.logs.export', 'path' => 'admin.logs.export',
'component' => null, 'component' => null,
'meta' => null, 'meta' => null,
'sort' => 4, 'sort' => 4,
@@ -183,70 +199,70 @@ private function createSystemPermissions(): void
// 数据字典 // 数据字典
[ [
'name' => '数据字典', 'title' => '数据字典',
'code' => 'system.dictionaries', 'name' => 'system.dictionaries',
'type' => 'menu', 'type' => 'menu',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为系统菜单的ID
'route' => '/system/dictionaries', 'path' => '/system/dictionaries',
'component' => 'system/dictionaries/index', 'component' => 'system/dictionaries/index',
'meta' => json_encode([ 'meta' => json_encode([
'icon' => 'Notebook', 'icon' => 'Notebook',
'hidden' => false, 'hidden' => false,
'hiddenBreadcrumb' => false, 'hiddenBreadcrumb' => false,
]), ]),
'sort' => 8, 'sort' => 3,
'status' => 1, 'status' => 1,
], ],
[ [
'name' => '查看字典', 'title' => '查看字典',
'code' => 'system.dictionaries.view', 'name' => 'system.dictionaries.view',
'type' => 'button', 'type' => 'button',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为数据字典菜单的ID
'route' => 'admin.dictionaries.index', 'path' => 'admin.dictionaries.index',
'component' => null, 'component' => null,
'meta' => null, 'meta' => null,
'sort' => 1, 'sort' => 1,
'status' => 1, 'status' => 1,
], ],
[ [
'name' => '创建字典', 'title' => '创建字典',
'code' => 'system.dictionaries.create', 'name' => 'system.dictionaries.create',
'type' => 'button', 'type' => 'button',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为数据字典菜单的ID
'route' => 'admin.dictionaries.store', 'path' => 'admin.dictionaries.store',
'component' => null, 'component' => null,
'meta' => null, 'meta' => null,
'sort' => 2, 'sort' => 2,
'status' => 1, 'status' => 1,
], ],
[ [
'name' => '编辑字典', 'title' => '编辑字典',
'code' => 'system.dictionaries.update', 'name' => 'system.dictionaries.update',
'type' => 'button', 'type' => 'button',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为数据字典菜单的ID
'route' => 'admin.dictionaries.update', 'path' => 'admin.dictionaries.update',
'component' => null, 'component' => null,
'meta' => null, 'meta' => null,
'sort' => 3, 'sort' => 3,
'status' => 1, 'status' => 1,
], ],
[ [
'name' => '删除字典', 'title' => '删除字典',
'code' => 'system.dictionaries.delete', 'name' => 'system.dictionaries.delete',
'type' => 'button', 'type' => 'button',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为数据字典菜单的ID
'route' => 'admin.dictionaries.destroy', 'path' => 'admin.dictionaries.destroy',
'component' => null, 'component' => null,
'meta' => null, 'meta' => null,
'sort' => 4, 'sort' => 4,
'status' => 1, 'status' => 1,
], ],
[ [
'name' => '批量删除字典', 'title' => '批量删除字典',
'code' => 'system.dictionaries.batch-delete', 'name' => 'system.dictionaries.batch-delete',
'type' => 'button', 'type' => 'button',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为数据字典菜单的ID
'route' => 'admin.dictionaries.batch-delete', 'path' => 'admin.dictionaries.batch-delete',
'component' => null, 'component' => null,
'meta' => null, 'meta' => null,
'sort' => 5, 'sort' => 5,
@@ -255,130 +271,253 @@ private function createSystemPermissions(): void
// 定时任务 // 定时任务
[ [
'name' => '定时任务', 'title' => '定时任务',
'code' => 'system.tasks', 'name' => 'system.tasks',
'type' => 'menu', 'type' => 'menu',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为系统菜单的ID
'route' => '/system/tasks', 'path' => '/system/tasks',
'component' => 'system/tasks/index', 'component' => 'system/tasks/index',
'meta' => json_encode([ 'meta' => json_encode([
'icon' => 'Timer', 'icon' => 'Timer',
'hidden' => false, 'hidden' => false,
'hiddenBreadcrumb' => false, 'hiddenBreadcrumb' => false,
]), ]),
'sort' => 9, 'sort' => 4,
'status' => 1, 'status' => 1,
], ],
[ [
'name' => '查看任务', 'title' => '查看任务',
'code' => 'system.tasks.view', 'name' => 'system.tasks.view',
'type' => 'button', 'type' => 'button',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为定时任务菜单的ID
'route' => 'admin.tasks.index', 'path' => 'admin.tasks.index',
'component' => null, 'component' => null,
'meta' => null, 'meta' => null,
'sort' => 1, 'sort' => 1,
'status' => 1, 'status' => 1,
], ],
[ [
'name' => '创建任务', 'title' => '创建任务',
'code' => 'system.tasks.create', 'name' => 'system.tasks.create',
'type' => 'button', 'type' => 'button',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为定时任务菜单的ID
'route' => 'admin.tasks.store', 'path' => 'admin.tasks.store',
'component' => null, 'component' => null,
'meta' => null, 'meta' => null,
'sort' => 2, 'sort' => 2,
'status' => 1, 'status' => 1,
], ],
[ [
'name' => '编辑任务', 'title' => '编辑任务',
'code' => 'system.tasks.update', 'name' => 'system.tasks.update',
'type' => 'button', 'type' => 'button',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为定时任务菜单的ID
'route' => 'admin.tasks.update', 'path' => 'admin.tasks.update',
'component' => null, 'component' => null,
'meta' => null, 'meta' => null,
'sort' => 3, 'sort' => 3,
'status' => 1, 'status' => 1,
], ],
[ [
'name' => '删除任务', 'title' => '删除任务',
'code' => 'system.tasks.delete', 'name' => 'system.tasks.delete',
'type' => 'button', 'type' => 'button',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为定时任务菜单的ID
'route' => 'admin.tasks.destroy', 'path' => 'admin.tasks.destroy',
'component' => null, 'component' => null,
'meta' => null, 'meta' => null,
'sort' => 4, 'sort' => 4,
'status' => 1, 'status' => 1,
], ],
[ [
'name' => '批量删除任务', 'title' => '批量删除任务',
'code' => 'system.tasks.batch-delete', 'name' => 'system.tasks.batch-delete',
'type' => 'button', 'type' => 'button',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为定时任务菜单的ID
'route' => 'admin.tasks.batch-delete', 'path' => 'admin.tasks.batch-delete',
'component' => null, 'component' => null,
'meta' => null, 'meta' => null,
'sort' => 5, 'sort' => 5,
'status' => 1, 'status' => 1,
], ],
[ [
'name' => '执行任务', 'title' => '执行任务',
'code' => 'system.tasks.execute', 'name' => 'system.tasks.execute',
'type' => 'button', 'type' => 'button',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为定时任务菜单的ID
'route' => 'admin.tasks.execute', 'path' => 'admin.tasks.execute',
'component' => null, 'component' => null,
'meta' => null, 'meta' => null,
'sort' => 6, 'sort' => 6,
'status' => 1, 'status' => 1,
], ],
[ [
'name' => '启用任务', 'title' => '启用任务',
'code' => 'system.tasks.enable', 'name' => 'system.tasks.enable',
'type' => 'button', 'type' => 'button',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为定时任务菜单的ID
'route' => 'admin.tasks.enable', 'path' => 'admin.tasks.enable',
'component' => null, 'component' => null,
'meta' => null, 'meta' => null,
'sort' => 7, 'sort' => 7,
'status' => 1, 'status' => 1,
], ],
[ [
'name' => '禁用任务', 'title' => '禁用任务',
'code' => 'system.tasks.disable', 'name' => 'system.tasks.disable',
'type' => 'button', 'type' => 'button',
'parent_id' => 0, 'parent_id' => 0, // 稍后更新为定时任务菜单的ID
'route' => 'admin.tasks.disable', 'path' => 'admin.tasks.disable',
'component' => null, 'component' => null,
'meta' => null, 'meta' => null,
'sort' => 8, 'sort' => 8,
'status' => 1, 'status' => 1,
], ],
// 个人中心
[
'name' => '个人中心',
'code' => 'system.profile',
'type' => 'menu',
'parent_id' => 0,
'route' => '/system/profile',
'component' => 'system/profile/index',
'meta' => json_encode([
'icon' => 'UserFilled',
'hidden' => false,
'hiddenBreadcrumb' => false,
]),
'sort' => 10,
'status' => 1,
],
]; ];
foreach ($permissions as $permission) { foreach ($permissions as $permission) {
Permission::create($permission); Permission::create($permission);
} }
// 更新parent_id
$this->updateParentIds();
}
/**
* 更新parent_id,建立层级关系
*/
private function updateParentIds(): void
{
$permissions = Permission::all();
// 获取系统顶级菜单ID
$systemMenu = $permissions->where('name', 'system')->first();
// 获取系统子菜单ID
$configMenu = $permissions->where('name', 'system.config')->first();
$logsMenu = $permissions->where('name', 'system.logs')->first();
$dictionariesMenu = $permissions->where('name', 'system.dictionaries')->first();
$tasksMenu = $permissions->where('name', 'system.tasks')->first();
// 更新系统子菜单的parent_id
if ($systemMenu) {
if ($configMenu) {
$configMenu->update(['parent_id' => $systemMenu->id]);
}
if ($logsMenu) {
$logsMenu->update(['parent_id' => $systemMenu->id]);
}
if ($dictionariesMenu) {
$dictionariesMenu->update(['parent_id' => $systemMenu->id]);
}
if ($tasksMenu) {
$tasksMenu->update(['parent_id' => $systemMenu->id]);
}
}
// 更新按钮权限的parent_id - 系统配置
$configViewBtn = $permissions->where('name', 'system.config.view')->first();
$configCreateBtn = $permissions->where('name', 'system.config.create')->first();
$configUpdateBtn = $permissions->where('name', 'system.config.update')->first();
$configDeleteBtn = $permissions->where('name', 'system.config.delete')->first();
$configBatchDeleteBtn = $permissions->where('name', 'system.config.batch-delete')->first();
if ($configMenu) {
if ($configViewBtn) {
$configViewBtn->update(['parent_id' => $configMenu->id]);
}
if ($configCreateBtn) {
$configCreateBtn->update(['parent_id' => $configMenu->id]);
}
if ($configUpdateBtn) {
$configUpdateBtn->update(['parent_id' => $configMenu->id]);
}
if ($configDeleteBtn) {
$configDeleteBtn->update(['parent_id' => $configMenu->id]);
}
if ($configBatchDeleteBtn) {
$configBatchDeleteBtn->update(['parent_id' => $configMenu->id]);
}
}
// 更新按钮权限的parent_id - 系统日志
$logsViewBtn = $permissions->where('name', 'system.logs.view')->first();
$logsDeleteBtn = $permissions->where('name', 'system.logs.delete')->first();
$logsBatchDeleteBtn = $permissions->where('name', 'system.logs.batch-delete')->first();
$logsExportBtn = $permissions->where('name', 'system.logs.export')->first();
if ($logsMenu) {
if ($logsViewBtn) {
$logsViewBtn->update(['parent_id' => $logsMenu->id]);
}
if ($logsDeleteBtn) {
$logsDeleteBtn->update(['parent_id' => $logsMenu->id]);
}
if ($logsBatchDeleteBtn) {
$logsBatchDeleteBtn->update(['parent_id' => $logsMenu->id]);
}
if ($logsExportBtn) {
$logsExportBtn->update(['parent_id' => $logsMenu->id]);
}
}
// 更新按钮权限的parent_id - 数据字典
$dictViewBtn = $permissions->where('name', 'system.dictionaries.view')->first();
$dictCreateBtn = $permissions->where('name', 'system.dictionaries.create')->first();
$dictUpdateBtn = $permissions->where('name', 'system.dictionaries.update')->first();
$dictDeleteBtn = $permissions->where('name', 'system.dictionaries.delete')->first();
$dictBatchDeleteBtn = $permissions->where('name', 'system.dictionaries.batch-delete')->first();
if ($dictionariesMenu) {
if ($dictViewBtn) {
$dictViewBtn->update(['parent_id' => $dictionariesMenu->id]);
}
if ($dictCreateBtn) {
$dictCreateBtn->update(['parent_id' => $dictionariesMenu->id]);
}
if ($dictUpdateBtn) {
$dictUpdateBtn->update(['parent_id' => $dictionariesMenu->id]);
}
if ($dictDeleteBtn) {
$dictDeleteBtn->update(['parent_id' => $dictionariesMenu->id]);
}
if ($dictBatchDeleteBtn) {
$dictBatchDeleteBtn->update(['parent_id' => $dictionariesMenu->id]);
}
}
// 更新按钮权限的parent_id - 定时任务
$taskViewBtn = $permissions->where('name', 'system.tasks.view')->first();
$taskCreateBtn = $permissions->where('name', 'system.tasks.create')->first();
$taskUpdateBtn = $permissions->where('name', 'system.tasks.update')->first();
$taskDeleteBtn = $permissions->where('name', 'system.tasks.delete')->first();
$taskBatchDeleteBtn = $permissions->where('name', 'system.tasks.batch-delete')->first();
$taskExecuteBtn = $permissions->where('name', 'system.tasks.execute')->first();
$taskEnableBtn = $permissions->where('name', 'system.tasks.enable')->first();
$taskDisableBtn = $permissions->where('name', 'system.tasks.disable')->first();
if ($tasksMenu) {
if ($taskViewBtn) {
$taskViewBtn->update(['parent_id' => $tasksMenu->id]);
}
if ($taskCreateBtn) {
$taskCreateBtn->update(['parent_id' => $tasksMenu->id]);
}
if ($taskUpdateBtn) {
$taskUpdateBtn->update(['parent_id' => $tasksMenu->id]);
}
if ($taskDeleteBtn) {
$taskDeleteBtn->update(['parent_id' => $tasksMenu->id]);
}
if ($taskBatchDeleteBtn) {
$taskBatchDeleteBtn->update(['parent_id' => $tasksMenu->id]);
}
if ($taskExecuteBtn) {
$taskExecuteBtn->update(['parent_id' => $tasksMenu->id]);
}
if ($taskEnableBtn) {
$taskEnableBtn->update(['parent_id' => $tasksMenu->id]);
}
if ($taskDisableBtn) {
$taskDisableBtn->update(['parent_id' => $tasksMenu->id]);
}
}
} }
/** /**
@@ -5,7 +5,7 @@
<template #icon v-if="item.meta?.icon"> <template #icon v-if="item.meta?.icon">
<component :is="getIconComponent(item.meta.icon)" /> <component :is="getIconComponent(item.meta.icon)" />
</template> </template>
<template #title>{{ item.meta?.title || item.name }}</template> <template #title>{{ item.title || item.name }}</template>
<navMenu :menu-items="item.children" :active-path="activePath" :parent-path="item.path" /> <navMenu :menu-items="item.children" :active-path="activePath" :parent-path="item.path" />
</a-sub-menu> </a-sub-menu>
<!-- 无子菜单的菜单项 --> <!-- 无子菜单的菜单项 -->
@@ -14,7 +14,7 @@
<template #icon v-if="item.meta?.icon"> <template #icon v-if="item.meta?.icon">
<component :is="getIconComponent(item.meta.icon)" /> <component :is="getIconComponent(item.meta.icon)" />
</template> </template>
{{ item.meta?.title || item.name }} {{ item.title || item.name }}
</a-menu-item> </a-menu-item>
</template> </template>
</template> </template>
+2 -2
View File
@@ -12,7 +12,7 @@
:class="{ active: selectedParentMenu?.path === item.path }" :class="{ active: selectedParentMenu?.path === item.path }"
@click="handleParentMenuClick(item)"> @click="handleParentMenuClick(item)">
<component :is="getIconComponent(item.meta?.icon)" /> <component :is="getIconComponent(item.meta?.icon)" />
<span>{{ item.meta?.title }}</span> <span>{{ item.title }}</span>
</li> </li>
</ul> </ul>
</a-layout-sider> </a-layout-sider>
@@ -24,7 +24,7 @@
:collapsed-width="64" class="right-sidebar"> :collapsed-width="64" class="right-sidebar">
<div class="parent-title"> <div class="parent-title">
<component :is="getIconComponent(selectedParentMenu.meta?.icon)" /> <component :is="getIconComponent(selectedParentMenu.meta?.icon)" />
<span v-if="!sidebarCollapsed">{{ selectedParentMenu.meta?.title }}</span> <span v-if="!sidebarCollapsed">{{ selectedParentMenu.title }}</span>
</div> </div>
<a-menu v-model:openKeys="openKeys" v-model:selectedKeys="selectedKeys" mode="inline" <a-menu v-model:openKeys="openKeys" v-model:selectedKeys="selectedKeys" mode="inline"
:selected-keys="[route.path]"> :selected-keys="[route.path]">