BaseVideoController.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Admin\Repositories\BaseProductCategory;
  4. use App\Admin\Repositories\BaseVideo;
  5. use App\Admin\Repositories\BaseVideoCategory;
  6. use App\Libraries\CommonHelper;
  7. use Dcat\Admin\Form;
  8. use Dcat\Admin\Grid;
  9. use Dcat\Admin\Show;
  10. use Dcat\Admin\Http\Controllers\AdminController;
  11. use Dcat\Admin\Layout\Content;
  12. class BaseVideoController extends AdminController
  13. {
  14. /**
  15. * page index
  16. */
  17. public function index(Content $content)
  18. {
  19. return $content
  20. ->header(admin_trans( 'admin.video_list'))
  21. ->description('')
  22. ->breadcrumb(['text'=>'list','url'=>''])
  23. ->body($this->grid());
  24. }
  25. /**
  26. * Make a grid builder.
  27. *
  28. * @return Grid
  29. */
  30. protected function grid()
  31. {
  32. return Grid::make(BaseVideo::with(['baseVideoCategory']), function (Grid $grid) {
  33. //默认分页条数
  34. $grid->paginate(config('admin.per_page'));
  35. $grid->column('id')->sortable();
  36. $grid->column('title');
  37. $grid->column('base_video_category.name',admin_trans_label('category_name'));
  38. $grid->column('cover_image')->display(function ($image) {
  39. // 开始生成 HTML
  40. $dataImages = [$image];
  41. return CommonHelper::displayImage($dataImages,100);
  42. });
  43. $grid->column('order')->orderable();
  44. $grid->column('is_pinned')->switch();
  45. $grid->column('enabled')->switch();
  46. $grid->column('created_at');
  47. $grid->column('updated_at')->sortable();
  48. // 筛选
  49. $grid->filter(function (Grid\Filter $filter) {
  50. $filter->panel();
  51. $filter->expand();
  52. $filter->equal('sku')->width(2);
  53. $filter->like('title')->width(2);
  54. $filter->equal('category_id',admin_trans_label('category'))->select(BaseVideoCategory::selectOptions())->width(2);
  55. $filter->equal('enabled', admin_trans_label('enabled'))->select(admin_trans_array(config('dictionary.enabled')))->width(2);
  56. });
  57. //排序
  58. $grid->model()->orderBy("is_pinned",'desc')->orderBy("order",'desc');
  59. //按钮
  60. });
  61. }
  62. /**
  63. * Make a show builder.
  64. *
  65. * @param mixed $id
  66. *
  67. * @return Show
  68. */
  69. protected function detail($id)
  70. {
  71. return Show::make($id, BaseVideo::with(['baseVideoCategory']), function (Show $show) {
  72. $show->field('id');
  73. $show->field('title');
  74. $show->field('base_video_category.name',admin_trans_field('category_name'));
  75. $show->field('cover_image')->as(function ($image) {
  76. // 开始生成 HTML
  77. $dataImages = [$image];
  78. return CommonHelper::displayImage($dataImages,150);
  79. })->unescape();
  80. $show->html(function () {
  81. $content = $this->video_url;
  82. return view('admin::show.field', [
  83. 'wrapped'=>true,
  84. 'escape'=>false,
  85. 'width'=>['label' => '2','field'=>'8'],
  86. 'label'=>admin_trans_label('video_url'),
  87. 'content'=>$content
  88. ]);
  89. });
  90. $show->field('video_url',admin_trans_label('video_player'))->as(function ($value) {
  91. $html = '
  92. <iframe width="560" height="315" src="'.$value.'"
  93. title="YouTube video player"
  94. frameborder="0"
  95. allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
  96. allowfullscreen>
  97. </iframe>';
  98. return $html;
  99. })->unescape();
  100. $show->field('remark')->unescape();
  101. $show->field('enabled')->using(admin_trans_array(config('dictionary.enabled')));
  102. $show->field('created_at');
  103. $show->field('updated_at');
  104. });
  105. }
  106. /**
  107. * Make a form builder.
  108. *
  109. * @return Form
  110. */
  111. protected function form()
  112. {
  113. return Form::make(new BaseVideo(), function (Form $form) {
  114. $form->display('id');
  115. $form->text('title')->required();
  116. $form->select('category_id', admin_trans_field('category_name'))
  117. ->options(BaseVideoCategory::selectOptions())
  118. ->required();
  119. $form->image("cover_image")
  120. ->autoUpload()
  121. ->uniqueName()
  122. ->accept(config('admin.upload.oss_image.accept'))
  123. ->maxSize(config('admin.upload.oss_image.max_size'))
  124. ->dir(config("admin.upload.directory.image").'/video/'.date("Ymd"));//
  125. $form->url("video_url")->required();
  126. $form->editor('remark');
  127. $form->switch('is_pinned')->default(0);
  128. $form->switch('enabled')->default(1);
  129. });
  130. }
  131. }