链街Dcat后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
3.0 KiB

  1. <?php
  2. namespace App\Admin\Controllers\v3;
  3. use App\Admin\Repositories\v3\SystemConfig;
  4. use Dcat\Admin\Form;
  5. use Dcat\Admin\Grid;
  6. use Dcat\Admin\Show;
  7. use Dcat\Admin\Controllers\AdminController;
  8. use App\Models\v3\SystemConfig as SystemConfigModel;
  9. class SystemConfigController extends AdminController
  10. {
  11. /**
  12. * Make a grid builder.
  13. *
  14. * @return Grid
  15. */
  16. protected function grid()
  17. {
  18. return Grid::make(new SystemConfig(), function (Grid $grid) {
  19. $grid->column('id')->sortable();
  20. $grid->column('menu_name');
  21. $grid->column('info');
  22. $grid->column('value');
  23. $grid->column('category_text');
  24. $grid->column('sort');
  25. $grid->column('status')->switch();
  26. $grid->model()->orderby('id','desc');
  27. $grid->filter(function (Grid\Filter $filter) {
  28. $filter->equal('id');
  29. $filter->like('menu_name');
  30. $filter->equal('category')->select(SystemConfigModel::$_CATEGORY);
  31. });
  32. });
  33. }
  34. /**
  35. * Make a show builder.
  36. *
  37. * @param mixed $id
  38. *
  39. * @return Show
  40. */
  41. protected function detail($id)
  42. {
  43. return Show::make($id, new SystemConfig(), function (Show $show) {
  44. $show->field('id');
  45. $show->field('menu_name');
  46. $show->field('category_text');
  47. $show->field('value');
  48. $show->field('info');
  49. $show->field('desc');
  50. $show->field('sort');
  51. $show->field('status_text');
  52. $show->field('created_at');
  53. $show->field('updated_at');
  54. });
  55. }
  56. /**
  57. * Make a form builder.
  58. *
  59. * @return Form
  60. */
  61. protected function form()
  62. {
  63. return Form::make(new SystemConfig(), function (Form $form) {
  64. $form->hidden('id');
  65. $form->text('menu_name')->width(4)->required()->rules('regex:/^[0-9a-z_]{1,}$/',['regex'=>'只能输入数字、小写字母和下划线'])->help('本字段在添加成功后不能编辑!');
  66. $form->select('category')->width(4)->options(SystemConfigModel::$_CATEGORY);
  67. $form->text('value')->required()->width(6)->maxLength(100);
  68. $form->text('info')->maxLength(255);
  69. $form->text('desc')->maxLength(500);
  70. $form->number('sort')->width(2)->default(0);
  71. $form->saving(function(Form $form){
  72. $id = $form->input('id');
  73. if($id && $form->input('menu_name') ){
  74. $form->deleteInput('menu_name');
  75. }
  76. });
  77. $form->switch('status')
  78. ->customFormat(function ($v) {
  79. return $v == 1 ? 1 : 0;
  80. })
  81. ->saving(function ($v) {
  82. return $v == 1 ? 1 : 0;
  83. });
  84. $form->disableResetButton();
  85. $form->disableViewCheck();
  86. $form->disableEditingCheck();
  87. $form->disableCreatingCheck();
  88. });
  89. }
  90. }