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.

57 lines
1.7 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
namespace Database\Seeders;
use App\Models\Menu;
use Illuminate\Database\Seeder;
/**
* 为已有子菜单补全/修正 Element Plus 图标名(侧栏展示)。
* 用法php artisan db:seed --class=MenuIconsSeeder
*/
class MenuIconsSeeder extends Seeder
{
public function run(): void
{
$icons = [
'/dashboard' => 'Odometer',
'/map' => 'MapLocation',
'/courses' => 'Notebook',
'/activities' => 'Calendar',
'/news' => 'Reading',
'/teachers' => 'Avatar',
'/students' => 'Postcard',
'/demands' => 'ChatLineRound',
'/crawler' => 'Download',
'/papers' => 'Document',
'/universities' => 'School',
'/banners' => 'Picture',
'/system/users' => 'User',
'/system/roles' => 'Key',
'/system/menus' => 'Menu',
'/system/dict' => 'Notebook',
'/system/audit-logs' => 'Tickets',
'/system/research-directions' => 'Collection',
'/system/grid-members' => 'Coordinate',
];
foreach ($icons as $path => $icon) {
$count = Menu::query()->where('path', $path)->update(['icon' => $icon]);
if ($count > 0) {
$this->command?->info("{$path}{$icon}");
}
}
// 兜底:所有可见子菜单若仍无图标,使用 Menu
Menu::query()
->whereNotNull('parent_id')
->where('status', 1)
->where(function ($q) {
$q->whereNull('icon')->orWhere('icon', '');
})
->update(['icon' => 'Menu']);
$this->command?->info('子菜单图标已更新。');
}
}