1
0
Fork 0

添加搜索示例

develop
vine_liutk 2023-04-26 10:13:56 +08:00
parent 16aae8cfa2
commit 412c97bd7a
5 changed files with 54 additions and 0 deletions

View File

@ -7,6 +7,7 @@ use Slowlyo\OwlAdmin\Renderers\Form;
use Slowlyo\OwlAdmin\Renderers\TableColumn;
use Slowlyo\OwlAdmin\Renderers\TextControl;
use Slowlyo\OwlAdmin\Controllers\AdminController;
use Slowlyo\OwlAdmin\Renderers\Button;
use App\Services\Admin\RegionCategoryService;
use App\Admin\Components;
@ -29,6 +30,14 @@ class RegionCategoryController extends AdminController
$this->createButton(true),
...$this->baseHeaderToolBar(),
])
->filter(
$this->baseFilter()->body([
amisMake()->TextControl()->make('name')->label('分类名称')->name('name'),
Button::make()->label(__('admin.reset'))->actionType('clear-and-submit'),
amis('submit')->label(__('admin.search'))->level('primary'),
])->actions([])
)
->columns([
TableColumn::make()->name('id')->label('ID')->sortable(true),
TableColumn::make()->name('name')->label('名称'),
@ -59,6 +68,7 @@ class RegionCategoryController extends AdminController
return $this->baseDetail()->body([
TextControl::make()->static(true)->name('id')->label('ID'),
TextControl::make()->static(true)->name('name')->label('名称'),
TextControl::make()->static(true)->name('description')->label('描述'),
TextControl::make()->static(true)->name('created_at')->label('创建时间'),
TextControl::make()->static(true)->name('updated_at')->label('更新时间')
]);

View File

@ -0,0 +1,30 @@
<?php
namespace App\Filters\Admin;
use EloquentFilter\ModelFilter;
class RegionCategoryFilter extends ModelFilter
{
/**
* 名称
*/
public function name($name){
return $this->where('name', 'like', '%'.$name.'%');
}
/**
* 父级分类
*/
public function parent($parentId){
return $this->where('parent_id', $parentId);
}
/**
* 是否开启
*/
public function isEnable($isEnable){
return $this->where('is_enbale', $isEnable);
}
}

View File

@ -13,6 +13,9 @@ class RegionCategory extends Model
protected $fillable = ['name', 'icon', 'description', 'parent_id', 'level', 'sort', 'path', 'is_enable'];
protected function serializeDate(\DateTimeInterface $date){
return $date->format('Y-m-d H:i:s');
}
protected static function boot()
{

View File

@ -3,6 +3,7 @@
namespace App\Services\Admin;
use App\Models\RegionCategory;
use App\Filters\Admin\RegionCategoryFilter;
use Slowlyo\OwlAdmin\Services\AdminService;
/**
@ -12,4 +13,14 @@ use Slowlyo\OwlAdmin\Services\AdminService;
class RegionCategoryService extends AdminService
{
protected string $modelName = RegionCategory::class;
public function listQuery()
{
$model = $this->getModel();
return $this->query()
->with('parent')
->filter(request()->input(), RegionCategoryFilter::class)
->orderByDesc($model->getUpdatedAtColumn() ?? $model->getKeyName());
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 KiB