DistAppearanceController.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Admin\Repositories\DistAppearance;
  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 DistAppearanceController extends AdminController
  12. {
  13. /**
  14. * page index
  15. */
  16. public function index(Content $content)
  17. {
  18. return $content
  19. ->header('Appearance')
  20. ->description('all')
  21. ->breadcrumb(['text'=>'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(new DistAppearance(), function (Grid $grid) {
  32. $grid->column('id')->sortable();
  33. $grid->column('title');
  34. $grid->column('cover_image')->display(function ($image) {
  35. // 开始生成 HTML
  36. $dataImages = [$image];
  37. return CommonHelper::displayImage($dataImages,100);
  38. });
  39. $grid->column('order')->orderable();
  40. $grid->column('enabled')->switch();
  41. $grid->column('created_at');
  42. $grid->column('updated_at')->sortable();
  43. // 过滤器
  44. $grid->filter(function (Grid\Filter $filter) {
  45. $filter->panel();
  46. $filter->expand();
  47. $filter->equal('title')->width(2);
  48. $filter->equal('enabled', 'enabled')->select(config('dictionary.enabled'))->width(2);
  49. });
  50. });
  51. }
  52. /**
  53. * Make a show builder.
  54. *
  55. * @param mixed $id
  56. *
  57. * @return Show
  58. */
  59. protected function detail($id)
  60. {
  61. return Show::make($id, new DistAppearance(), function (Show $show) {
  62. $show->field('id');
  63. $show->field('title');
  64. $show->field('cover_image')->as(function ($image) {
  65. // 开始生成 HTML
  66. $dataImages = [$image];
  67. return CommonHelper::displayImage($dataImages,100);
  68. })->unescape();
  69. $show->field('describe');
  70. $show->field('enabled')->using(config('dictionary.enabled'));
  71. $show->field('created_at');
  72. $show->field('updated_at');
  73. });
  74. }
  75. /**
  76. * Make a form builder.
  77. *
  78. * @return Form
  79. */
  80. protected function form()
  81. {
  82. return Form::make(new DistAppearance(), function (Form $form) {
  83. $form->display('id');
  84. $form->text('title');
  85. $form->image("cover_image")
  86. ->autoUpload()
  87. ->uniqueName()
  88. ->accept(config('admin.upload.oss_image.accept'))
  89. ->maxSize(config('admin.upload.oss_image.max_size'))
  90. ->dir('images/appearance/'.date("Ymd"));//
  91. $form->textarea('describe');
  92. $form->switch('enabled')->default(1);
  93. });
  94. }
  95. }