diff --git a/app/Admin/Components.php b/app/Admin/Components.php index da89c02..93b66ee 100644 --- a/app/Admin/Components.php +++ b/app/Admin/Components.php @@ -6,13 +6,46 @@ use Slowlyo\OwlAdmin\Renderers\BaseRenderer; class Components extends BaseRenderer { + /** + * 父级选择器 + */ public function parentControl($apiUrl = '', $name ='parent_id', $labelField = 'name', $valueField = 'id') { return amisMake()->TreeSelectControl() - ->name('parent_id')->label('父级') + ->name($name)->label('父级') ->showIcon(false) ->labelField($labelField) ->valueField($valueField) ->value(0)->source($apiUrl); } + + /** + * 排序字段 + */ + public function sortControl($name ='sort', $label = '排序'){ + return amisMake()->NumberControl()->name($name)->label($label)->min(0); + } + + /** + * 富文本编辑器 + */ + public function fuEditorControl($name ='content', $label = '内容', $uploadUrl = ''){ + return amisMake()->RichTextControl()->vendor('tinymce') + ->options([ + "menubar"=>false, + "min_height" => 500, + "toolbar"=> "undo redo | formatselect | bold italic backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | removeformat | link image | help", + "help_tabs" => [] + ]) + ->name($name)->label($label); + + //froala去除授权提示;(但是保存会有额外内容,需要处理) + // + } } \ No newline at end of file diff --git a/app/Admin/Controllers/AdminNoticeController.php b/app/Admin/Controllers/AdminNoticeController.php new file mode 100644 index 0000000..b7646a1 --- /dev/null +++ b/app/Admin/Controllers/AdminNoticeController.php @@ -0,0 +1,62 @@ +baseCRUD() + ->filterTogglable(false) + ->headerToolbar([ + $this->createButton(true, 'lg'), + ...$this->baseHeaderToolBar(), + ]) + ->columns([ + TableColumn::make()->name('id')->label('ID')->sortable(true), + TableColumn::make()->name('title')->label('标题'), + TableColumn::make()->name('article_id')->label('关联文章')->className('text-primary'), + TableColumn::make()->name('is_enable')->type('switch')->label('显示'), + TableColumn::make()->name('published_at')->label('发布时间')->type('datetime')->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, 'lg'), + ]); + + return $this->baseList($crud); + } + + public function form(): Form + { + return $this->baseForm()->body([ + \amisMake()->TextControl()->name('title')->label('标题')->required(true), + Components::make()->fuEditorControl(), + \amisMake()->SelectControl()->name('article_id')->label('关联文章'), + Components::make()->sortControl(), + \amisMake()->DateTimeControl()->name('published_at')->label('发布时间')->description('*不填写则默认为创建时间'), + \amisMake()->SwitchControl()->name('is_enable')->label('显示'), + ]); + } + + public function detail(): Form + { + return $this->baseDetail()->body([ + TextControl::make()->static(true)->name('id')->label('ID'), + TextControl::make()->static(true)->name('title')->label('标题'), + TextControl::make()->static(true)->name('created_at')->label('创建时间'), + TextControl::make()->static(true)->name('updated_at')->label('更新时间') + ]); + } +} diff --git a/app/Admin/routes.php b/app/Admin/routes.php index d491d79..6f70672 100644 --- a/app/Admin/routes.php +++ b/app/Admin/routes.php @@ -16,9 +16,10 @@ Route::group([ $router->resource('dashboard', \App\Admin\Controllers\HomeController::class); - $router->resource('keywords', \App\Admin\Controllers\KeywordController::class); + //公告管理 + $router->resource('admin-notices', \App\Admin\Controllers\AdminNoticeController::class); - // $router->resource('system/re-roles', \App\Admin\Controllers\AdminRoleController::class); + $router->resource('keywords', \App\Admin\Controllers\KeywordController::class); $router->resource('system/settings', \App\Admin\Controllers\SettingController::class); }); diff --git a/app/Models/AdminNotice.php b/app/Models/AdminNotice.php new file mode 100644 index 0000000..00ea281 --- /dev/null +++ b/app/Models/AdminNotice.php @@ -0,0 +1,16 @@ +id(); + $table->string('title')->comment('标题'); + $table->text('content')->nullable()->comment('内容'); + $table->unsignedBigInteger('article_id')->nullable()->comment('关联文章ID'); + $table->string('remark')->nullable()->comment('备注'); + $table->timestamp('published_at')->nullable()->comment('发布时间'); + $table->unsignedTinyInteger('is_enable')->default(1)->comment('显示开关'); + $table->unsignedInteger('sort')->default(0)->comment('排序'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('admin_notices'); + } +}; diff --git a/database/seeders/AdminMenuSeeder.php b/database/seeders/AdminMenuSeeder.php index 6516b40..887611e 100644 --- a/database/seeders/AdminMenuSeeder.php +++ b/database/seeders/AdminMenuSeeder.php @@ -22,7 +22,7 @@ class AdminMenuSeeder extends Seeder ['title' => '主页', 'icon' => 'icon-park:home-two', 'url' => '/dashboard', 'is_home'=>1], ['title' => '公众号管理', 'icon' => 'icon-park:wechat', 'url' => '', 'children' => [ - ['title' => '公告管理', 'icon' => 'icon-park:volume-notice', 'url' => '/notices'], + ['title' => '公告管理', 'icon' => 'icon-park:volume-notice', 'url' => '/admin-notices'], ['title' => '文章分类', 'icon' => 'icon-park:book-one', 'url' => '/article-categories'], ['title' => '文章管理', 'icon' => 'icon-park:file-search', 'url' => '/articles'], ['title' => '图片位置', 'icon' => 'icon-park:graphic-design-two', 'url' => '/banner-addresses'],