SettingController.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. namespace App\Admin\Controllers\Setting;
  3. use App\Models\Setting;
  4. use Dcat\Admin\Form;
  5. use Dcat\Admin\Grid;
  6. use Dcat\Admin\Layout\Content;
  7. use Dcat\Admin\Show;
  8. use Dcat\Admin\Http\Controllers\AdminController;
  9. use Dingo\Api\Http\Request;
  10. class SettingController extends AdminController
  11. {
  12. const TYPE_BASIC = 'basic'; // 基础设置
  13. const TYPE_TIPS = 'tips'; // 消息设置
  14. protected $type = '';
  15. public function __construct()
  16. {
  17. $route = \request()->route();
  18. $arr = explode("/",$route->uri);
  19. $this->type = $arr[3];
  20. }
  21. /**
  22. * Make a grid builder.
  23. *
  24. * @return Grid
  25. */
  26. protected function grid()
  27. {
  28. return Grid::make(new Setting(), function (Grid $grid) {
  29. $grid->column('id')->sortable();
  30. if($this->type == self::TYPE_BASIC){
  31. $grid->column('name');
  32. $grid->column('logo')->image('',150);
  33. $grid->column('contact')->editable();
  34. }elseif($this->type == self::TYPE_TIPS){
  35. $grid->column('tips')->editable();
  36. }else{
  37. $grid->column('recharge_bg_img')->image('',150);;
  38. $grid->column('recharge_button_txt');
  39. $grid->column('recharge_desc');
  40. }
  41. $grid->disableDeleteButton();
  42. $grid->disableCreateButton();
  43. $grid->disableViewButton();
  44. $grid->disableRowSelector();
  45. });
  46. }
  47. /**
  48. * Make a show builder.
  49. *
  50. * @param mixed $id
  51. *
  52. * @return Show
  53. */
  54. protected function detail($id)
  55. {
  56. return Show::make($id, new Setting(), function (Show $show) {
  57. $show->field('id');
  58. $show->field('name');
  59. $show->field('logo');
  60. $show->field('contact');
  61. $show->field('tips');
  62. $show->field('is_watch_auto_pay');
  63. $show->field('recharge_bg_img');
  64. $show->field('recharge_button_txt');
  65. $show->field('recharge_desc');
  66. $show->field('created_at');
  67. $show->field('updated_at');
  68. });
  69. }
  70. /**
  71. * Make a form builder.
  72. *
  73. * @param $type
  74. * @return Form
  75. */
  76. protected function form()
  77. {
  78. return Form::make(new Setting(), function (Form $form) {
  79. $form->display('id');
  80. if($this->type == self::TYPE_BASIC){
  81. $form->text('name');
  82. $form->image('logo')->saveFullUrl()
  83. ->uniqueName()->autoUpload()
  84. ->autoSave(false)
  85. ->removable(false)
  86. ->width(4);
  87. $form->text('contact')->minLength(11)->maxLength(11);
  88. }elseif($this->type == self::TYPE_TIPS){
  89. $form->text('tips');
  90. }else{
  91. $form->image('recharge_bg_img')->saveFullUrl()
  92. ->uniqueName()->autoUpload()
  93. ->autoSave(false)
  94. ->removable(false)
  95. ->width(4);
  96. $form->text('recharge_button_txt')->maxLength(10);
  97. $form->textarea('recharge_desc');
  98. }
  99. $form->disableViewButton();
  100. $form->disableDeleteButton();
  101. $form->disableListButton();
  102. $form->disableEditingCheck();
  103. $form->disableViewCheck();
  104. });
  105. }
  106. }