BaseVideoController.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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('Video Management')
  21. ->description('all')
  22. ->breadcrumb(['text'=>'Video Management','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. $grid->column('id')->sortable();
  34. $grid->column('title');
  35. $grid->column('base_video_category.name','Category Name');
  36. $grid->column('cover_image')->display(function ($image) {
  37. // 开始生成 HTML
  38. $dataImages = [$image];
  39. return CommonHelper::displayImage($dataImages,100);
  40. });
  41. $grid->column('order')->orderable();
  42. $grid->column('is_pinned')->switch();
  43. $grid->column('enabled')->switch();
  44. $grid->column('created_at');
  45. $grid->column('updated_at')->sortable();
  46. // 筛选
  47. $grid->filter(function (Grid\Filter $filter) {
  48. $filter->equal('sku');
  49. $filter->like('title');
  50. $filter->equal('category_id','Category')->select(BaseVideoCategory::selectOptions());
  51. $filter->equal('enabled', 'enabled')->select(config('dictionary.enabled'));
  52. });
  53. //排序
  54. $grid->model()->orderBy("is_pinned",'desc')->orderBy("order",'desc');
  55. //按钮
  56. });
  57. }
  58. /**
  59. * Make a show builder.
  60. *
  61. * @param mixed $id
  62. *
  63. * @return Show
  64. */
  65. protected function detail($id)
  66. {
  67. return Show::make($id, BaseVideo::with(['baseVideoCategory']), function (Show $show) {
  68. $show->field('id');
  69. $show->field('title');
  70. $show->field('base_video_category.name','Category Name');
  71. $show->field('cover_image')->as(function ($image) {
  72. // 开始生成 HTML
  73. $dataImages = [$image];
  74. return CommonHelper::displayImage($dataImages,150);
  75. })->unescape();
  76. $show->html(function () {
  77. $content = $this->video_url;
  78. return view('admin::show.field', [
  79. 'wrapped'=>true,
  80. 'escape'=>false,
  81. 'width'=>['label' => '2','field'=>'8'],
  82. 'label'=>'Video Url',
  83. 'content'=>$content
  84. ]);
  85. });
  86. $show->field('video_url','Video player')->as(function ($value) {
  87. $html = '
  88. <iframe width="560" height="315" src="'.$value.'"
  89. title="YouTube video player"
  90. frameborder="0"
  91. allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
  92. allowfullscreen>
  93. </iframe>';
  94. return $html;
  95. })->unescape();
  96. $show->field('remark')->unescape();
  97. $show->field('enabled')->using(config('dictionary.enabled'));
  98. $show->field('created_at');
  99. $show->field('updated_at');
  100. });
  101. }
  102. /**
  103. * Make a form builder.
  104. *
  105. * @return Form
  106. */
  107. protected function form()
  108. {
  109. return Form::make(new BaseVideo(), function (Form $form) {
  110. $form->display('id');
  111. $form->text('title')->required();
  112. $form->select('category_id', 'Category Name')
  113. ->options(BaseVideoCategory::selectOptions())
  114. ->required();
  115. $form->image("cover_image")
  116. ->autoUpload()
  117. ->uniqueName()
  118. ->accept(config('admin.upload.oss_image.accept'))
  119. ->maxSize(config('admin.upload.oss_image.max_size'))
  120. ->dir('images/video/'.date("Ymd"));//
  121. $form->url("video_url")->required();
  122. $form->editor('remark');
  123. $form->switch('is_pinned')->default(0);
  124. $form->switch('enabled')->default(1);
  125. });
  126. }
  127. }