article filter
parent
4995c1c367
commit
8c38cfd497
|
|
@ -3,7 +3,7 @@
|
||||||
namespace App\Admin\Controllers;
|
namespace App\Admin\Controllers;
|
||||||
|
|
||||||
use Slowlyo\OwlAdmin\Renderers\{Form, Page};
|
use Slowlyo\OwlAdmin\Renderers\{Form, Page};
|
||||||
use Slowlyo\OwlAdmin\Renderers\{TableColumn, TextControl, Image, ImageControl, DateTimeControl, SwitchControl, Tabs, Tab};
|
use Slowlyo\OwlAdmin\Renderers\{Component, Button, TableColumn, TextControl, Image, ImageControl, DateTimeControl, SwitchControl, Tabs, Tab, Status, Html};
|
||||||
use Slowlyo\OwlAdmin\Controllers\AdminController;
|
use Slowlyo\OwlAdmin\Controllers\AdminController;
|
||||||
use App\Services\Admin\ArticleService;
|
use App\Services\Admin\ArticleService;
|
||||||
use App\Admin\Components;
|
use App\Admin\Components;
|
||||||
|
|
@ -16,6 +16,12 @@ class ArticleController extends AdminController
|
||||||
{
|
{
|
||||||
$crud = $this->baseCRUD()
|
$crud = $this->baseCRUD()
|
||||||
->filterTogglable(false)
|
->filterTogglable(false)
|
||||||
|
->filter($this->baseFilter()->actions([])->body([
|
||||||
|
TextControl::make()->name('title')->label(__('article.title'))->size('md'),
|
||||||
|
Components::make()->parentControl(admin_url('api/article-categories/tree-list'), 'category_path', __('article.category_id'))->size('lg'),
|
||||||
|
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(__('article.id'))->sortable(true),
|
TableColumn::make()->name('id')->label(__('article.id'))->sortable(true),
|
||||||
TableColumn::make()->name('title')->label(__('article.title')),
|
TableColumn::make()->name('title')->label(__('article.title')),
|
||||||
|
|
@ -43,23 +49,30 @@ class ArticleController extends AdminController
|
||||||
DateTimeControl::make()->name('published_at')->label(__('article.published_at'))->value(now())->format('YYYY-MM-DD HH:mm:ss')->description('*不填写则默认为创建时间'),
|
DateTimeControl::make()->name('published_at')->label(__('article.published_at'))->value(now())->format('YYYY-MM-DD HH:mm:ss')->description('*不填写则默认为创建时间'),
|
||||||
SwitchControl::make()->name('is_enable')->label(__('article.is_enable'))->value(true),
|
SwitchControl::make()->name('is_enable')->label(__('article.is_enable'))->value(true),
|
||||||
]),
|
]),
|
||||||
Tab::make()->title('内容')->body(Components::make('content', __('article.content'))->fuEditorControl())
|
Tab::make()->title('内容')->body(Components::make()->fuEditorControl('content', ''))
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function detail(): Form
|
public function detail(): Form
|
||||||
{
|
{
|
||||||
return $this->baseDetail()->title('')->body(
|
return $this->baseDetail()->title('')->body(
|
||||||
Tabs::make()->tabs(
|
Tabs::make()->tabs([
|
||||||
Tab::make()->title('基本信息')->body([
|
Tab::make()->title('基本信息')->body([
|
||||||
TextControl::make()->static(true)->name('id')->label(__('article.id')),
|
TextControl::make()->static(true)->name('id')->label(__('article.id')),
|
||||||
TextControl::make()->static(true)->name('title')->label(__('article.title')),
|
TextControl::make()->static(true)->name('title')->label(__('article.title')),
|
||||||
TextControl::make()->static(true)->name('category.name')->label(__('article.category_id')),
|
TextControl::make()->static(true)->name('category.name')->label(__('article.category_id')),
|
||||||
TextControl::make()->static(true)->name('title')->label(__('article.sub_title')),
|
TextControl::make()->static(true)->name('sub_title')->label(__('article.sub_title')),
|
||||||
|
TextControl::make()->name('cover')->label(__('article.cover'))->static(true)->staticSchema(Image::make()),
|
||||||
|
TextControl::make()->static(true)->name('sort')->label(__('article.sort')),
|
||||||
|
TextControl::make()->name('is_enable')->label(__('article.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(__('article.published_at')),
|
||||||
TextControl::make()->static(true)->name('created_at')->label(__('article.created_at')),
|
TextControl::make()->static(true)->name('created_at')->label(__('article.created_at')),
|
||||||
]),
|
]),
|
||||||
Tab::make()->title('内容')->body('1234567')
|
Tab::make()->title('内容')->body(Html::make()->name('content'))
|
||||||
)
|
])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filters;
|
||||||
|
|
||||||
|
use EloquentFilter\ModelFilter;
|
||||||
|
|
||||||
|
class ArticleFilter 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function categoryId($v)
|
||||||
|
{
|
||||||
|
$this->where('category_id', $v);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function categoryPath($v)
|
||||||
|
{
|
||||||
|
$this->where('category_path', 'like', '%-'.$v.'-%');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,9 +2,8 @@
|
||||||
|
|
||||||
namespace App\Services\Admin;
|
namespace App\Services\Admin;
|
||||||
|
|
||||||
use App\Models\Article;
|
use App\Models\{Article, ArticleCategory};
|
||||||
use Illuminate\Support\Facades\Storage;
|
use App\Filters\ArticleFilter;
|
||||||
use Illuminate\Support\Str;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method Article getModel()
|
* @method Article getModel()
|
||||||
|
|
@ -16,6 +15,8 @@ class ArticleService extends BaseService
|
||||||
|
|
||||||
protected string $modelName = Article::class;
|
protected string $modelName = Article::class;
|
||||||
|
|
||||||
|
protected string $modelFilterName = ArticleFilter::class;
|
||||||
|
|
||||||
public function listQuery()
|
public function listQuery()
|
||||||
{
|
{
|
||||||
$model = $this->getModel();
|
$model = $this->getModel();
|
||||||
|
|
@ -32,4 +33,22 @@ class ArticleService extends BaseService
|
||||||
|
|
||||||
return $query->sort();
|
return $query->sort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function update($primaryKey, $data): bool
|
||||||
|
{
|
||||||
|
$cid = data_get($data, 'category_id');
|
||||||
|
if ($cid && $category = ArticleCategory::find($cid)) {
|
||||||
|
$data['category_path'] = $category->path . $category->id . '-';
|
||||||
|
}
|
||||||
|
return parent::update($primaryKey, $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function store($data): bool
|
||||||
|
{
|
||||||
|
$cid = data_get($data, 'category_id');
|
||||||
|
if ($cid && $category = ArticleCategory::find($cid)) {
|
||||||
|
$data['category_path'] = $category->path . $category->id . '-';
|
||||||
|
}
|
||||||
|
return parent::store($data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ return new class extends Migration
|
||||||
// 可能用到的额外字段
|
// 可能用到的额外字段
|
||||||
$table->string('cover')->nullable()->comment('封面');
|
$table->string('cover')->nullable()->comment('封面');
|
||||||
$table->string('author')->nullable()->comment('作者/来源');
|
$table->string('author')->nullable()->comment('作者/来源');
|
||||||
$table->string('category_path')->nullable()->comment('所有上级分类id');
|
$table->string('category_path')->nullable()->comment('所有分类id');
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue