DistAppearanceController.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. $grid->filter(function (Grid\Filter $filter) {
  44. $filter->equal('title');
  45. });
  46. });
  47. }
  48. /**
  49. * Make a show builder.
  50. *
  51. * @param mixed $id
  52. *
  53. * @return Show
  54. */
  55. protected function detail($id)
  56. {
  57. return Show::make($id, new DistAppearance(), function (Show $show) {
  58. $show->field('id');
  59. $show->field('title');
  60. $show->field('cover_image')->display(function ($image) {
  61. // 开始生成 HTML
  62. $dataImages = [$image];
  63. return CommonHelper::displayImage($dataImages,100);
  64. });
  65. $show->field('describe');
  66. $show->field('enabled')->using(config('dictionary.enabled'));
  67. $show->field('created_at');
  68. $show->field('updated_at');
  69. });
  70. }
  71. /**
  72. * Make a form builder.
  73. *
  74. * @return Form
  75. */
  76. protected function form()
  77. {
  78. return Form::make(new DistAppearance(), function (Form $form) {
  79. $form->display('id');
  80. $form->text('title');
  81. $form->image("cover_image")
  82. ->autoUpload()
  83. ->uniqueName()
  84. ->accept(config('admin.upload.oss_image.accept'))
  85. ->maxSize(config('admin.upload.oss_image.max_size'))
  86. ->dir('images/appearance/'.date("Ymd"));//
  87. $form->textarea('describe');
  88. $form->switch('enabled')->default(1);
  89. });
  90. }
  91. }