header($this->title()) ->description('') ->breadcrumb(['text'=>'list','url'=>'']) ->body($this->grid()); } /** * Make a grid builder. * * @return Grid */ protected function grid() { return Grid::make(BaseVideo::with(['baseVideoCategory']), function (Grid $grid) { //默认分页条数 $grid->paginate(config('admin.per_page')); $grid->column('id')->display(function () { return $this->_index+1; }); $grid->column('title')->width('25%'); $grid->column('base_video_category.name',admin_trans_label('category_name')); $grid->column('cover_image')->display(function ($image) { // 开始生成 HTML $dataImages = [$image]; return CommonHelper::displayImage($dataImages,100); }); $grid->column('order'); $grid->column('enabled')->switch(); $grid->column('created_at')->sortable(); $grid->column('updated_at')->sortable(); // 筛选 $grid->filter(function (Grid\Filter $filter) { $filter->panel(); $filter->expand(); $filter->equal('sku')->width(2); $filter->like('title')->width(2); $filter->equal('category_id',admin_trans_label('category'))->select(BaseVideoCategory::selectOptions())->width(2); $filter->equal('enabled', admin_trans_label('enabled'))->select(admin_trans_array(config('dictionary.enabled')))->width(2); }); //排序 $grid->model()->orderBy("order",'desc')->orderBy('id','desc'); //按钮 }); } /** * Make a show builder. * * @param mixed $id * * @return Show */ protected function detail($id) { return Show::make($id, BaseVideo::with(['baseVideoCategory']), function (Show $show) { $show->field('title'); $show->field('base_video_category.name',admin_trans_field('category_name')); $show->field('cover_image')->as(function ($image) { // 开始生成 HTML $dataImages = [$image]; return CommonHelper::displayImage($dataImages,150); })->unescape(); $show->html(function () { $content = $this->video_url; return view('admin::show.field', [ 'wrapped'=>true, 'escape'=>false, 'width'=>['label' => '2','field'=>'8'], 'label'=>admin_trans_label('video_url'), 'content'=>$content ]); }); $show->field('video_url',admin_trans_label('video_player'))->as(function ($value) { $html = ' '; return $html; })->unescape(); $show->field('remark')->unescape(); $show->field('order'); $show->field('enabled')->using(admin_trans_array(config('dictionary.enabled'))); $show->field('created_at'); $show->field('updated_at'); }); } /** * Make a form builder. * * @return Form */ protected function form() { return Form::make(new BaseVideo(), function (Form $form) { //$form->display('id'); $help = admin_trans_label('video_help'); $inputFormat = admin_trans_label('input_format'); $form->text('title')->required(); $form->select('category_id', admin_trans_field('category_name')) ->options(BaseVideoCategory::selectOptions()) ->required(); $form->image("cover_image") ->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").'/video/'.date("Ymd"));// $form->text("video_url") ->required() ->help(''.$help. ' , '.$inputFormat.' : https://www.youtube.com/embed/xxxxxxxx'); $form->editor('remark'); $form->number('order') ->default(0) ->rules('numeric'); $form->switch('enabled')->default(1); $form->saving(function (Form $form) { //替换youtube URL if (strpos($form->video_url, ']+src="([^"]+)"/', $form->video_url, $matches)) { $src = $matches[1]; $form->video_url = $src; } } }); }); } }