SiteBannerController.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace App\Distributor\Controllers;
  3. use App\Distributor\Repositories\SiteBanner;
  4. use App\Libraries\CommonHelper;
  5. use Dcat\Admin\Form;
  6. use Dcat\Admin\Grid;
  7. use Dcat\Admin\Show;
  8. use Dcat\Admin\Http\Controllers\AdminController;
  9. use Dcat\Admin\Layout\Content;
  10. use Dcat\Admin\Admin;
  11. class SiteBannerController extends AdminDistController
  12. {
  13. public function title()
  14. {
  15. return admin_trans('admin.banner_list');
  16. }
  17. /**
  18. * page index
  19. */
  20. public function index(Content $content)
  21. {
  22. return $content
  23. ->header($this->title())
  24. ->body($this->grid());
  25. }
  26. /**
  27. * Make a grid builder.
  28. *
  29. * @return Grid
  30. */
  31. protected function grid()
  32. {
  33. return Grid::make(new SiteBanner(), function (Grid $grid) {
  34. $grid->column('id')->display(function () {
  35. return $this->_index+1;
  36. });
  37. $grid->column('title')->width('25%');
  38. $grid->column('subtitle')->width('25%');
  39. $grid->column('image_url',admin_trans_label('images'))->display(function ($image) {
  40. // 开始生成 HTML
  41. $dataImages = [$image];
  42. return CommonHelper::displayImage($dataImages,100);
  43. });
  44. $grid->column('position');
  45. $grid->column('order');
  46. $grid->column('show')->switch();
  47. $grid->disableViewButton();
  48. $grid->showQuickEditButton();
  49. $grid->enableDialogCreate();
  50. $grid->disableEditButton();
  51. $grid->model()->where('dist_id', getDistributorId())->orderBy('order', 'desc')->orderBy('id', 'desc');
  52. });
  53. }
  54. /**
  55. * Make a form builder.
  56. *
  57. * @return Form
  58. */
  59. protected function form()
  60. {
  61. return Form::make(new SiteBanner(), function (Form $form) {
  62. $form->text('title')->required();
  63. $form->text('subtitle');
  64. $form->image("image_url", admin_trans_label('images'))
  65. ->retainable()//禁止删OSS图
  66. ->autoUpload()
  67. ->uniqueName()
  68. ->accept(config('distributor.upload.oss_image.accept'))
  69. ->maxSize(config('distributor.upload.oss_image.max_size'))
  70. ->dir(config("distributor.upload.directory.image").'/banner/'.date("Ymd"));
  71. $form->text('banner_url');
  72. $form->number('position')->default(1);
  73. $form->number('order')->default(0);
  74. $form->switch('show')->default(1);
  75. $form->hidden('dist_id');
  76. $form->saving(function (Form $form) {
  77. $form->dist_id =getDistributorId();//保存时直接写死dist_id
  78. });
  79. });
  80. }
  81. }