1
0
Fork 0

Compare commits

..

No commits in common. "b67e8f04af767df56313202d8eef62d644df6585" and "87b76c331122fed90dc0a4a1dfecd8cf46b30a31" have entirely different histories.

14 changed files with 68 additions and 240 deletions

View File

@ -2,38 +2,42 @@
namespace App\Admin\Controllers; namespace App\Admin\Controllers;
use Slowlyo\OwlAdmin\Renderers\{Form, Page}; use Slowlyo\OwlAdmin\Renderers\Page;
use Slowlyo\OwlAdmin\Renderers\{Component, Button, TableColumn, TextControl, SelectControl, DateTimeControl, SwitchControl, Tabs, Tab, Status, Html}; use Slowlyo\OwlAdmin\Renderers\Form;
use Slowlyo\OwlAdmin\Renderers\TableColumn;
use Slowlyo\OwlAdmin\Renderers\TextControl;
use Slowlyo\OwlAdmin\Controllers\AdminController; use Slowlyo\OwlAdmin\Controllers\AdminController;
use App\Services\Admin\AdminNoticeService; use App\Services\Admin\AdminNoticeService;
use App\Admin\Components; use App\Admin\Components;
use Slowlyo\OwlAdmin\OwlAdmin;
class AdminNoticeController extends AdminController class AdminNoticeController extends AdminController
{ {
protected string $serviceName = AdminNoticeService::class; protected string $serviceName = AdminNoticeService::class;
protected string $pageTitle = '公告管理';//待完善-todo
public function list(): Page 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() $crud = $this->baseCRUD()
->filterTogglable(false) ->filterTogglable(false)
->filter($this->baseFilter()->actions([])->body([ ->headerToolbar($options)
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([ ->columns([
TableColumn::make()->name('id')->label(__('admin-notice.id'))->sortable(true), TableColumn::make()->name('id')->label('ID')->sortable(true),
TableColumn::make()->name('title')->label(__('admin-notice.title')), TableColumn::make()->name('title')->label('标题'),
TableColumn::make() TableColumn::make()->name('article_id')->label('关联文章')->className('text-primary'),
->name('article.title') TableColumn::make()->name('is_enable')->type('switch')->label('显示'),
->label(__('admin-notice.article_id')), TableColumn::make()->name('published_at')->label('发布时间')->type('datetime')->sortable(true),
// ->type('button') TableColumn::make()->name('created_at')->label('创建时间')->type('datetime')->sortable(true),
// ->actionType('link') // TableColumn::make()->name('updated_at')->label('更新时间')->type('datetime')->sortable(true),
// ->link('articles/${article_id}'), $this->rowActions(true, 'lg'),
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); return $this->baseList($crud);
@ -41,37 +45,25 @@ class AdminNoticeController extends AdminController
public function form(): Form public function form(): Form
{ {
return $this->baseForm()->title('')->body( return $this->baseForm()->body([
Tabs::make()->tabs([ \amisMake()->TextControl()->name('title')->label('标题')->required(true),
Tab::make()->title('基本信息')->body([ Components::make()->fuEditorControl(),
TextControl::make()->name('title')->label(__('admin-notice.title'))->required(true), \amisMake()->SelectControl()->name('article_id')->label('关联文章'),
SelectControl::make()->name('article_id')->label(__('admin-notice.article_id'))->source(admin_url('api/articles/options')), Components::make()->sortControl(),
Components::make()->sortControl('sort', __('admin-notice.sort')), \amisMake()->DateTimeControl()->name('published_at')->label('发布时间')->description('*不填写则默认为创建时间'),
DateTimeControl::make()->name('published_at')->label(__('admin-notice.published_at'))->value(now())->format('YYYY-MM-DD HH:mm:ss')->description('*不填写则默认为创建时间'), \amisMake()->SwitchControl()->name('is_enable')->label('显示'),
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 public function detail(): Form
{ {
return $this->baseDetail()->title('')->body( return $this->baseDetail()->body([
Tabs::make()->tabs([ TextControl::make()->static(true)->name('id')->label('ID'),
Tab::make()->title('基本信息')->body([ TextControl::make()->static(true)->name('title')->label('标题'),
TextControl::make()->static(true)->name('id')->label(__('admin-notice.id')), //-todo
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('created_at')->label('创建时间'),
TextControl::make()->static(true)->name('sort')->label(__('admin-notice.sort')), TextControl::make()->static(true)->name('updated_at')->label('更新时间')
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'))
])
);
} }
} }

View File

@ -76,11 +76,4 @@ 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);
}
} }

View File

@ -2,8 +2,10 @@
namespace App\Admin\Controllers; namespace App\Admin\Controllers;
use Slowlyo\OwlAdmin\Renderers\{Form, Page}; use Slowlyo\OwlAdmin\Renderers\Page;
use Slowlyo\OwlAdmin\Renderers\{TableColumn, TextControl, SwitchControl, NumberControl, Status, Button, Component}; use Slowlyo\OwlAdmin\Renderers\Form;
use Slowlyo\OwlAdmin\Renderers\TableColumn;
use Slowlyo\OwlAdmin\Renderers\TextControl;
use Slowlyo\OwlAdmin\Controllers\AdminController; use Slowlyo\OwlAdmin\Controllers\AdminController;
use App\Services\Admin\BannerPlaceService; use App\Services\Admin\BannerPlaceService;
@ -11,7 +13,7 @@ class BannerPlaceController extends AdminController
{ {
protected string $serviceName = BannerPlaceService::class; protected string $serviceName = BannerPlaceService::class;
protected string $pageTitle = '图片位置'; protected string $pageTitle = '图片位置';//待完善-todo
public function list(): Page public function list(): Page
{ {
@ -21,19 +23,11 @@ class BannerPlaceController extends AdminController
$this->createButton(true), $this->createButton(true),
...$this->baseHeaderToolBar(), ...$this->baseHeaderToolBar(),
]) ])
->quickSaveItemApi(admin_url('quick-edit/banner-places/$id'))
->filter($this->baseFilter()->actions([])->body([
TextControl::make()->name('key')->label(__('banner-place.key'))->size('md'),
TextControl::make()->name('name')->label(__('banner-place.name'))->size('md'),
Button::make()->label(__('admin.reset'))->actionType('clear-and-submit'),
Component::make()->setType('submit')->label(__('admin.search'))->level('primary'),
]))
->columns([ ->columns([
TableColumn::make()->name('id')->label(__('banner-place.id')), TableColumn::make()->name('id')->label('ID')->sortable(true),
TableColumn::make()->name('key')->label(__('banner-place.key')), TableColumn::make()->name('name')->label('名称'),
TableColumn::make()->name('name')->label(__('banner-place.name')), TableColumn::make()->name('created_at')->label('创建时间')->type('datetime')->sortable(true),
TableColumn::make()->name('is_enable')->type('switch')->label(__('banner-place.is_enable'))->quickEdit(SwitchControl::make()->saveImmediately(true)->mode('inline')), TableColumn::make()->name('updated_at')->label('更新时间')->type('datetime')->sortable(true),
TableColumn::make()->name('remark')->label(__('banner-place.remark'))->quickEdit(TextControl::make()->saveImmediately(true)),
$this->rowActions(true), $this->rowActions(true),
]); ]);
@ -42,12 +36,10 @@ class BannerPlaceController extends AdminController
public function form(): Form public function form(): Form
{ {
return $this->baseForm()->title('')->body([ return $this->baseForm()->body([
TextControl::make()->name('key')->label('KEY')->required(true),
TextControl::make()->name('name')->label('名称')->required(true), TextControl::make()->name('name')->label('名称')->required(true),
NumberControl::make()->name('width')->label(__('banner-place.width'))->step(1)->min(0), TextControl::make()->name('key')->label('KEY')->required(true),
NumberControl::make()->name('height')->label(__('banner-place.height'))->step(1)->min(0), \amisMake()->SwitchControl()->name('is_enable')->label('显示'),
SwitchControl::make()->name('is_enable')->label(__('banner-place.is_enable'))->value(true),
TextControl::make()->name('remark')->label('备注'), TextControl::make()->name('remark')->label('备注'),
]); ]);
} }
@ -55,16 +47,10 @@ class BannerPlaceController extends AdminController
public function detail(): Form public function detail(): Form
{ {
return $this->baseDetail()->body([ return $this->baseDetail()->body([
TextControl::make()->static(true)->name('id')->label(__('banner-place.id')), TextControl::make()->static(true)->name('id')->label('ID'),
TextControl::make()->static(true)->name('name')->label(__('banner-place.name')), TextControl::make()->static(true)->name('name')->label('名称'),
TextControl::make()->static(true)->name('width')->label(__('banner-place.width')), TextControl::make()->static(true)->name('created_at')->label('创建时间'),
TextControl::make()->static(true)->name('height')->label(__('banner-place.height')), TextControl::make()->static(true)->name('updated_at')->label('更新时间')
TextControl::make()->name('is_enable')->label(__('banner-place.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('remark')->label(__('banner-place.remark')),
TextControl::make()->static(true)->name('created_at')->label(__('banner-place.created_at')),
]); ]);
} }
} }

View File

@ -14,7 +14,6 @@ Route::group([
], function (Router $router) { ], function (Router $router) {
$router->get('keywords/tree-list', '\App\Admin\Controllers\KeywordController@getTreeList')->name('api.keywords.tree-list'); $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('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'); $router->get('region-categories/tree-list', '\App\Admin\Controllers\RegionCategoryController@getTreeList')->name('api.region-categories.tree-list');
}); });
@ -22,7 +21,6 @@ Route::group([
//公告管理 //公告管理
$router->resource('admin-notices', \App\Admin\Controllers\AdminNoticeController::class); $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->resource('article-categories', \App\Admin\Controllers\ArticleCategoryController::class);
$router->post('quick-edit/article-categories/{article_category}', [\App\Admin\Controllers\ArticleCategoryController::class, 'update']); $router->post('quick-edit/article-categories/{article_category}', [\App\Admin\Controllers\ArticleCategoryController::class, 'update']);
@ -32,7 +30,6 @@ Route::group([
$router->post('quick-edit/article/{article}', [\App\Admin\Controllers\ArticleController::class, 'update']); $router->post('quick-edit/article/{article}', [\App\Admin\Controllers\ArticleController::class, 'update']);
//图片位置 //图片位置
$router->resource('banner-places', \App\Admin\Controllers\BannerPlaceController::class); $router->resource('banner-places', \App\Admin\Controllers\BannerPlaceController::class);
$router->post('quick-edit/banner-places/{banner_place}',[ \App\Admin\Controllers\BannerPlaceController::class, 'update']);
//图片管理 //图片管理
$router->resource('banners', \App\Admin\Controllers\BannerController::class); $router->resource('banners', \App\Admin\Controllers\BannerController::class);
//友情链接 //友情链接

View File

@ -1,21 +0,0 @@
<?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);
}
}

View File

@ -1,25 +0,0 @@
<?php
namespace App\Filters;
use EloquentFilter\ModelFilter;
class BannerPlaceFilter 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 key($v)
{
$this->whereLike('key', $v);
}
public function name($v)
{
$this->whereLike('name', $v);
}
}

View File

@ -2,33 +2,18 @@
namespace App\Models; namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use EloquentFilter\Filterable; use EloquentFilter\Filterable;
class AdminNotice extends Model class AdminNotice extends Model
{ {
use HasFactory;
use Filterable; use Filterable;
protected $fillable = ['title', 'content', 'article_id', 'remark', 'is_enable', 'published_at' ,'sort']; 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'
];
public function article() protected function serializeDate(\DateTimeInterface $date){
{ return $date->format('Y-m-d H:i:s');
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());
} }
} }

View File

@ -44,6 +44,6 @@ class Article extends Model
public function scopeShow($q) public function scopeShow($q)
{ {
return $q->where('is_enable', 1)->where('published_at', '<=', now()); return $q->where('is_enable', 1)->where(fn ($q1) => $q1->whereNull('published_at')->orWhere('published_at', '<=', now()));
} }
} }

View File

@ -40,11 +40,6 @@ class ArticleCategory extends Model
return $this->hasMany(static::class, 'parent_id'); return $this->hasMany(static::class, 'parent_id');
} }
public function articles()
{
return $this->hasMany(Article::class, 'category_id');
}
public function scopeSort($q) public function scopeSort($q)
{ {
return $q->orderBy('sort', 'desc'); return $q->orderBy('sort', 'desc');

View File

@ -2,28 +2,10 @@
namespace App\Models; namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use EloquentFilter\Filterable;
class BannerPlace extends Model class BannerPlace extends Model
{ {
use Filterable; use HasFactory;
protected $fillable = ['height', 'is_enable', 'key', 'name', 'remark', 'width'];
protected $casts = [
'created_at' => 'datetime:Y-m-d H:i:s',
'updated_at' => 'datetime:Y-m-d H:i:s',
'is_enable' => 'boolean',
];
public function banners()
{
return $this->hasMany(Banner::class, 'place_id');
}
public function scopeEnable($q)
{
return $q->where('is_enable', 1);
}
} }

View File

@ -3,34 +3,13 @@
namespace App\Services\Admin; namespace App\Services\Admin;
use App\Models\AdminNotice; use App\Models\AdminNotice;
use App\Filters\AdminNoticeFilter; use Slowlyo\OwlAdmin\Services\AdminService;
/** /**
* @method AdminNotice getModel() * @method AdminNotice getModel()
* @method AdminNotice|\Illuminate\Database\Query\Builder query() * @method AdminNotice|\Illuminate\Database\Query\Builder query()
*/ */
class AdminNoticeService extends BaseService class AdminNoticeService extends AdminService
{ {
protected string $modelName = AdminNotice::class; 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();
}
} }

View File

@ -2,24 +2,14 @@
namespace App\Services\Admin; namespace App\Services\Admin;
use App\Models\{BannerPlace, Banner}; use App\Models\BannerPlace;
use App\Filters\BannerPlaceFilter; use Slowlyo\OwlAdmin\Services\AdminService;
/** /**
* @method BannerPlace getModel() * @method BannerPlace getModel()
* @method BannerPlace|\Illuminate\Database\Query\Builder query() * @method BannerPlace|\Illuminate\Database\Query\Builder query()
*/ */
class BannerPlaceService extends BaseService class BannerPlaceService extends AdminService
{ {
protected string $modelName = BannerPlace::class; protected string $modelName = BannerPlace::class;
protected string $modelFilterName = BannerPlaceFilter::class;
public function delete(string $ids): mixed
{
$id = explode(',', $ids);
// 删除广告
Banner::whereIn('place_id', $id)->delete();
return parent::delete($ids);
}
} }

View File

@ -1,13 +0,0 @@
<?php
return [
'id' => 'ID',
'title' => '标题',
'content' => '内容',
'article_id' => '关联文章',
'remark' => '备注',
'is_enable' => '显示',
'published_at' => '发布时间',
'sort' => '排序(倒序)',
'created_at' => '创建时间',
];

View File

@ -1,12 +0,0 @@
<?php
return [
'id' => 'ID',
'created_at' => '创建时间',
'height' => '高度(px)',
'is_enable' => '显示',
'key' => 'KEY',
'name' => '名称',
'remark' => '备注',
'width' => '宽度(px)',
];