AdminSetting.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. 'default' => '深蓝',
  17. 'blue' => '蓝',
  18. // 'blue-light' => '浅蓝',
  19. // 'blue-dark' => '深蓝',
  20. 'green' => '绿',
  21. ];
  22. /**
  23. * 处理表单请求.
  24. *
  25. * @param array $input
  26. *
  27. * @return mixed
  28. */
  29. public function handle(array $input)
  30. {
  31. $input['layout']['horizontal_menu'] = in_array('horizontal_menu', $input['layout']['body_class'], true);
  32. foreach (Arr::dot($input) as $k => $v) {
  33. $this->update($k, $v);
  34. }
  35. return $this->response()->success('设置成功');
  36. }
  37. /**
  38. * 构建表单.
  39. */
  40. public function form()
  41. {
  42. $this->text('name')->required()->help('网站名称');
  43. $this->text('logo')->required()->help('logo设置');
  44. $this->text('logo-mini', 'Logo mini')->required();
  45. $this->radio('lang', '语言')->required()->options(['en' => 'English', 'zh_CN' => '简体中文']);
  46. $this->radio('layout.color', '主题')
  47. ->required()
  48. ->help('主题颜色,支持自定义!')
  49. ->options($this->colors);
  50. $this->radio('layout.sidebar_style', '菜单样式')
  51. ->options(['light' => 'Light', 'primary' => 'Primary'])
  52. ->help('切换菜单栏样式');
  53. $this->checkbox('layout.body_class', '菜单布局')
  54. ->options([
  55. 'horizontal_menu' => '水平 (Horizontal)',
  56. 'sidebar-separate' => 'sidebar-separate',
  57. ])
  58. ->help('切换菜单布局');
  59. // $this->switch('https', '启用HTTPS');
  60. $this->switch('helpers.enable', '开发工具');
  61. }
  62. /**
  63. * 设置接口保存成功后的回调JS代码.
  64. *
  65. * 1.2秒后刷新整个页面.
  66. *
  67. * @return string|void
  68. */
  69. public function savedScript()
  70. {
  71. return <<<'JS'
  72. if (data.status) {
  73. setTimeout(function () {
  74. location.reload()
  75. }, 1200);
  76. }
  77. JS;
  78. }
  79. /**
  80. * 返回表单数据.
  81. *
  82. * @return array
  83. */
  84. public function default()
  85. {
  86. return user_admin_config();
  87. }
  88. /**
  89. * 更新配置.
  90. *
  91. * @param string $key
  92. * @param string $value
  93. */
  94. protected function update($key, $value)
  95. {
  96. user_admin_config([$key => $value]);
  97. }
  98. }