1
0
Fork 0
internet-everythings-agricu.../app/Admin/Controllers/ArticleController.php

85 lines
4.8 KiB
PHP

<?php
namespace App\Admin\Controllers;
use Slowlyo\OwlAdmin\Renderers\{Form, Page};
use Slowlyo\OwlAdmin\Renderers\{Component, Button, TableColumn, TextControl, Image, ImageControl, DateTimeControl, SwitchControl, Tabs, Tab, Status, Html};
use Slowlyo\OwlAdmin\Controllers\AdminController;
use App\Services\Admin\ArticleService;
use App\Admin\Components;
class ArticleController extends AdminController
{
protected string $serviceName = ArticleService::class;
public function list(): Page
{
$crud = $this->baseCRUD()
->filterTogglable(false)
->headerToolbar([
$this->createButton(true, 'lg'),
...$this->baseHeaderToolBar(),
])
->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'),
]))
->quickSaveItemApi(admin_url('quick-edit/article/$id'))
->columns([
TableColumn::make()->name('id')->label(__('article.id'))->sortable(true),
TableColumn::make()->name('title')->label(__('article.title')),
TableColumn::make()->name('category.name')->label(__('article.category_id'))->className('text-primary'),
Image::make()->name('cover')->label(__('article.cover'))->width(100),
TableColumn::make()->name('sub_title')->label(__('article.sub_title')),
TableColumn::make()->name('sort')->label(__('article.sort'))->align('center')->quickEdit(Components::make()->sortControl('sort', __('article-category.sort'))->saveImmediately(true)),
TableColumn::make()->name('is_enable')->type('switch')->label(__('article.is_enable'))->quickEdit(SwitchControl::make()->saveImmediately(true)->mode('inline')),
TableColumn::make()->name('published_at')->label(__('article.published_at')),
$this->rowActions(true, 'lg'),
]);
return $this->baseList($crud);
}
public function form(): Form
{
return $this->baseForm()->title('')->body([
TextControl::make()->name('title')->label(__('article.title'))->required(true),
Components::make()->parentControl(admin_url('api/article-categories/tree-list'), 'category_id', __('article.category_id')),
TextControl::make()->name('sub_title')->label(__('article.sub_title')),
ImageControl::make()->name('cover')->label(__('article.cover'))->autoUpload(true),
Components::make()->sortControl('sort', __('article.sort')),
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),
Components::make()->fuEditorControl('content', __('article.content')),
]);
}
public function detail(): Form
{
return $this->baseDetail()->title('')->body([
TextControl::make()->static(true)->name('id')->label(__('article.id')),
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('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')),
Components::make()->fuEditorControl('content', __('article.content'))->static(true),
]);
}
public function options()
{
$list = $this->service->listQuery()->select(['id as value', 'title as label'])->without('category')->get();
return $this->response()->success($list);
}
}