DistAppearanceController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Admin\Actions\Grid\AppearanceImport;
  4. use App\Admin\Repositories\DistAppearance;
  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. use Dcat\Admin\Admin;
  12. class DistAppearanceController extends AdminController
  13. {
  14. /**
  15. * page index
  16. */
  17. public function index(Content $content)
  18. {
  19. return $content
  20. ->header('Appearance')
  21. ->description('all')
  22. ->breadcrumb(['text'=>'list','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(new DistAppearance(), function (Grid $grid) {
  33. $grid->column('id')->sortable();
  34. // 标题
  35. $grid->column('title');
  36. // 文件夹
  37. $grid->column('folder')->help('Folder names under the directory:/resources/appearance');
  38. // 封面图
  39. $grid->column('cover_image')->display(function ($image) {
  40. $dataImages = [$image];
  41. return CommonHelper::displayImage($dataImages,100);
  42. });
  43. // 排序
  44. $grid->column('order')->orderable();
  45. //是否导入
  46. $grid->column('imported')->using(config('dictionary.whether'))->label([
  47. 0 => 'default',
  48. 1 => 'success',
  49. ]);
  50. //是否启用
  51. $grid->column('enabled')->switch();
  52. // 时间
  53. $grid->column('created_at');
  54. $grid->column('updated_at')->sortable();
  55. // 过滤器
  56. $grid->filter(function (Grid\Filter $filter) {
  57. $filter->panel();
  58. $filter->expand();
  59. $filter->equal('title')->width(2);
  60. $filter->equal('enabled', 'enabled')->select(config('dictionary.enabled'))->width(2);
  61. });
  62. // 操作
  63. $grid->actions(function (Grid\Displayers\Actions $actions) {
  64. $actions->disableDelete();
  65. $actions->append(new AppearanceImport());
  66. });
  67. });
  68. }
  69. /**
  70. * Make a show builder.
  71. *
  72. * @param mixed $id
  73. *
  74. * @return Show
  75. */
  76. protected function detail($id)
  77. {
  78. return Show::make($id, new DistAppearance(), function (Show $show) {
  79. $show->field('id');
  80. $show->field('title');
  81. $show->field('folder');
  82. $show->field('cover_image')->as(function ($image) {
  83. // 开始生成 HTML
  84. $dataImages = [$image];
  85. return CommonHelper::displayImage($dataImages,100);
  86. })->unescape();
  87. $show->field('describe');
  88. $show->field('enabled')->using(config('dictionary.enabled'));
  89. $show->field('created_at');
  90. $show->field('updated_at');
  91. });
  92. }
  93. /**
  94. * Make a form builder.
  95. *
  96. * @return Form
  97. */
  98. protected function form()
  99. {
  100. return Form::make(new DistAppearance(), function (Form $form) {
  101. $form->display('id');
  102. $form->text('title');
  103. $form->text('folder');
  104. $form->image("cover_image")
  105. ->autoUpload()
  106. ->uniqueName()
  107. ->accept(config('admin.upload.oss_image.accept'))
  108. ->maxSize(config('admin.upload.oss_image.max_size'))
  109. ->dir('images/appearance/'.date("Ymd"));//
  110. $form->textarea('describe');
  111. $form->switch('enabled')->default(1);
  112. });
  113. }
  114. }