AdminSetting.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. namespace App\Admin\Forms;
  3. use Dcat\Admin\Contracts\LazyRenderable;
  4. use Dcat\Admin\Traits\LazyWidget;
  5. use Dcat\Admin\Widgets\Form;
  6. use Illuminate\Support\Arr;
  7. class AdminSetting extends Form implements LazyRenderable
  8. {
  9. use LazyWidget;
  10. /**
  11. * 主题颜色.
  12. *
  13. * @var array
  14. */
  15. protected $colors;
  16. public function __construct($data = [], $key = null)
  17. {
  18. parent::__construct($data, $key);
  19. $this->colors = [
  20. 'default' => trans('site-setting.Dark_blue'),
  21. 'blue' => trans('site-setting.blue'),
  22. // 'blue-light' => '浅蓝',
  23. // 'blue-dark' => '深蓝',
  24. 'green' => trans('site-setting.green'),
  25. ];
  26. }
  27. /**
  28. * 处理表单请求.
  29. *
  30. * @param array $input
  31. *
  32. * @return mixed
  33. */
  34. public function handle(array $input)
  35. {
  36. $input['layout']['horizontal_menu'] = in_array('horizontal_menu', $input['layout']['body_class'], true);
  37. foreach (Arr::dot($input) as $k => $v) {
  38. $this->update($k, $v);
  39. }
  40. return $this->response()->success(trans('site-setting.Set_successfully'));
  41. }
  42. /**
  43. * 构建表单.
  44. */
  45. public function form()
  46. {
  47. // $this->text('name')->required()->help(trans('site-setting.Website_name'));
  48. // $this->text('logo')->required()->help(trans('site-setting.logo'));
  49. // $this->text('logo-mini', 'Logo mini')->required();
  50. $this->radio('lang', trans('site-setting.language'))->required()->options(['en' => 'English', 'zh' => '简体中文']);
  51. // $this->radio('layout.color', trans('site-setting.theme'))
  52. // ->required()
  53. // ->help(trans('site-setting.theme_color'))
  54. // ->options($this->colors);
  55. // $this->radio('layout.sidebar_style', trans('site-setting.menu_style'))
  56. // ->options(['light' => 'Light', 'primary' => 'Primary'])
  57. // ->help(trans('site-setting.t_menu_style'));
  58. $this->checkbox('layout.body_class', trans('site-setting.Menu_layout'))
  59. ->options([
  60. 'horizontal_menu' => 'Horizontal',
  61. 'sidebar-separate' => 'sidebar-separate',
  62. ])
  63. ->help(trans('site-setting.Switch_menu_layout'));
  64. // $this->switch('https', '启用HTTPS');
  65. $this->switch('helpers.enable', trans('site-setting.development_tool'));
  66. }
  67. /**
  68. * 设置接口保存成功后的回调JS代码.
  69. *
  70. * 1.2秒后刷新整个页面.
  71. *
  72. * @return string|void
  73. */
  74. public function savedScript()
  75. {
  76. return <<<'JS'
  77. if (data.status) {
  78. setTimeout(function () {
  79. location.reload()
  80. }, 1200);
  81. }
  82. JS;
  83. }
  84. /**
  85. * 返回表单数据.
  86. *
  87. * @return array
  88. */
  89. public function default()
  90. {
  91. return user_admin_config();
  92. }
  93. /**
  94. * 更新配置.
  95. *
  96. * @param string $key
  97. * @param string $value
  98. */
  99. protected function update($key, $value)
  100. {
  101. user_admin_config([$key => $value]);
  102. }
  103. }