111 lines
5.7 KiB
PHP
111 lines
5.7 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use Slowlyo\OwlAdmin\Models\AdminMenu;
|
|
use Illuminate\Database\Seeder;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Str;
|
|
use Throwable;
|
|
|
|
class AdminMenuSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Run the database seeds.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function run()
|
|
{
|
|
//
|
|
$menus = [
|
|
['title' => '主页', 'icon' => 'icon-park:home-two', 'url' => '/dashboard', 'is_home'=>1, 'order'=>1],
|
|
['title' => '公众号管理', 'icon' => 'icon-park:wechat', 'url' => '', 'order'=>2,
|
|
'children' => [
|
|
['title' => '公告管理', 'icon' => 'icon-park:volume-notice', 'url' => '/admin-notices', 'order'=>1],
|
|
['title' => '文章分类', 'icon' => 'icon-park:book-one', 'url' => '/article-categories', 'order'=>2],
|
|
['title' => '文章管理', 'icon' => 'icon-park:file-search', 'url' => '/articles', 'order'=>3],
|
|
['title' => '图片位置', 'icon' => 'icon-park:graphic-design-two', 'url' => '/banner-places', 'order'=>4],
|
|
['title' => '图片管理', 'icon' => 'icon-park:picture-album', 'url' => '/banners', 'order'=>5],
|
|
]
|
|
],
|
|
|
|
['title' => '区域管理', 'icon' => 'icon-park:category-management', 'url' => '', 'order'=>3,
|
|
'children' => [
|
|
['title' => '区域分类', 'icon' => 'icon-park:graphic-stitching-four', 'url' => '/region-categories', 'order'=>1],
|
|
['title' => '实验田', 'icon' => 'icon-park:freezing-line-column', 'url' => '/regions', 'order'=>2],
|
|
]
|
|
],
|
|
['title' => '育秧中心', 'icon' => 'icon-park:lotus', 'url' => '', 'order'=>4,
|
|
'children' => [
|
|
// ['title' => '大棚控制', 'icon' => 'icon-park:link-one', 'url' => 'https://www.baidu.com', 'url_type'=>2, 'order'=>1],
|
|
['title' => '育秧列表', 'icon' => 'icon-park:more-app', 'url' => '/custom-region/yuyang', 'order'=>2],
|
|
]
|
|
],
|
|
['title' => '实验稻田', 'icon' => 'icon-park:four-leaves', 'url' => '', 'order'=>5,
|
|
'children' => [
|
|
['title' => '农机控制', 'icon' => 'icon-park:link-one', 'url' => 'https://www.baidu.com', 'url_type'=>2, 'order'=>1],
|
|
['title' => '稻田列表', 'icon' => 'icon-park:more-app', 'url' => '/custom-region/daotian', 'order'=>2],
|
|
]
|
|
],
|
|
|
|
['title' => '设备管理', 'icon' => 'icon-park:devices', 'url' => '/devices', 'order'=>6],
|
|
['title' => '设备数据', 'icon' => 'icon-park:data-switching', 'url' => '', 'order'=>7,
|
|
'children' => [
|
|
['title' => '实时监控', 'icon'=>'icon-park:videocamera', 'url'=> '/custom-region-monitor', 'order'=>1],
|
|
['title' => '历史视频', 'icon'=>'icon-park:film', 'url'=> '/custom-region-monitor-video', 'order'=>2],
|
|
['title' => '气象数据', 'icon'=>'icon-park:brightness', 'url'=> '/custom-region-meteorological', 'order'=>3],
|
|
['title' => '土壤数据', 'icon'=>'icon-park:floor-tile', 'url'=> '/custom-region-water', 'order'=>4],
|
|
['title' => '水质数据', 'icon'=>'icon-park:diving-bottle', 'url'=> '/custom-region-soil', 'order'=>5],
|
|
]
|
|
],
|
|
['title' => '设备预警', 'icon' => 'icon-park:alarm', 'url' => '', 'order'=>8,
|
|
'children' => [
|
|
['title' => '预警设置', 'icon'=>'icon-park:six-circular-connection', 'url'=> '/warning-setting', 'order'=>1],
|
|
['title' => '报警记录', 'icon'=>'icon-park:massage-chair-one', 'url'=> '/warning-notice', 'order'=>2],
|
|
]
|
|
],
|
|
['title' => '友情链接', 'icon' => 'icon-park:copy-link', 'url' => '/friend-links', 'order'=>9],
|
|
['title' => '系统管理', 'icon' => 'icon-park:setting', 'url' => '/system', 'order'=>10,
|
|
'children' => [
|
|
['title' => '用户管理', 'icon' => 'icon-park:people-plus', 'url' => '/system/admin_users', 'order'=>1],
|
|
['title' => '角色管理', 'icon' => 'icon-park:people-plus-one', 'url' => '/system/admin_roles', 'order'=>2],
|
|
['title' => '权限管理', 'icon' => 'icon-park:key-one', 'url' => '/system/admin_permissions', 'order'=>3],
|
|
['title' => '菜单管理', 'icon' => 'icon-park:menu-fold-one', 'url' => '/system/admin_menus', 'order'=>4],
|
|
['title' => '字典管理', 'icon' => 'icon-park:arrow-keys', 'url' => '/keywords', 'order'=>5],
|
|
['title' => '配置管理', 'icon' => 'icon-park:setting-two', 'url' => '/system/settings', 'order'=>6],
|
|
],
|
|
],
|
|
];
|
|
DB::table('admin_menus')->truncate();
|
|
try {
|
|
DB::begintransaction();
|
|
$this->createMenus($menus);
|
|
DB::commit();
|
|
} catch (Throwable $th) {
|
|
DB::rollBack();
|
|
report($th);
|
|
}
|
|
}
|
|
|
|
public function createMenus(array $menus, $pid = 0)
|
|
{
|
|
foreach ($menus as $menu) {
|
|
$mm = AdminMenu::create([
|
|
'title' => $menu['title'],
|
|
'icon' => $menu['icon'],
|
|
'url' => $menu['url'],
|
|
'parent_id' => $pid,
|
|
'url_type' => $menu['url_type'] ?? 1,
|
|
'visible' => $menu['visible'] ?? 1,
|
|
'is_home' => $menu['is_home'] ?? 0,
|
|
'order' => $menu['order'] ?? 0,
|
|
]);
|
|
|
|
if (isset($menu['children'])) {
|
|
$this->createMenus($menu['children'], $mm->id);
|
|
}
|
|
}
|
|
}
|
|
}
|