banner
parent
b67e8f04af
commit
7baf63523d
|
|
@ -2,10 +2,8 @@
|
||||||
|
|
||||||
namespace App\Admin\Controllers;
|
namespace App\Admin\Controllers;
|
||||||
|
|
||||||
use Slowlyo\OwlAdmin\Renderers\Page;
|
use Slowlyo\OwlAdmin\Renderers\{Page, Form};
|
||||||
use Slowlyo\OwlAdmin\Renderers\Form;
|
use Slowlyo\OwlAdmin\Renderers\{TableColumn, TextControl, Image, ImageControl, SelectControl, SwitchControl, DateTimeControl, InputKV, Status, Json};
|
||||||
use Slowlyo\OwlAdmin\Renderers\TableColumn;
|
|
||||||
use Slowlyo\OwlAdmin\Renderers\TextControl;
|
|
||||||
use Slowlyo\OwlAdmin\Controllers\AdminController;
|
use Slowlyo\OwlAdmin\Controllers\AdminController;
|
||||||
use App\Services\Admin\BannerService;
|
use App\Services\Admin\BannerService;
|
||||||
use App\Admin\Components;
|
use App\Admin\Components;
|
||||||
|
|
@ -14,22 +12,22 @@ class BannerController extends AdminController
|
||||||
{
|
{
|
||||||
protected string $serviceName = BannerService::class;
|
protected string $serviceName = BannerService::class;
|
||||||
|
|
||||||
protected string $pageTitle = '图片管理';//待完善-todo
|
|
||||||
|
|
||||||
public function list(): Page
|
public function list(): Page
|
||||||
{
|
{
|
||||||
$crud = $this->baseCRUD()
|
$crud = $this->baseCRUD()
|
||||||
->filterTogglable(false)
|
->filterTogglable(false)
|
||||||
->headerToolbar([
|
// ->headerToolbar([
|
||||||
$this->createButton(true),
|
// $this->createButton(true),
|
||||||
...$this->baseHeaderToolBar(),
|
// ...$this->baseHeaderToolBar(),
|
||||||
])
|
// ])
|
||||||
|
->quickSaveItemApi(admin_url('quick-edit/banners/$id'))
|
||||||
->columns([
|
->columns([
|
||||||
TableColumn::make()->name('id')->label('ID')->sortable(true),
|
TableColumn::make()->name('place.name')->label(__('banner.place_id')),
|
||||||
TableColumn::make()->name('name')->label('名称'),
|
TableColumn::make()->name('name')->label(__('banner.name')),
|
||||||
TableColumn::make()->name('created_at')->label('创建时间')->type('datetime')->sortable(true),
|
Image::make()->name('picture')->label(__('banner.picture'))->width(100),
|
||||||
TableColumn::make()->name('updated_at')->label('更新时间')->type('datetime')->sortable(true),
|
TableColumn::make()->name('sort')->label(__('banner.sort'))->align('center')->quickEdit(Components::make()->sortControl('sort', __('article-category.sort'))->saveImmediately(true)),
|
||||||
$this->rowActions(true),
|
TableColumn::make()->name('is_enable')->label(__('banner.is_enable'))->type('switch')->quickEdit(SwitchControl::make()->mode('inline')->saveImmediately(true)),
|
||||||
|
$this->rowActions(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $this->baseList($crud);
|
return $this->baseList($crud);
|
||||||
|
|
@ -37,23 +35,31 @@ class BannerController extends AdminController
|
||||||
|
|
||||||
public function form(): Form
|
public function form(): Form
|
||||||
{
|
{
|
||||||
return $this->baseForm()->body([
|
return $this->baseForm()->title('')->body([
|
||||||
TextControl::make()->name('name')->label('名称')->required(true),
|
SelectControl::make()->name('place_id')->label(__('banner.place_id'))->source(admin_url('api/banner-places/options'))->required(true),
|
||||||
\amisMake()->ImageControl()->name('picture')->label('图片')->autoUpload(true),
|
TextControl::make()->name('name')->label(__('banner.name'))->required(true),
|
||||||
Components::make()->parentControl('', 'place_id', '位置'),
|
ImageControl::make()->name('picture')->label(__('banner.picture'))->autoUpload(true)->required(true),
|
||||||
Components::make()->sortControl(),
|
InputKV::make()->name('link_config')->label(__('banner.link_config'))->draggable(false),
|
||||||
\amisMake()->DateTimeControl()->name('published_at')->label('发布时间')->description('*不填写则默认为创建时间'),
|
Components::make()->sortControl('sort', __('banner.sort')),
|
||||||
\amisMake()->SwitchControl()->name('is_enable')->label('显示'),
|
DateTimeControl::make()->name('published_at')->label(__('banner.published_at'))->value(now())->format('YYYY-MM-DD HH:mm:ss')->description('*不填写则默认为创建时间'),
|
||||||
|
SwitchControl::make()->name('is_enable')->label(__('banner.is_enable'))->value(true),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function detail(): Form
|
public function detail(): Form
|
||||||
{
|
{
|
||||||
return $this->baseDetail()->body([
|
return $this->baseDetail()->title('')->body([
|
||||||
TextControl::make()->static(true)->name('id')->label('ID'),
|
TextControl::make()->name('place.name')->label(__('banner.place_id'))->static(true),
|
||||||
TextControl::make()->static(true)->name('name')->label('名称'),
|
TextControl::make()->name('name')->label(__('banner.name'))->static(true),
|
||||||
TextControl::make()->static(true)->name('created_at')->label('创建时间'),
|
TextControl::make()->name('picture')->label(__('banner.picture'))->static(true)->staticSchema(Image::make()),
|
||||||
TextControl::make()->static(true)->name('updated_at')->label('更新时间')
|
TextControl::make()->name('link_config')->label(__('banner.link_config'))->static(true)->staticSchema(Json::make()),
|
||||||
|
TextControl::make()->name('sort')->label(__('banner.sort'))->static(true),
|
||||||
|
TextControl::make()->name('published_at')->label(__('banner.published_at'))->static(true),
|
||||||
|
TextControl::make()->name('is_enable')->label(__('banner.is_enable'))->static(true)->staticSchema(Status::make()->source([
|
||||||
|
['label' => '不显示', 'icon' => 'fa fa-close', 'color' => '#cc292e'],
|
||||||
|
['label' => '显示', 'icon' => 'fa fa-check', 'color' => '#30bf13'],
|
||||||
|
])),
|
||||||
|
TextControl::make()->name('created_at')->label(__('banner.created_at'))->static(true),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -67,4 +67,11 @@ class BannerPlaceController extends AdminController
|
||||||
TextControl::make()->static(true)->name('created_at')->label(__('banner-place.created_at')),
|
TextControl::make()->static(true)->name('created_at')->label(__('banner-place.created_at')),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function options()
|
||||||
|
{
|
||||||
|
$list = $this->service->listQuery()->select(['id as value', 'name as label'])->get();
|
||||||
|
|
||||||
|
return $this->response()->success($list);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ Route::group([
|
||||||
$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('articles/options', [\App\Admin\Controllers\ArticleController::class, 'options'])->name('api.articles.options');
|
||||||
|
$router->get('banner-places/options', [\App\Admin\Controllers\BannerPlaceController::class, 'options'])->name('api.banner-places.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');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -32,9 +33,10 @@ 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->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);
|
||||||
|
$router->post('quick-edit/banners/{banner}',[\App\Admin\Controllers\BannerController::class, 'update']);
|
||||||
//友情链接
|
//友情链接
|
||||||
$router->resource('friend-links', \App\Admin\Controllers\FriendLinkController::class);
|
$router->resource('friend-links', \App\Admin\Controllers\FriendLinkController::class);
|
||||||
//字典表
|
//字典表
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filters;
|
||||||
|
|
||||||
|
use EloquentFilter\ModelFilter;
|
||||||
|
|
||||||
|
class BannerFilter 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 place($id)
|
||||||
|
{
|
||||||
|
$this->where('place_id', $id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function key($v)
|
||||||
|
{
|
||||||
|
$this->whereHas('place', fn ($q) => $q->whereIn('key', explode(',', $v)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function name($v)
|
||||||
|
{
|
||||||
|
$this->whereLike('name', $v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,10 +2,46 @@
|
||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Support\Str;
|
||||||
|
use EloquentFilter\Filterable;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
|
||||||
class Banner extends Model
|
class Banner extends Model
|
||||||
{
|
{
|
||||||
use HasFactory;
|
use Filterable;
|
||||||
|
|
||||||
|
protected $fillable = ['is_enable', 'link_config', 'name', 'picture', 'place_id', 'published_at', 'sort'];
|
||||||
|
|
||||||
|
protected $casts = [
|
||||||
|
'created_at' => 'datetime:Y-m-d H:i:s',
|
||||||
|
'updated_at' => 'datetime:Y-m-d H:i:s',
|
||||||
|
'published_at' => 'datetime:Y-m-d H:i:s',
|
||||||
|
'is_enable' => 'boolean',
|
||||||
|
'link_config' => 'json',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected function picture(): Attribute
|
||||||
|
{
|
||||||
|
return Attribute::make(
|
||||||
|
get: fn($value) => $value ? (Str::startsWith($value, ['http://', 'https://']) ? $value : Storage::url($value)) : '',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function place()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(BannerPlace::class, 'place_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function scopeSort($q)
|
||||||
|
{
|
||||||
|
return $q->orderBy('sort', 'desc');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function scopeEnable($q)
|
||||||
|
{
|
||||||
|
return $q->where('is_enable', 1)->where('published_at', '<=', now());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,34 @@
|
||||||
namespace App\Services\Admin;
|
namespace App\Services\Admin;
|
||||||
|
|
||||||
use App\Models\Banner;
|
use App\Models\Banner;
|
||||||
use Slowlyo\OwlAdmin\Services\AdminService;
|
use App\Filters\BannerFilter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method Banner getModel()
|
* @method Banner getModel()
|
||||||
* @method Banner|\Illuminate\Database\Query\Builder query()
|
* @method Banner|\Illuminate\Database\Query\Builder query()
|
||||||
*/
|
*/
|
||||||
class BannerService extends AdminService
|
class BannerService extends BaseService
|
||||||
{
|
{
|
||||||
protected string $modelName = Banner::class;
|
protected string $modelName = Banner::class;
|
||||||
|
|
||||||
|
protected array $withRelationships = ['place'];
|
||||||
|
|
||||||
|
protected string $modelFilterName = BannerFilter::class;
|
||||||
|
|
||||||
|
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',
|
||||||
|
'created_at' => '创建时间',
|
||||||
|
'is_enable' => '显示',
|
||||||
|
'link_config' => '跳转',
|
||||||
|
'name' => '名称',
|
||||||
|
'picture' => '广告图',
|
||||||
|
'place_id' => '位置',
|
||||||
|
'published_at' => '发布时间',
|
||||||
|
'sort' => '排序(倒序)',
|
||||||
|
];
|
||||||
Loading…
Reference in New Issue