DistVideoController.php 4.6 KB

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