AdminSetting.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. foreach (Arr::dot($input) as $k => $v) {
  37. $this->update($k, $v);
  38. }
  39. return $this->response()->success(trans('site-setting.Set_successfully'));
  40. }
  41. /**
  42. * 构建表单.
  43. */
  44. public function form()
  45. {
  46. $this->radio('lang', trans('site-setting.language'))->width(6)->required()->options(['zh' => '简体中文','ko'=>'한국어']);
  47. }
  48. /**
  49. * 设置接口保存成功后的回调JS代码.
  50. *
  51. * 1.2秒后刷新整个页面.
  52. *
  53. * @return string|void
  54. */
  55. public function savedScript()
  56. {
  57. return <<<'JS'
  58. if (data.status) {
  59. setTimeout(function () {
  60. location.reload()
  61. }, 1000);
  62. }
  63. JS;
  64. }
  65. /**
  66. * 返回表单数据.
  67. *
  68. * @return array
  69. */
  70. public function default()
  71. {
  72. return user_admin_config();
  73. }
  74. /**
  75. * 更新配置.
  76. *
  77. * @param string $key
  78. * @param string $value
  79. */
  80. protected function update($key, $value)
  81. {
  82. user_admin_config([$key => $value]);
  83. }
  84. }