banner-place
parent
d675db43a3
commit
b67e8f04af
|
|
@ -2,10 +2,8 @@
|
|||
|
||||
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\{TableColumn, TextControl, SwitchControl, NumberControl, Status, Button, Component};
|
||||
use Slowlyo\OwlAdmin\Controllers\AdminController;
|
||||
use App\Services\Admin\BannerPlaceService;
|
||||
|
||||
|
|
@ -13,7 +11,7 @@ class BannerPlaceController extends AdminController
|
|||
{
|
||||
protected string $serviceName = BannerPlaceService::class;
|
||||
|
||||
protected string $pageTitle = '图片位置';//待完善-todo
|
||||
protected string $pageTitle = '图片位置';
|
||||
|
||||
public function list(): Page
|
||||
{
|
||||
|
|
@ -23,11 +21,19 @@ class BannerPlaceController extends AdminController
|
|||
$this->createButton(true),
|
||||
...$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([
|
||||
TableColumn::make()->name('id')->label('ID')->sortable(true),
|
||||
TableColumn::make()->name('name')->label('名称'),
|
||||
TableColumn::make()->name('created_at')->label('创建时间')->type('datetime')->sortable(true),
|
||||
TableColumn::make()->name('updated_at')->label('更新时间')->type('datetime')->sortable(true),
|
||||
TableColumn::make()->name('id')->label(__('banner-place.id')),
|
||||
TableColumn::make()->name('key')->label(__('banner-place.key')),
|
||||
TableColumn::make()->name('name')->label(__('banner-place.name')),
|
||||
TableColumn::make()->name('is_enable')->type('switch')->label(__('banner-place.is_enable'))->quickEdit(SwitchControl::make()->saveImmediately(true)->mode('inline')),
|
||||
TableColumn::make()->name('remark')->label(__('banner-place.remark'))->quickEdit(TextControl::make()->saveImmediately(true)),
|
||||
$this->rowActions(true),
|
||||
]);
|
||||
|
||||
|
|
@ -36,10 +42,12 @@ class BannerPlaceController extends AdminController
|
|||
|
||||
public function form(): Form
|
||||
{
|
||||
return $this->baseForm()->body([
|
||||
TextControl::make()->name('name')->label('名称')->required(true),
|
||||
return $this->baseForm()->title('')->body([
|
||||
TextControl::make()->name('key')->label('KEY')->required(true),
|
||||
\amisMake()->SwitchControl()->name('is_enable')->label('显示'),
|
||||
TextControl::make()->name('name')->label('名称')->required(true),
|
||||
NumberControl::make()->name('width')->label(__('banner-place.width'))->step(1)->min(0),
|
||||
NumberControl::make()->name('height')->label(__('banner-place.height'))->step(1)->min(0),
|
||||
SwitchControl::make()->name('is_enable')->label(__('banner-place.is_enable'))->value(true),
|
||||
TextControl::make()->name('remark')->label('备注'),
|
||||
]);
|
||||
}
|
||||
|
|
@ -47,10 +55,16 @@ class BannerPlaceController extends AdminController
|
|||
public function detail(): Form
|
||||
{
|
||||
return $this->baseDetail()->body([
|
||||
TextControl::make()->static(true)->name('id')->label('ID'),
|
||||
TextControl::make()->static(true)->name('name')->label('名称'),
|
||||
TextControl::make()->static(true)->name('created_at')->label('创建时间'),
|
||||
TextControl::make()->static(true)->name('updated_at')->label('更新时间')
|
||||
TextControl::make()->static(true)->name('id')->label(__('banner-place.id')),
|
||||
TextControl::make()->static(true)->name('name')->label(__('banner-place.name')),
|
||||
TextControl::make()->static(true)->name('width')->label(__('banner-place.width')),
|
||||
TextControl::make()->static(true)->name('height')->label(__('banner-place.height')),
|
||||
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')),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,8 +30,9 @@ Route::group([
|
|||
// 文章管理
|
||||
$router->resource('articles', \App\Admin\Controllers\ArticleController::class);
|
||||
$router->post('quick-edit/article/{article}', [\App\Admin\Controllers\ArticleController::class, 'update']);
|
||||
//图片位置
|
||||
// 图片位置
|
||||
$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);
|
||||
//友情链接
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
<?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);
|
||||
}
|
||||
}
|
||||
|
|
@ -40,6 +40,11 @@ class ArticleCategory extends Model
|
|||
return $this->hasMany(static::class, 'parent_id');
|
||||
}
|
||||
|
||||
public function articles()
|
||||
{
|
||||
return $this->hasMany(Article::class, 'category_id');
|
||||
}
|
||||
|
||||
public function scopeSort($q)
|
||||
{
|
||||
return $q->orderBy('sort', 'desc');
|
||||
|
|
|
|||
|
|
@ -2,10 +2,28 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use EloquentFilter\Filterable;
|
||||
|
||||
class BannerPlace extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use Filterable;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,14 +2,24 @@
|
|||
|
||||
namespace App\Services\Admin;
|
||||
|
||||
use App\Models\BannerPlace;
|
||||
use Slowlyo\OwlAdmin\Services\AdminService;
|
||||
use App\Models\{BannerPlace, Banner};
|
||||
use App\Filters\BannerPlaceFilter;
|
||||
|
||||
/**
|
||||
* @method BannerPlace getModel()
|
||||
* @method BannerPlace|\Illuminate\Database\Query\Builder query()
|
||||
*/
|
||||
class BannerPlaceService extends AdminService
|
||||
class BannerPlaceService extends BaseService
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
'id' => 'ID',
|
||||
'created_at' => '创建时间',
|
||||
'height' => '高度(px)',
|
||||
'is_enable' => '显示',
|
||||
'key' => 'KEY',
|
||||
'name' => '名称',
|
||||
'remark' => '备注',
|
||||
'width' => '宽度(px)',
|
||||
];
|
||||
Loading…
Reference in New Issue