123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <?php
- namespace App\Admin\Controllers;
- use App\Admin\Repositories\SiteAlbumFolder;
- use App\Libraries\CommonHelper;
- use Dcat\Admin\Form;
- use Dcat\Admin\Grid;
- use Dcat\Admin\Show;
- use Dcat\Admin\Http\Controllers\AdminController;
- use Dcat\Admin\Layout\Content;
- use Dcat\Admin\Admin;
- class SiteAlbumFolderController extends AdminController
- {
- /**
- * page index
- */
- public function index(Content $content)
- {
- return $content
- ->header(admin_trans( 'admin.folder'))
- ->body($this->grid());
- }
- /**
- * Make a grid builder.
- *
- * @return Grid
- */
- protected function grid()
- {
- return Grid::make(new SiteAlbumFolder(), function (Grid $grid) {
- $grid->view('admin.grid-custom.table');
- $grid->column('id')->sortable();
- $grid->column('title')->display(function ($title) {
- $level = $this->level; // 获取当前行的 level 字段值
- $has_children = $this->has_children; // 获取当前行的 has_children 字段值
- if ($has_children) {
- $prefix = str_repeat(' ', $level * 2). ' <i class="fa fa-angle-right"></i> '; // 生成 level * 3 个加号
- } else {
- $prefix = str_repeat(' ', $level * 2). ' '; // 生成 level * 3 个加号
- }
- return $prefix . ' ' . html_entity_decode($title); // 拼接加号和名称
- });
- $grid->column('cover') ->display(function ($images) {
- return CommonHelper::displayImage([$images],80);
- });
- //$grid->column('folder_type')->using(admin_trans_array(config('dictionary.folder_type')))->label([0 => 'primary', 1 => 'success',]);
- $grid->column('parent_id');
- $grid->column('order')->sortable();
- $grid->column('enabled')->switch();
- $grid->column('created_at')->sortable();
- $grid->disableViewButton();
- $grid->showQuickEditButton();
- $grid->enableDialogCreate();
- $grid->disableEditButton();
- $grid->disablePerPages();
- });
- }
- /**
- * Make a form builder.
- *
- * @return Form
- */
- protected function form()
- {
- return Form::make(new SiteAlbumFolder(), function (Form $form) {
- $form->select('parent_id', admin_trans_field('parent'))
- ->options(SiteAlbumFolder::selectMainOptions())
- ->saving(function ($v) {
- return (int) $v;
- })->default(0);
- $form->text('title')->required();
- $form->image('cover')
- ->retainable()//禁止删OSS图
- ->autoUpload()
- ->uniqueName()
- ->accept(config('admin.upload.oss_image.accept'))
- ->maxSize(config('admin.upload.oss_image.max_size'))
- ->dir(config("admin.upload.directory.image").'/uploads/'.date("Ymd"))
- ->required();
- // $form->radio('folder_type')
- // ->options(admin_trans_array(config('dictionary.folder_type')))
- // ->default(0)->required();
- $form->listbox('show_tabs')->options(admin_trans_array([
- '0' => 'cover',
- '1' => 'en_detail',
- '2' => 'cn_detail',
- '3' => 'video',
- '4' => 'poster',
- '5' => 'cert',
- '6' => 'pdf',
- ]))->default([0, 1, 2, 3, 4, 5, 6])->saving(function ($v) { return json_encode($v); });
- $form->number('order')
- ->default(0)
- ->rules('numeric');
- $form->switch('enabled')->default(1);
- });
- }
- }
|