|
|
<?php
|
|
|
|
|
|
namespace Database\Seeders;
|
|
|
|
|
|
use App\Models\Menu;
|
|
|
use App\Models\Role;
|
|
|
use Illuminate\Database\Seeder;
|
|
|
|
|
|
/**
|
|
|
* 增量挂载「数据资产」侧栏。
|
|
|
* 用法:php artisan db:seed --class=DataAssetsMenusSeeder
|
|
|
*/
|
|
|
class DataAssetsMenusSeeder extends Seeder
|
|
|
{
|
|
|
public function run(): void
|
|
|
{
|
|
|
$role = Role::query()->where('code', 'super_admin')->first();
|
|
|
if (! $role) {
|
|
|
$this->command?->warn('未找到 super_admin,已跳过。');
|
|
|
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
$root = Menu::query()->firstOrCreate(
|
|
|
['path' => '/assets', 'parent_id' => null],
|
|
|
[
|
|
|
'name' => 'Assets',
|
|
|
'title' => '数据资产',
|
|
|
'component' => null,
|
|
|
'icon' => 'DataAnalysis',
|
|
|
'sort' => 70,
|
|
|
'visible' => 1,
|
|
|
'keep_alive' => 0,
|
|
|
'permission_code' => null,
|
|
|
'status' => 1,
|
|
|
]
|
|
|
);
|
|
|
|
|
|
$menus = [
|
|
|
[
|
|
|
'path' => '/crawler',
|
|
|
'name' => 'Crawler',
|
|
|
'title' => '论文爬虫',
|
|
|
'component' => 'assets/crawler/index',
|
|
|
'icon' => 'Download',
|
|
|
'sort' => 10,
|
|
|
],
|
|
|
[
|
|
|
'path' => '/papers',
|
|
|
'name' => 'Papers',
|
|
|
'title' => '论文库',
|
|
|
'component' => 'assets/papers/index',
|
|
|
'icon' => 'Document',
|
|
|
'sort' => 20,
|
|
|
],
|
|
|
[
|
|
|
'path' => '/universities',
|
|
|
'name' => 'Universities',
|
|
|
'title' => '高校坐标库',
|
|
|
'component' => 'assets/universities/index',
|
|
|
'icon' => 'School',
|
|
|
'sort' => 40,
|
|
|
],
|
|
|
[
|
|
|
'path' => '/banners',
|
|
|
'name' => 'Banners',
|
|
|
'title' => 'Banner图管理',
|
|
|
'component' => 'assets/banners/index',
|
|
|
'icon' => 'Picture',
|
|
|
'sort' => 50,
|
|
|
],
|
|
|
];
|
|
|
|
|
|
$ids = [$root->id];
|
|
|
foreach ($menus as $row) {
|
|
|
$menu = Menu::query()->firstOrCreate(
|
|
|
['path' => $row['path'], 'parent_id' => $root->id],
|
|
|
[
|
|
|
'name' => $row['name'],
|
|
|
'title' => $row['title'],
|
|
|
'component' => $row['component'],
|
|
|
'icon' => $row['icon'],
|
|
|
'sort' => $row['sort'],
|
|
|
'visible' => 1,
|
|
|
'keep_alive' => 1,
|
|
|
'permission_code' => null,
|
|
|
'status' => 1,
|
|
|
]
|
|
|
);
|
|
|
$ids[] = $menu->id;
|
|
|
}
|
|
|
|
|
|
$role->menus()->syncWithoutDetaching($ids);
|
|
|
$this->command?->info('数据资产菜单已挂载到 super_admin。');
|
|
|
}
|
|
|
}
|