generated from liutk/owl-admin-base
110 lines
6.2 KiB
PHP
110 lines
6.2 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Controllers\Train;
|
|
|
|
use App\Admin\Controllers\AdminController;
|
|
use App\Admin\Services\Train\BookService;
|
|
use Slowlyo\OwlAdmin\Admin;
|
|
use Slowlyo\OwlAdmin\Renderers\Form;
|
|
use Slowlyo\OwlAdmin\Renderers\Page;
|
|
use App\Enums\BookType;
|
|
use App\Admin\Components;
|
|
|
|
/**
|
|
* 课件管理
|
|
*/
|
|
class BookController extends AdminController
|
|
{
|
|
protected string $serviceName = BookService::class;
|
|
|
|
public function list(): Page
|
|
{
|
|
$crud = $this->baseCRUD()
|
|
->tableLayout('fixed')
|
|
->headerToolbar([
|
|
$this->createTypeButton('drawer', 'lg')->visible(Admin::user()->can('admin.train.books.create')),
|
|
...$this->baseHeaderToolBar(),
|
|
])
|
|
->filter($this->baseFilter()->body([
|
|
amis()->GroupControl()->mode('horizontal')->body([
|
|
amisMake()->SelectControl()->name('category_id')->label(__('train_book.category_id'))
|
|
->source(admin_url('api/keywords/tree-list?parent_key=book_category'))
|
|
->labelField('name')
|
|
->valueField('key')
|
|
->columnRatio(3)
|
|
->clearable(),
|
|
amisMake()->TextControl()->name('search')->label(__('train_book.title'))->columnRatio(3)->clearable(),
|
|
amisMake()->SelectControl()->options(BookType::options())->name('type')->label(__('train_book.type'))->columnRatio(3)->clearable(),
|
|
]),
|
|
]))
|
|
->filterDefaultVisible()
|
|
->columns([
|
|
amisMake()->TableColumn()->name('id')->label(__('train_book.id')),
|
|
amisMake()->TableColumn()->name('category.name')->label(__('train_book.category_id')),
|
|
amisMake()->TableColumn()->name('cover_image')->label(__('train_book.cover_image'))->set('type', 'image')->set('width', '80px')->set('height', '60px'),
|
|
amisMake()->TableColumn()->name('title')->label(__('train_book.title')),
|
|
// amisMake()->TableColumn()->name('description')->label(__('train_book.description')),
|
|
amisMake()->TableColumn()->name('type')->label(__('train_book.type'))->set('type', 'mapping')->map(BookType::options()),
|
|
amisMake()->TableColumn()->name('created_at')->label(__('train_book.created_at')),
|
|
$this->rowActions([
|
|
$this->rowShowTypeButton('drawer', 'lg')->visible(Admin::user()->can('admin.train.books.view')),
|
|
$this->rowEditTypeButton('drawer', 'lg')->closeOnOutside(false)->visible(Admin::user()->can('admin.train.books.update')),
|
|
$this->rowDeleteButton()->visible(Admin::user()->can('admin.train.books.delete')),
|
|
]),
|
|
]);
|
|
|
|
return $this->baseList($crud);
|
|
}
|
|
|
|
public function form($edit): Form
|
|
{
|
|
return $this->baseForm()->data(['type' => BookType::Text->value])->title('')->body([
|
|
amisMake()->SelectControl()->name('category_id')->label(__('train_book.category_id'))
|
|
->source(admin_url('api/keywords/tree-list?parent_key=book_category'))
|
|
->labelField('name')
|
|
->valueField('key')
|
|
->required(),
|
|
amisMake()->TextControl()->name('title')->label(__('train_book.title'))->required(),
|
|
amisMake()->ImageControl()->name('cover_image')->label(__('train_book.cover_image'))->receiver(admin_url('upload_image') . '?full-url=1'),
|
|
amisMake()->TextControl()->name('description')->label(__('train_book.description')),
|
|
amisMake()->RadiosControl()->options(BookType::options())->name('type')->label(__('train_book.type')),
|
|
Components::make()->fuEditorControl('content', __('train_book.content'))->visibleOn('${type == '.BookType::Text->value.'}'),
|
|
amisMake()->FileControl()->name('video')->label(__('train_book.video'))
|
|
->receiver(admin_url('upload_file') . '?full-url=1')
|
|
->startChunkApi(admin_url('start_chunk_upload_file'))
|
|
->chunkApi(admin_url('save_chunk_upload_file'))
|
|
->finishChunkApi(admin_url('finish_chunk_upload_file'))
|
|
->visibleOn('${type == '.BookType::Video->value.'}'),
|
|
amisMake()->FileControl()->name('files')->label(__('train_book.files'))
|
|
->receiver(admin_url('upload_file') . '?full-url=1')
|
|
->multiple()
|
|
->joinValues(false)
|
|
->startChunkApi(admin_url('start_chunk_upload_file'))
|
|
->chunkApi(admin_url('save_chunk_upload_file'))
|
|
->finishChunkApi(admin_url('finish_chunk_upload_file'))
|
|
->visibleOn('${type == '.BookType::File->value.'}'),
|
|
]);
|
|
}
|
|
|
|
public function detail(): Form
|
|
{
|
|
$list = amisMake()->ListRenderer()->source('${files}')->listItem(
|
|
amisMake()->ListItem()->body(
|
|
amisMake()->Link()->body('${name}')->href('${value}')->blank()
|
|
)
|
|
);
|
|
$items = [
|
|
['label' => __('train_book.category_id'), 'content' => '${category.name}'],
|
|
['label' => __('train_book.title'), 'content' => '${title}'],
|
|
['label' => __('train_book.description'), 'content' => '${description}'],
|
|
['label' => __('train_book.cover_image'), 'content' => amisMake()->Image()->name('cover_image')->width('80px')->height('60px')],
|
|
['label' => __('train_book.type'), 'content' => amisMake()->Mapping()->map(BookType::options())->name('type')],
|
|
['label' => __('train_book.created_at'), 'content' => '${created_at}'],
|
|
['label' => __('train_book.content'), 'content' => Components::make()->fuEditorControl('content', false, 'auto')->static(), 'span' => 3, 'visibleOn' => '${type == '.BookType::Text->value.'}'],
|
|
['label' => __('train_book.video'), 'content' => amisMake()->Video()->src('${video}'), 'span' => 3, 'visibleOn' => '${type == '.BookType::Video->value.'}'],
|
|
['label' => __('train_book.files'), 'content' => $list, 'span' => 3, 'visibleOn' => '${type == '.BookType::File->value.'}'],
|
|
];
|
|
return $this->baseDetail()->title('')->body(amisMake()->Property()->items($items));
|
|
}
|
|
}
|