DistAppearanceController.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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(admin_trans( 'admin.appearance'))
  21. ->description('')
  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', )->select(admin_trans_array(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(admin_trans_array(config('dictionary.enabled')));
  89. $show->field('created_at');
  90. $show->field('updated_at');
  91. $show->disableDeleteButton();
  92. });
  93. }
  94. /**
  95. * Make a form builder.
  96. *
  97. * @return Form
  98. */
  99. protected function form()
  100. {
  101. return Form::make(new DistAppearance(), function (Form $form) {
  102. $form->display('id');
  103. $form->text('title');
  104. $form->text('folder');
  105. $form->image("cover_image")
  106. ->autoUpload()
  107. ->uniqueName()
  108. ->accept(config('admin.upload.oss_image.accept'))
  109. ->maxSize(config('admin.upload.oss_image.max_size'))
  110. ->dir(config("admin.upload.directory.image").'/appearance/'.date("Ymd"));//
  111. $form->textarea('describe');
  112. $form->switch('enabled')->default(0);
  113. $form->saving(function (Form $form) {
  114. if ($form->isCreating() && $form->input('enabled') == 1) {
  115. return $form->response()->error('Please create the template first, then import it, and finally enable it.');
  116. }
  117. if (!$form->isCreating()) {
  118. if ($form->input('enabled') == 1 && $form->model()->imported == 0) {
  119. return $form->response()->error('Please select the import option first, then enable it.');
  120. }
  121. }
  122. });
  123. $form->disableDeleteButton();
  124. });
  125. }
  126. }