admin-notice
parent
994e0c7895
commit
0fae071c1b
|
|
@ -2,42 +2,38 @@
|
|||
|
||||
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\Renderers\{Form, Page};
|
||||
use Slowlyo\OwlAdmin\Renderers\{Component, Button, TableColumn, TextControl, SelectControl, DateTimeControl, SwitchControl, Tabs, Tab, Status, Html};
|
||||
use Slowlyo\OwlAdmin\Controllers\AdminController;
|
||||
use App\Services\Admin\AdminNoticeService;
|
||||
use App\Admin\Components;
|
||||
use Slowlyo\OwlAdmin\OwlAdmin;
|
||||
|
||||
class AdminNoticeController extends AdminController
|
||||
{
|
||||
protected string $serviceName = AdminNoticeService::class;
|
||||
|
||||
protected string $pageTitle = '公告管理';//待完善-todo
|
||||
|
||||
public function list(): Page
|
||||
{
|
||||
$options = [];
|
||||
$user = OwlAdmin::user();
|
||||
// 添加权限
|
||||
if ($user->can('admin_notice.create')) {
|
||||
array_push($options, $this->createButton(true, 'lg'));
|
||||
}
|
||||
$options = array_merge($options, $this->baseHeaderToolBar(),);
|
||||
$crud = $this->baseCRUD()
|
||||
->filterTogglable(false)
|
||||
->headerToolbar($options)
|
||||
->filter($this->baseFilter()->actions([])->body([
|
||||
TextControl::make()->name('title')->label(__('admin-notice.title'))->size('md'),
|
||||
Button::make()->label(__('admin.reset'))->actionType('clear-and-submit'),
|
||||
Component::make()->setType('submit')->label(__('admin.search'))->level('primary'),
|
||||
]))
|
||||
->quickSaveItemApi(admin_url('quick-edit/admin-notices/$id'))
|
||||
->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'),
|
||||
TableColumn::make()->name('id')->label(__('admin-notice.id'))->sortable(true),
|
||||
TableColumn::make()->name('title')->label(__('admin-notice.title')),
|
||||
TableColumn::make()
|
||||
->name('article.title')
|
||||
->label(__('admin-notice.article_id')),
|
||||
// ->type('button')
|
||||
// ->actionType('link')
|
||||
// ->link('articles/${article_id}'),
|
||||
TableColumn::make()->name('is_enable')->type('switch')->label(__('admin-notice.is_enable'))->quickEdit(SwitchControl::make()->saveImmediately(true)->mode('inline')),
|
||||
TableColumn::make()->name('published_at')->label(__('admin-notice.published_at')),
|
||||
$this->rowActions(),
|
||||
]);
|
||||
|
||||
return $this->baseList($crud);
|
||||
|
|
@ -45,25 +41,37 @@ class AdminNoticeController extends AdminController
|
|||
|
||||
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('显示'),
|
||||
]);
|
||||
return $this->baseForm()->title('')->body(
|
||||
Tabs::make()->tabs([
|
||||
Tab::make()->title('基本信息')->body([
|
||||
TextControl::make()->name('title')->label(__('admin-notice.title'))->required(true),
|
||||
SelectControl::make()->name('article_id')->label(__('admin-notice.article_id'))->source(admin_url('api/articles/options')),
|
||||
Components::make()->sortControl('sort', __('admin-notice.sort')),
|
||||
DateTimeControl::make()->name('published_at')->label(__('admin-notice.published_at'))->value(now())->format('YYYY-MM-DD HH:mm:ss')->description('*不填写则默认为创建时间'),
|
||||
SwitchControl::make()->name('is_enable')->label(__('admin-notice.is_enable'))->value(true),
|
||||
]),
|
||||
Tab::make()->title(__('admin-notice.content'))->body(Components::make()->fuEditorControl('content', ''))
|
||||
]));
|
||||
}
|
||||
|
||||
public function detail(): Form
|
||||
{
|
||||
return $this->baseDetail()->body([
|
||||
TextControl::make()->static(true)->name('id')->label('ID'),
|
||||
TextControl::make()->static(true)->name('title')->label('标题'),
|
||||
//-todo
|
||||
|
||||
TextControl::make()->static(true)->name('created_at')->label('创建时间'),
|
||||
TextControl::make()->static(true)->name('updated_at')->label('更新时间')
|
||||
]);
|
||||
return $this->baseDetail()->title('')->body(
|
||||
Tabs::make()->tabs([
|
||||
Tab::make()->title('基本信息')->body([
|
||||
TextControl::make()->static(true)->name('id')->label(__('admin-notice.id')),
|
||||
TextControl::make()->static(true)->name('title')->label(__('admin-notice.title')),
|
||||
TextControl::make()->static(true)->name('article.title')->label(__('admin-notice.article_id')),
|
||||
TextControl::make()->static(true)->name('sort')->label(__('admin-notice.sort')),
|
||||
TextControl::make()->name('is_enable')->label(__('admin-notice.is_enable'))->static(true)->staticSchema(Status::make()->source([
|
||||
['label' => '不显示', 'icon' => 'fa fa-close', 'color' => '#cc292e'],
|
||||
['label' => '显示', 'icon' => 'fa fa-check', 'color' => '#30bf13'],
|
||||
])),
|
||||
TextControl::make()->static(true)->name('published_at')->label(__('admin-notice.published_at')),
|
||||
TextControl::make()->static(true)->name('created_at')->label(__('admin-notice.created_at')),
|
||||
]),
|
||||
Tab::make()->title(__('admin-notice.content'))->body(Html::make()->name('content'))
|
||||
])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,4 +76,11 @@ class ArticleController extends AdminController
|
|||
])
|
||||
);
|
||||
}
|
||||
|
||||
public function options()
|
||||
{
|
||||
$list = $this->service->listQuery()->select(['id as value', 'title as label'])->without('category')->show()->get();
|
||||
|
||||
return $this->response()->success($list);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ Route::group([
|
|||
], function (Router $router) {
|
||||
$router->get('keywords/tree-list', '\App\Admin\Controllers\KeywordController@getTreeList')->name('api.keywords.tree-list');
|
||||
$router->get('article-categories/tree-list', [\App\Admin\Controllers\ArticleCategoryController::class, 'getTreeList'])->name('api.article-categories.tree-list');
|
||||
$router->get('articles/options', [\App\Admin\Controllers\ArticleController::class, 'options'])->name('api.articles.options');
|
||||
$router->get('region-categories/tree-list', '\App\Admin\Controllers\RegionCategoryController@getTreeList')->name('api.region-categories.tree-list');
|
||||
});
|
||||
|
||||
|
|
@ -21,6 +22,7 @@ Route::group([
|
|||
|
||||
//公告管理
|
||||
$router->resource('admin-notices', \App\Admin\Controllers\AdminNoticeController::class);
|
||||
$router->post('quick-edit/admin-notices/{admin_notice}',[ \App\Admin\Controllers\AdminNoticeController::class, 'update']);
|
||||
// 文章分类
|
||||
$router->resource('article-categories', \App\Admin\Controllers\ArticleCategoryController::class);
|
||||
$router->post('quick-edit/article-categories/{article_category}', [\App\Admin\Controllers\ArticleCategoryController::class, 'update']);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace App\Filters;
|
||||
|
||||
use EloquentFilter\ModelFilter;
|
||||
|
||||
class AdminNoticeFilter extends ModelFilter
|
||||
{
|
||||
/**
|
||||
* Related Models that have ModelFilters as well as the method on the ModelFilter
|
||||
* As [relationMethod => [input_key1, input_key2]].
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $relations = [];
|
||||
|
||||
public function title($v)
|
||||
{
|
||||
$this->whereLike('title', $v);
|
||||
}
|
||||
}
|
||||
|
|
@ -2,18 +2,33 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use EloquentFilter\Filterable;
|
||||
|
||||
class AdminNotice extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use Filterable;
|
||||
|
||||
protected $fillable = ['title', 'content', 'article_id', 'remark', 'is_enable', 'published_at' ,'sort'];
|
||||
protected $casts = [
|
||||
'published_at' => 'datetime:Y-m-d H:i:s',
|
||||
'created_at' => 'datetime:Y-m-d H:i:s',
|
||||
'updated_at' => 'datetime:Y-m-d H:i:s',
|
||||
'is_enable' => 'boolean'
|
||||
];
|
||||
|
||||
protected function serializeDate(\DateTimeInterface $date){
|
||||
return $date->format('Y-m-d H:i:s');
|
||||
public function article()
|
||||
{
|
||||
return $this->belongsTo(Article::class, 'article_id');
|
||||
}
|
||||
|
||||
public function scopeSort($q)
|
||||
{
|
||||
return $q->orderBy('sort', 'desc')->orderBy('published_at', 'desc');
|
||||
}
|
||||
|
||||
public function scopeShow($q)
|
||||
{
|
||||
return $q->where('is_enable', 1)->where('published_at', '<=', now());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,6 +44,6 @@ class Article extends Model
|
|||
|
||||
public function scopeShow($q)
|
||||
{
|
||||
return $q->where('is_enable', 1)->where(fn ($q1) => $q1->whereNull('published_at')->orWhere('published_at', '<=', now()));
|
||||
return $q->where('is_enable', 1)->where('published_at', '<=', now());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,13 +3,34 @@
|
|||
namespace App\Services\Admin;
|
||||
|
||||
use App\Models\AdminNotice;
|
||||
use Slowlyo\OwlAdmin\Services\AdminService;
|
||||
use App\Filters\AdminNoticeFilter;
|
||||
|
||||
/**
|
||||
* @method AdminNotice getModel()
|
||||
* @method AdminNotice|\Illuminate\Database\Query\Builder query()
|
||||
*/
|
||||
class AdminNoticeService extends AdminService
|
||||
class AdminNoticeService extends BaseService
|
||||
{
|
||||
protected string $modelName = AdminNotice::class;
|
||||
|
||||
protected string $modelFilterName = AdminNoticeFilter::class;
|
||||
|
||||
protected array $withRelationships = ['article'];
|
||||
|
||||
public function listQuery()
|
||||
{
|
||||
$model = $this->getModel();
|
||||
$filter = $this->getModelFilter();
|
||||
|
||||
$query = $this->query();
|
||||
if($this->withRelationships){
|
||||
$query->with($this->withRelationships);
|
||||
}
|
||||
|
||||
if ($filter) {
|
||||
$query->filter(request()->input(), $filter);
|
||||
}
|
||||
|
||||
return $query->sort();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
'id' => 'ID',
|
||||
'title' => '标题',
|
||||
'content' => '内容',
|
||||
'article_id' => '关联文章',
|
||||
'remark' => '备注',
|
||||
'is_enable' => '显示',
|
||||
'published_at' => '发布时间',
|
||||
'sort' => '排序(倒序)',
|
||||
'created_at' => '创建时间',
|
||||
];
|
||||
Loading…
Reference in New Issue