Browse Source

增加后台主题配置

Anyon 3 years ago
parent
commit
7a08b76dbd

+ 1 - 1
app/admin/controller/Auth.php

@@ -3,7 +3,7 @@
 // +----------------------------------------------------------------------
 // | ThinkAdmin
 // +----------------------------------------------------------------------
-// | 版权所有 2014~2021 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
+// | 版权所有 2014~2022 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
 // +----------------------------------------------------------------------
 // | 官方网站: https://thinkadmin.top
 // +----------------------------------------------------------------------

+ 1 - 1
app/admin/controller/Base.php

@@ -3,7 +3,7 @@
 // +----------------------------------------------------------------------
 // | ThinkAdmin
 // +----------------------------------------------------------------------
-// | 版权所有 2014~2021 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
+// | 版权所有 2014~2022 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
 // +----------------------------------------------------------------------
 // | 官方网站: https://thinkadmin.top
 // +----------------------------------------------------------------------

+ 12 - 3
app/admin/controller/Config.php

@@ -3,7 +3,7 @@
 // +----------------------------------------------------------------------
 // | ThinkAdmin
 // +----------------------------------------------------------------------
-// | 版权所有 2014~2021 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
+// | 版权所有 2014~2022 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
 // +----------------------------------------------------------------------
 // | 官方网站: https://thinkadmin.top
 // +----------------------------------------------------------------------
@@ -33,6 +33,14 @@ use think\admin\storage\TxcosStorage;
  */
 class Config extends Controller
 {
+    const themes = [
+        'default' => '默认色',
+        'red'     => '玫瑰红',
+        'blue'    => '天空蓝',
+        'black'   => '精典黑',
+        'white'   => '简约白'
+    ];
+
     /**
      * 系统参数配置
      * @auth true
@@ -41,7 +49,7 @@ class Config extends Controller
     public function index()
     {
         $this->title = '系统参数配置';
-        $this->isSuper = AdminService::instance()->isSuper();
+        $this->super = AdminService::instance()->isSuper();
         $this->version = ModuleService::instance()->getVersion();
         $this->fetch();
     }
@@ -58,6 +66,7 @@ class Config extends Controller
         $this->_applyFormToken();
         if ($this->request->isGet()) {
             $this->title = '修改系统参数';
+            $this->themes = static::themes;
             $this->fetch();
         } else {
             $post = $this->request->post();
@@ -81,7 +90,7 @@ class Config extends Controller
                 }
                 if (!empty($info) && !empty($info['file'])) {
                     $favicon = new FaviconExtend($info['file']);
-                    $favicon->saveIco($this->app->getRootPath() . 'public/favicon.ico');
+                    $favicon->saveIco("{$this->app->getRootPath()}public/favicon.ico");
                 }
             } catch (\Exception $exception) {
                 trace_file($exception);

+ 28 - 4
app/admin/controller/Index.php

@@ -3,7 +3,7 @@
 // +----------------------------------------------------------------------
 // | ThinkAdmin
 // +----------------------------------------------------------------------
-// | 版权所有 2014~2021 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
+// | 版权所有 2014~2022 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
 // +----------------------------------------------------------------------
 // | 官方网站: https://thinkadmin.top
 // +----------------------------------------------------------------------
@@ -28,7 +28,6 @@ use think\admin\service\MenuService;
  */
 class Index extends Controller
 {
-
     /**
      * 显示后台首页
      * @throws \ReflectionException
@@ -39,6 +38,7 @@ class Index extends Controller
     public function index()
     {
         /*! 根据运行模式刷新权限 */
+
         $debug = $this->app->isDebug();
         AdminService::instance()->apply($debug);
         /*! 读取当前用户权限菜单树 */
@@ -50,13 +50,37 @@ class Index extends Controller
             $this->redirect(sysuri('admin/login/index'));
         } else {
             $this->title = '系统管理后台';
-            $this->isSuper = AdminService::instance()->isSuper();
-            $this->theme = sysconf('base.site_theme') ?: 'default';
+            $this->super = AdminService::instance()->isSuper();
+            $this->theme = AdminService::instance()->getUserTheme();
             $this->fetch('layout');
         }
     }
 
     /**
+     * 后台主题切换
+     * @login true
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function theme()
+    {
+        if ($this->request->isGet()) {
+            $this->theme = AdminService::instance()->getUserTheme();
+            $this->themes = Config::themes;
+            $this->fetch();
+        } else {
+            $data = $this->_vali(['site_theme.require' => '主题名称不能为空!']);
+            if (AdminService::instance()->setUserTheme($data['site_theme'])) {
+                $this->success('主题配置保存成功!');
+            } else {
+                $this->error('主题配置保存失败!');
+            }
+        }
+    }
+
+    /**
      * 修改用户资料
      * @login true
      * @param mixed $id 用户ID

+ 1 - 1
app/admin/controller/Login.php

@@ -3,7 +3,7 @@
 // +----------------------------------------------------------------------
 // | ThinkAdmin
 // +----------------------------------------------------------------------
-// | 版权所有 2014~2021 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
+// | 版权所有 2014~2022 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
 // +----------------------------------------------------------------------
 // | 官方网站: https://thinkadmin.top
 // +----------------------------------------------------------------------

+ 1 - 1
app/admin/controller/Menu.php

@@ -3,7 +3,7 @@
 // +----------------------------------------------------------------------
 // | ThinkAdmin
 // +----------------------------------------------------------------------
-// | 版权所有 2014~2021 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
+// | 版权所有 2014~2022 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
 // +----------------------------------------------------------------------
 // | 官方网站: https://thinkadmin.top
 // +----------------------------------------------------------------------

+ 1 - 1
app/admin/controller/Module.php

@@ -3,7 +3,7 @@
 // +----------------------------------------------------------------------
 // | ThinkAdmin
 // +----------------------------------------------------------------------
-// | 版权所有 2014~2021 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
+// | 版权所有 2014~2022 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
 // +----------------------------------------------------------------------
 // | 官方网站: https://thinkadmin.top
 // +----------------------------------------------------------------------

+ 1 - 1
app/admin/controller/Oplog.php

@@ -3,7 +3,7 @@
 // +----------------------------------------------------------------------
 // | ThinkAdmin
 // +----------------------------------------------------------------------
-// | 版权所有 2014~2021 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
+// | 版权所有 2014~2022 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
 // +----------------------------------------------------------------------
 // | 官方网站: https://thinkadmin.top
 // +----------------------------------------------------------------------

+ 2 - 2
app/admin/controller/Queue.php

@@ -3,7 +3,7 @@
 // +----------------------------------------------------------------------
 // | ThinkAdmin
 // +----------------------------------------------------------------------
-// | 版权所有 2014~2021 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
+// | 版权所有 2014~2022 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
 // +----------------------------------------------------------------------
 // | 官方网站: https://thinkadmin.top
 // +----------------------------------------------------------------------
@@ -46,7 +46,7 @@ class Queue extends Controller
             $this->title = '系统任务管理';
             $this->iswin = ProcessService::instance()->iswin();
             // 超级管理面板
-            if ($this->isSuper = AdminService::instance()->isSuper()) {
+            if ($this->super = AdminService::instance()->isSuper()) {
                 $process = ProcessService::instance();
                 if ($process->iswin() || empty($_SERVER['USER'])) {
                     $this->command = $process->think('xadmin:queue start');

+ 1 - 1
app/admin/controller/User.php

@@ -3,7 +3,7 @@
 // +----------------------------------------------------------------------
 // | ThinkAdmin
 // +----------------------------------------------------------------------
-// | 版权所有 2014~2021 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
+// | 版权所有 2014~2022 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
 // +----------------------------------------------------------------------
 // | 官方网站: https://thinkadmin.top
 // +----------------------------------------------------------------------

+ 1 - 1
app/admin/controller/api/Plugs.php

@@ -3,7 +3,7 @@
 // +----------------------------------------------------------------------
 // | ThinkAdmin
 // +----------------------------------------------------------------------
-// | 版权所有 2014~2021 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
+// | 版权所有 2014~2022 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
 // +----------------------------------------------------------------------
 // | 官方网站: https://thinkadmin.top
 // +----------------------------------------------------------------------

+ 1 - 1
app/admin/controller/api/Queue.php

@@ -3,7 +3,7 @@
 // +----------------------------------------------------------------------
 // | ThinkAdmin
 // +----------------------------------------------------------------------
-// | 版权所有 2014~2021 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
+// | 版权所有 2014~2022 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
 // +----------------------------------------------------------------------
 // | 官方网站: https://thinkadmin.top
 // +----------------------------------------------------------------------

+ 1 - 1
app/admin/controller/api/Runtime.php

@@ -3,7 +3,7 @@
 // +----------------------------------------------------------------------
 // | ThinkAdmin
 // +----------------------------------------------------------------------
-// | 版权所有 2014~2021 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
+// | 版权所有 2014~2022 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
 // +----------------------------------------------------------------------
 // | 官方网站: https://thinkadmin.top
 // +----------------------------------------------------------------------

+ 1 - 1
app/admin/controller/api/Update.php

@@ -3,7 +3,7 @@
 // +----------------------------------------------------------------------
 // | ThinkAdmin
 // +----------------------------------------------------------------------
-// | 版权所有 2014~2021 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
+// | 版权所有 2014~2022 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
 // +----------------------------------------------------------------------
 // | 官方网站: https://thinkadmin.top
 // +----------------------------------------------------------------------

+ 1 - 1
app/admin/controller/api/Upload.php

@@ -3,7 +3,7 @@
 // +----------------------------------------------------------------------
 // | ThinkAdmin
 // +----------------------------------------------------------------------
-// | 版权所有 2014~2021 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
+// | 版权所有 2014~2022 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
 // +----------------------------------------------------------------------
 // | 官方网站: https://thinkadmin.top
 // +----------------------------------------------------------------------

+ 1 - 1
app/admin/module/default.php

@@ -3,7 +3,7 @@
 // +----------------------------------------------------------------------
 // | ThinkAdmin
 // +----------------------------------------------------------------------
-// | 版权所有 2014~2021 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
+// | 版权所有 2014~2022 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
 // +----------------------------------------------------------------------
 // | 官方网站: https://thinkadmin.top
 // +----------------------------------------------------------------------

+ 1 - 1
app/admin/route/demo.php

@@ -3,7 +3,7 @@
 // +----------------------------------------------------------------------
 // | ThinkAdmin
 // +----------------------------------------------------------------------
-// | 版权所有 2014~2021 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
+// | 版权所有 2014~2022 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
 // +----------------------------------------------------------------------
 // | 官方网站: https://thinkadmin.top
 // +----------------------------------------------------------------------

+ 2 - 2
app/admin/view/config/index.html

@@ -1,7 +1,7 @@
 {extend name="main"}
 
 {block name="button"}
-<!--{if isset($isSuper) and $isSuper}-->
+<!--{if isset($super) and $super}-->
 <a class="layui-btn layui-btn-sm layui-btn-primary" data-load="{:url('admin/api.runtime/config')}">清理无效配置</a>
 <!--{/if}-->
 
@@ -11,7 +11,7 @@
 {/block}
 
 {block name="content"}
-<!--{notempty name='isSuper'}-->
+<!--{notempty name='super'}-->
 <div class="layui-card padding-20 shadow">
     <div class="layui-card-header notselect">
         <b>运行模式</b><span class="color-desc font-s12 padding-left-5">Run Mode</span>

+ 34 - 40
app/admin/view/config/system.html

@@ -1,56 +1,50 @@
-<form onsubmit="return false" data-auto="true" action="{:sysuri()}" method="post" class='layui-form layui-card' autocomplete="off">
+<form data-auto="true" action="{:sysuri()}" method="post" class='layui-form layui-card'>
     <div class="layui-card-body padding-left-40">
 
-        <div class="layui-form-item">
-            <div class="help-label"><b>登录背景图片</b>Back Image</div>
-            <table class="layui-table">
-                <thead>
-                <tr>
-                    <th class="padding-bottom-5">
-                        <input type="hidden" value="{:sysconf('login_image')}" name="login_image">
-                        <script>$('[name="login_image"]').uploadMultipleImage()</script>
-                    </th>
-                </tr>
-                </thead>
-            </table>
+        <div class="layui-form-item margin-bottom-5">
+            <div class="help-label label-required-prev"><b>默认主题样式</b>Theme Style</div>
+            <div class="layui-textarea" style="min-height:unset">
+                {foreach $themes as $k=>$v}
+                <label class="think-radio">
+                    {if sysconf('base.site_theme') eq $k}
+                    <input name="site_theme" type="radio" value="{$k}" lay-ignore checked> {$v}
+                    {else}
+                    <input name="site_theme" type="radio" value="{$k}" lay-ignore> {$v}
+                    {/if}
+                </label>
+                {/foreach}
+            </div>
+            <span class="help-block">用户登录管理后台,未配置个性化主题的用户默认会使用此处配置的主题样式 ~</span>
         </div>
 
-        <div class="layui-row layui-col-space15 layui-form-item margin-bottom-5">
-            <div class="layui-col-xs6 padding-top-0 padding-bottom-0">
+        <div class="layui-row layui-col-space15 margin-bottom-5">
+            <div class="layui-col-xs6 padding-bottom-0">
+                <label class="relative block">
+                    <span class="help-label"><b>登录表单标题</b>Login Name</span>
+                    <input name="login_name" required placeholder="请输入登录页面的表单标题" value="{:sysconf('login_name')?:'系统管理'}" class="layui-input">
+                </label>
+            </div>
+            <div class="layui-col-xs6 padding-bottom-0">
                 <div class="help-label label-required-prev"><b>后台登录入口</b>Login Entry</div>
                 <label class="layui-input relative block label-required-null">
                     <span>{:sysuri('@',[],false,true)}</span>
                     <input autofocus required pattern="[a-zA-Z_][a-zA-Z0-9_]*" placeholder="请输入后台登录入口" class="layui-input inline-block padding-0 border-0" style="width:auto;background:none" value="{:substr(sysuri('admin/index/index',[],false), strlen(sysuri('@')))}" name="xpath">
                 </label>
             </div>
-            <div class="layui-col-xs6 padding-top-0 padding-bottom-0">
-                <label class="relative block">
-                    <span class="help-label"><b>登录表单标题</b>Login Name</span>
-                    <input name="login_name" required placeholder="请输入登录页面的表单标题" value="{:sysconf('login_name')?:'系统管理'}" class="layui-input">
-                </label>
-            </div>
             <div class="layui-col-xs12 padding-top-0 padding-bottom-0">
-                <span class="help-block">后台登录入口由英文字母开头且不能有相同名称的模块,设置之后原地址不能继续访问 ~</span>
+                <span class="help-block">后台登录入口是由英文字母开头,且不能有相同名称的模块,设置之后原地址不能继续访问,请谨慎配置 ~</span>
             </div>
         </div>
 
-        <div class="layui-form-item margin-bottom-5 label-required-prev">
-            <div class="help-label"><b>默认主题样式</b>Theme Style</div>
-            <div class="layui-input">
-                {foreach ['default'=>'默认色','white'=>'简约白','black'=>'精典黑','red'=>'玫瑰红','blue'=>'天空蓝'] as $k=>$v}
-                <label class="think-radio">
-                    {if sysconf('base.site_theme') eq $k}
-                    <input name="site_theme" type="radio" value="{$k}" lay-ignore checked> {$v}
-                    {else}
-                    <input name="site_theme" type="radio" value="{$k}" lay-ignore> {$v}
-                    {/if}
-                </label>
-                {/foreach}
+        <div class="layui-form-item margin-bottom-5">
+            <div class="help-label"><b>登录背景图片</b>Background Image</div>
+            <div class="layui-textarea think-bg-gray" style="min-height:unset;padding:10px 10px 3px 10px">
+                <input type="hidden" value="{:sysconf('login_image')}" name="login_image">
+                <script>$('[name=login_image]').uploadMultipleImage();</script>
             </div>
-            <span class="help-block">用户登录管理后台默认会以此配置的主题显示管理界面,用户也可以单独修改配置主题 ~</span>
         </div>
 
-        <div class="layui-form-item">
+        <div class="layui-form-item margin-bottom-5">
             <div class="help-label label-required-prev"><b>浏览器小图标</b>Browser Icon</div>
             <label class="relative block label-required-null">
                 <input class="layui-input" required pattern="^(http|/)" placeholder="请上传浏览器图标" value="{:sysconf('site_icon')}" name="site_icon">
@@ -59,22 +53,22 @@
             <span class="help-block">建议上传 <span class="color-blue">128x128</span> | <span class="color-blue">256x256</span> 的 ico 或 png 图片,可以通过 <a href="https://www.favicon-icon-generator.com" target="_blank">ICON </a>在线制作 ico 后缀文件 ~</span>
         </div>
 
-        <div class="layui-row layui-col-space15">
-            <div class="layui-col-xs4 padding-top-0 padding-bottom-0">
+        <div class="layui-row layui-col-space15 margin-bottom-5">
+            <div class="layui-col-xs4 padding-bottom-0">
                 <label class="layui-form-item margin-bottom-5 relative block">
                     <span class="help-label"><b>网站名称</b>Site Name</span>
                     <input name="site_name" required placeholder="请输入网站名称" value="{:sysconf('site_name')}" class="layui-input">
                     <span class="help-block">网站名称将显示在浏览器的标签上 ~</span>
                 </label>
             </div>
-            <div class="layui-col-xs4 padding-top-0 padding-bottom-0">
+            <div class="layui-col-xs4 padding-bottom-0">
                 <label class="layui-form-item margin-bottom-5 relative block">
                     <span class="help-label"><b>后台程序名称</b>App Name</span>
                     <input name="app_name" required placeholder="请输入程序名称" value="{:sysconf('app_name')}" class="layui-input">
                     <span class="help-block">管理程序名称显示在后台左上标题处 ~</span>
                 </label>
             </div>
-            <div class="layui-col-xs4 padding-top-0 padding-bottom-0">
+            <div class="layui-col-xs4 padding-bottom-0">
                 <label class="layui-form-item margin-bottom-5 relative block">
                     <span class="help-label"><b>后台程序版本</b>App Version</span>
                     <input name="app_version" placeholder="请输入程序版本" value="{:sysconf('app_version')}" class="layui-input">

+ 2 - 2
app/admin/view/index/layout-top.html

@@ -22,12 +22,12 @@
         <li class="layui-nav-item">
             <dl class="layui-nav-child">
                 <dd lay-unselect><a data-modal="{:sysuri('admin/index/info',['id'=>session('user.id')])}"><i class="layui-icon layui-icon-set-fill"></i> 基本资料</a></dd>
-                <dd lay-unselect><a data-modal="{:sysuri('admin/index/theme')}"><i class="layui-icon layui-icon-theme"></i> 配色方案</a></dd>
                 <dd lay-unselect><a data-modal="{:sysuri('admin/index/pass',['id'=>session('user.id')])}"><i class="layui-icon layui-icon-component"></i> 安全设置</a></dd>
-                {if isset($isSuper) and $isSuper}
+                {if isset($super) and $super}
                 <dd lay-unselect><a data-load="{:sysuri('admin/api.runtime/push')}"><i class="layui-icon layui-icon-template-1"></i> 缓存加速</a></dd>
                 <dd lay-unselect><a data-load="{:sysuri('admin/api.runtime/clear')}"><i class="layui-icon layui-icon-fonts-clear"></i> 清理缓存</a></dd>
                 {/if}
+                <dd lay-unselect><a data-modal="{:sysuri('admin/index/theme')}"><i class="layui-icon layui-icon-theme"></i> 配色方案</a></dd>
                 <dd lay-unselect><a data-load="{:sysuri('admin/login/out')}" data-confirm="确定要退出登录吗?"><i class="layui-icon layui-icon-release"></i> 退出登录</a></dd>
             </dl>
             <a class="layui-elip">

+ 36 - 0
app/admin/view/index/theme.html

@@ -0,0 +1,36 @@
+<form data-auto="true" action="{:sysuri()}" method="post" id="theme" class='layui-form layui-card' autocomplete="off">
+    <div class="layui-card-body padding-left-40">
+
+        <div class="layui-form-item margin-bottom-5 label-required-prev">
+            <div class="help-label"><b>后台主题样式</b>Theme Style</div>
+            <div class="layui-textarea" style="min-height:unset">
+                {foreach $themes as $k=>$v}
+                <label class="think-radio">
+                    {if isset($theme) and $theme eq $k}
+                    <input name="site_theme" type="radio" value="{$k}" lay-ignore checked> {$v}
+                    {else}
+                    <input name="site_theme" type="radio" value="{$k}" lay-ignore> {$v}
+                    {/if}
+                </label>
+                {/foreach}
+            </div>
+        </div>
+    </div>
+
+    <div class="hr-line-dashed"></div>
+    <div class="layui-form-item text-center">
+        <button class="layui-btn" type="submit">保存配置</button>
+        <button class="layui-btn layui-btn-danger" type='button' data-close>取消修改</button>
+    </div>
+</form>
+
+<script>
+    layui.form.render();
+    $('form#theme input[name=site_theme]').on('click', function () {
+        var alls = '', that = this, prox = 'layui-layout-theme-', curt = prox + that.value;
+        $('form#theme input[name=site_theme]').map(function () {
+            if (this.value !== that.value) alls += ' ' + prox + this.value;
+        });
+        $('.layui-layout-admin').removeClass(alls).addClass(curt)
+    });
+</script>

+ 1 - 1
app/admin/view/queue/index.html

@@ -1,7 +1,7 @@
 {extend name='table'}
 
 {block name="button"}
-<!--{if isset($isSuper) and $isSuper}-->
+<!--{if isset($super) and $super}-->
 <a class="layui-btn layui-btn-sm layui-btn-primary" data-queue="{:url('admin/api.plugs/optimize')}">优化数据库</a>
 <!--{if $iswin}-->
 <button data-load='{:url("admin/api.queue/start")}' class='layui-btn layui-btn-sm layui-btn-primary'>开启后台服务</button>

+ 1 - 1
app/admin/view/queue/index_search.html

@@ -1,4 +1,4 @@
-<!--{if isset($isSuper) and $isSuper}-->
+<!--{if isset($super) and $super}-->
 <fieldset class="margin-bottom-15">
     <legend class="notselect">服务状态</legend>
     <div class="layui-code border-0 margin-top-0">