You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.6 KiB

2 weeks ago
<?php
namespace Database\Seeders;
use App\Models\Menu;
use App\Models\Role;
use Illuminate\Database\Seeder;
/**
* 创建「工作台」父级菜单,并将「驾驶舱」「高校雷达网地图」挂为其子菜单。
* 用法php artisan db:seed --class=WorkbenchMenusSeeder
*/
class WorkbenchMenusSeeder extends Seeder
{
public function run(): void
{
$role = Role::query()->where('code', 'super_admin')->first();
if (! $role) {
$this->command?->warn('未找到 super_admin已跳过。');
return;
}
$workbench = Menu::query()->updateOrCreate(
['path' => '/workbench', 'parent_id' => null],
[
'name' => 'Workbench',
'title' => '工作台',
'component' => null,
'icon' => 'Monitor',
'sort' => 10,
'visible' => 1,
'keep_alive' => 0,
'permission_code' => null,
'status' => 1,
]
);
// 若「地图」仍挂在「数据资产」下,删除重复项(保留工作台下的 /map
$assetsRoot = Menu::query()->where('path', '/assets')->whereNull('parent_id')->first();
if ($assetsRoot) {
Menu::query()
->where('path', '/map')
->where('parent_id', $assetsRoot->id)
->delete();
}
$dashboard = Menu::query()->updateOrCreate(
['path' => '/dashboard'],
[
'parent_id' => $workbench->id,
'name' => 'Dashboard',
'title' => '驾驶舱',
'component' => 'dashboard/index',
'icon' => 'Odometer',
'sort' => 10,
'visible' => 1,
'keep_alive' => 0,
'permission_code' => null,
'status' => 1,
]
);
$map = Menu::query()->updateOrCreate(
['path' => '/map'],
[
'parent_id' => $workbench->id,
'name' => 'RadarMap',
'title' => '高校雷达网地图',
'component' => 'assets/map/index',
'icon' => 'MapLocation',
'sort' => 20,
'visible' => 1,
'keep_alive' => 1,
'permission_code' => null,
'status' => 1,
]
);
$role->menus()->syncWithoutDetaching([$workbench->id, $dashboard->id, $map->id]);
$this->command?->info('工作台菜单已就绪:驾驶舱、高校雷达网地图已归入工作台。');
}
}