Site.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. namespace App\Support;
  3. use Dcat\Admin\Admin;
  4. use Illuminate\Support\Facades\Storage;
  5. class Site
  6. {
  7. /**
  8. * 初始化配置注入.
  9. */
  10. public function initConfig()
  11. {
  12. /**
  13. * 处理站点LOGO自定义.
  14. */
  15. if (empty(admin_setting('site_logo'))) {
  16. $logo = admin_setting('site_logo_text');
  17. } else {
  18. $logo = Storage::disk(config('admin.upload.disk'))->url(admin_setting('site_logo'));
  19. $logo = "<img src='$logo' height='40' width='100%' />";
  20. }
  21. /**
  22. * 处理站点LOGO-MINI自定义.
  23. */
  24. if (empty(admin_setting('site_logo_mini'))) {
  25. $logo_mini = admin_setting('site_logo_text');
  26. } else {
  27. $logo_mini = Storage::disk(config('admin.upload.disk'))->url(admin_setting('site_logo_mini'));
  28. $logo_mini = "<img src='$logo_mini'>";
  29. }
  30. /**
  31. * 处理站点名称.
  32. */
  33. if (empty(admin_setting('site_url'))) {
  34. $site_url = 'http://localhost';
  35. } else {
  36. $site_url = admin_setting('site_url');
  37. }
  38. if (empty(admin_setting('site_debug'))) {
  39. $site_debug = true;
  40. } else {
  41. $site_debug = admin_setting('site_debug');
  42. }
  43. if (empty(admin_setting('theme_color'))) {
  44. $theme_color = 'blue-light';
  45. } else {
  46. $theme_color = admin_setting('theme_color');
  47. }
  48. /**
  49. * 处理AD HOSTS到数组.
  50. */
  51. $ad_hosts = [
  52. admin_setting('ad_host_primary'),
  53. ];
  54. if (!empty(admin_setting('ad_host_secondary'))) {
  55. $ad_hosts[] = admin_setting('ad_host_secondary');
  56. }
  57. /**
  58. * 处理AD端口号.
  59. */
  60. $ad_port = admin_setting('ad_port_primary');
  61. $ad_port = (int)$ad_port;
  62. /**
  63. * 处理AD SSL 和 TLS 协议,如果没填这个配置,就为false,否则就是本身设置的值
  64. */
  65. $ad_use_ssl = admin_setting('ad_use_ssl');
  66. $ad_use_ssl = !empty($ad_use_ssl);
  67. $ad_use_tls = admin_setting('ad_use_tls');
  68. $ad_use_tls = !empty($ad_use_tls);
  69. /**
  70. * 复写admin站点配置.
  71. */
  72. config([
  73. 'app.url' => $site_url,
  74. 'app.debug' => $site_debug,
  75. 'app.locale' => admin_setting('site_lang'),
  76. 'app.fallback_locale' => admin_setting('site_lang'),
  77. 'admin.title' => admin_setting('site_title'),
  78. 'admin.logo' => $logo,
  79. 'admin.logo-mini' => $logo_mini,
  80. 'admin.layout.color' => $theme_color,
  81. 'filesystems.disks.admin.url' => config('app.url') . '/uploads',
  82. 'ldap.connections.default.settings.hosts' => $ad_hosts,
  83. 'ldap.connections.default.settings.port' => $ad_port,
  84. 'ldap.connections.default.settings.base_dn' => admin_setting('ad_base_dn'),
  85. 'ldap.connections.default.settings.username' => admin_setting('ad_username'),
  86. 'ldap.connections.default.settings.password' => admin_setting('ad_password'),
  87. 'ldap.connections.default.settings.use_ssl' => $ad_use_ssl,
  88. 'ldap.connections.default.settings.use_tls' => $ad_use_tls,
  89. ]);
  90. }
  91. /**
  92. * 注入字段.
  93. */
  94. public function injectFields()
  95. {
  96. // Form::extend('selectCreate', SelectCreate::class);
  97. }
  98. /**
  99. * 底部授权移除.
  100. */
  101. public function footerRemove()
  102. {
  103. if (admin_setting('footer_remove')) {
  104. Admin::style(
  105. <<<'CSS'
  106. .main-footer {
  107. display: none;
  108. }
  109. CSS
  110. );
  111. }
  112. }
  113. /**
  114. * 头部边距优化.
  115. */
  116. public function headerPaddingFix()
  117. {
  118. if (admin_setting('header_padding_fix')) {
  119. Admin::style(
  120. <<<'CSS'
  121. .navbar{
  122. margin: 0 35px !important;
  123. }
  124. .main-horizontal-sidebar{
  125. box-sizing: border-box !important;
  126. padding: 0 35px !important;
  127. background-color: transparent !important;
  128. }
  129. .nav-link {
  130. padding: 0;
  131. }
  132. .empty-data {
  133. text-align: center;
  134. color: rgba(0, 0, 0, 0.7);
  135. display: flex;
  136. align-items: center;
  137. justify-content: left;
  138. }
  139. .font-grey {
  140. color: white;
  141. }
  142. CSS
  143. );
  144. }
  145. }
  146. /**
  147. * 行操作按钮最右.
  148. */
  149. public function gridRowActionsRight()
  150. {
  151. if (admin_setting('grid_row_actions_right')) {
  152. Admin::style(
  153. <<<'CSS'
  154. .grid__actions__{
  155. width: 20%;
  156. text-align: right;
  157. }
  158. CSS
  159. );
  160. }
  161. }
  162. /**
  163. * 引入自定义CSS
  164. */
  165. public function customCSS()
  166. {
  167. Admin::css('static/css/main.css');
  168. }
  169. }