添加菜单迁移文件
parent
4296f66090
commit
2b44bc6824
|
|
@ -25,7 +25,7 @@ class HomeController extends AdminController
|
|||
{
|
||||
$page = $this->basePage()->css($this->css())->body([
|
||||
Grid::make()->columns([
|
||||
$this->frameworkInfo()->md(5),
|
||||
// $this->frameworkInfo()->md(5),
|
||||
Flex::make()->items([
|
||||
$this->pieChart(),
|
||||
$this->cube(),
|
||||
|
|
@ -35,7 +35,7 @@ class HomeController extends AdminController
|
|||
$this->lineChart()->md(8),
|
||||
Flex::make()->className('h-full')->items([
|
||||
$this->clock(),
|
||||
$this->giteeWidget(),
|
||||
// $this->giteeWidget(),
|
||||
])->direction('column'),
|
||||
]),
|
||||
]);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
namespace App\Admin\Controllers;
|
||||
|
||||
use Slowlyo\OwlAdmin\Renderers\Page;
|
||||
use Slowlyo\OwlAdmin\Renderers\Form;
|
||||
use Slowlyo\OwlAdmin\Renderers\TableColumn;
|
||||
use Slowlyo\OwlAdmin\Renderers\TextControl;
|
||||
use Slowlyo\OwlAdmin\Controllers\AdminController;
|
||||
use App\Services\Admin\KeywordService;
|
||||
|
||||
class KeywordController extends AdminController
|
||||
{
|
||||
protected string $serviceName = KeywordService::class;
|
||||
|
||||
protected string $pageTitle = '字典管理';
|
||||
|
||||
public function list(): Page
|
||||
{
|
||||
$crud = $this->baseCRUD()
|
||||
->filterTogglable(false)
|
||||
->headerToolbar([
|
||||
$this->createButton(true),
|
||||
...$this->baseHeaderToolBar(),
|
||||
])
|
||||
->columns([
|
||||
TableColumn::make()->name('id')->label('ID')->sortable(true),
|
||||
TableColumn::make()->name('created_at')->label('创建时间')->type('datetime')->sortable(true),
|
||||
TableColumn::make()->name('updated_at')->label('更新时间')->type('datetime')->sortable(true),
|
||||
$this->rowActions(true),
|
||||
]);
|
||||
|
||||
return $this->baseList($crud);
|
||||
}
|
||||
|
||||
public function form(): Form
|
||||
{
|
||||
return $this->baseForm()->body([
|
||||
TextControl::make()->name('id')->label('Id'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function detail(): Form
|
||||
{
|
||||
return $this->baseDetail()->body([
|
||||
TextControl::make()->static(true)->name('id')->label('ID'),
|
||||
TextControl::make()->static(true)->name('created_at')->label('创建时间'),
|
||||
TextControl::make()->static(true)->name('updated_at')->label('更新时间')
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Keyword extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services\Admin;
|
||||
|
||||
use App\Models\Keyword;
|
||||
use Slowlyo\OwlAdmin\Services\AdminService;
|
||||
|
||||
/**
|
||||
* @method Keyword getModel()
|
||||
* @method Keyword|\Illuminate\Database\Query\Builder query()
|
||||
*/
|
||||
class KeywordService extends AdminService
|
||||
{
|
||||
protected string $modelName = Keyword::class;
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
return [
|
||||
// 应用名称
|
||||
'name' => 'Owl Admin',
|
||||
'name' => '农业园区平台',
|
||||
|
||||
// 应用 logo
|
||||
'logo' => '/admin/logo.png',
|
||||
|
|
|
|||
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('keywords', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('key')->unique();
|
||||
$table->string('name')->comment('名字');
|
||||
$table->string('value')->nullable();
|
||||
$table->string('type_key')->nullable();
|
||||
$table->unsignedInteger('sort')->default(0)->comment('排序');
|
||||
$table->unsignedBigInteger('parent_id')->default(0)->comment('上级ID');
|
||||
$table->unsignedInteger('level')->default(1)->comment('层级');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('keywords');
|
||||
}
|
||||
};
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
<?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],
|
||||
['title' => '区域管理', 'icon' => 'icon-park:category-management', 'url' => '',
|
||||
'children' => [
|
||||
['title' => '分类管理', 'icon' => 'icon-park:graphic-stitching-four', 'url' => '/region-categories'],
|
||||
['title' => '实验田', 'icon' => 'icon-park:freezing-line-column', 'url' => '/regions'],
|
||||
]
|
||||
],
|
||||
['title' => '育秧中心', 'icon' => 'icon-park:lotus', 'url' => '/devices'],
|
||||
['title' => '实验稻田', 'icon' => 'icon-park:four-leaves', 'url' => '/devices'],
|
||||
|
||||
['title' => '设备管理', 'icon' => 'icon-park:devices', 'url' => '/devices'],
|
||||
['title' => '系统管理', 'icon' => 'icon-park:setting', 'url' => '/system',
|
||||
'children' => [
|
||||
['title' => '用户管理', 'icon' => 'icon-park:people-plus', 'url' => '/system/admin_users'],
|
||||
['title' => '角色管理', 'icon' => 'icon-park:people-plus-one', 'url' => '/system/admin_roles'],
|
||||
['title' => '权限管理', 'icon' => 'icon-park:key-one', 'url' => '/system/admin_permissions'],
|
||||
['title' => '菜单管理', 'icon' => 'icon-park:menu-fold-one', 'url' => '/system/admin_menus'],
|
||||
['title' => '字典管理', 'icon' => 'icon-park:arrow-keys', 'url' => '/keywords'],
|
||||
],
|
||||
],
|
||||
];
|
||||
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,
|
||||
]);
|
||||
|
||||
if (isset($menu['children'])) {
|
||||
$this->createMenus($menu['children'], $mm->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue