优化后台管理

This commit is contained in:
邹景立 2021-05-10 10:55:47 +08:00
parent 9a07a03e6b
commit 91af7bb7f9
9 changed files with 131 additions and 100 deletions

View File

@ -17,8 +17,6 @@ namespace app\admin\controller\api;
use think\admin\Controller;
use think\admin\service\AdminService;
use think\admin\service\SystemService;
use think\exception\HttpResponseException;
/**
* 通用插件管理
@ -39,25 +37,6 @@ class Plugs extends Controller
$this->fetch(realpath(__DIR__ . '/../../view/api/icon.html'));
}
/**
* 当前运行模式
* @login true
*/
public function debug()
{
if (AdminService::instance()->isSuper()) if (input('state')) {
SystemService::instance()->setRuntime('product');
sysoplog('系统运维管理', '由开发模式切换为生产模式');
$this->success('已切换为生产模式!');
} else {
SystemService::instance()->setRuntime('debug');
sysoplog('系统运维管理', '由生产模式切换为开发模式');
$this->success('已切换为开发模式!');
} else {
$this->error('只有超级管理员才能操作!');
}
}
/**
* 优化数据库
* @login true
@ -71,73 +50,4 @@ class Plugs extends Controller
$this->error('只有超级管理员才能操作!');
}
}
/**
* 清理系统配置
* @login true
*/
public function clearConfig()
{
if (AdminService::instance()->isSuper()) try {
$this->app->db->transaction(function () {
[$tmpdata, $newdata] = [[], []];
foreach ($this->app->db->name('SystemConfig')->order('type,name asc')->cursor() as $item) {
$tmpdata[$item['type']][$item['name']] = $item['value'];
}
foreach ($tmpdata as $type => $items) foreach ($items as $name => $value) {
$newdata[] = ['type' => $type, 'name' => $name, 'value' => $value];
}
$this->_query('SystemConfig')->empty()->insertAll($newdata);
});
$this->app->cache->delete('SystemConfig');
sysoplog('系统运维管理', '清理系统参数配置成功');
$this->success('清理系统配置成功!');
} catch (HttpResponseException $exception) {
throw $exception;
} catch (\Exception $exception) {
$this->error($exception->getMessage());
} else {
$this->error('只有超级管理员才能操作!');
}
}
/**
* 网站压缩发布
* @login true
*/
public function pushRuntime()
{
if (AdminService::instance()->isSuper()) try {
AdminService::instance()->clearCache();
SystemService::instance()->pushRuntime();
sysoplog('系统运维管理', '刷新并创建网站路由缓存');
$this->success('网站缓存加速成功!');
} catch (HttpResponseException $exception) {
throw $exception;
} catch (\Exception $exception) {
$this->error($exception->getMessage());
} else {
$this->error('只有超级管理员才能操作!');
}
}
/**
* 清理运行缓存
* @login true
*/
public function clearRuntime()
{
if (AdminService::instance()->isSuper()) try {
AdminService::instance()->clearCache();
SystemService::instance()->clearRuntime();
sysoplog('系统运维管理', '清理网站日志及缓存数据');
$this->success('清空缓存日志成功!');
} catch (HttpResponseException $exception) {
throw $exception;
} catch (\Exception $exception) {
$this->error($exception->getMessage());
} else {
$this->error('只有超级管理员才能操作!');
}
}
}

View File

@ -0,0 +1,119 @@
<?php
// +----------------------------------------------------------------------
// | ThinkAdmin
// +----------------------------------------------------------------------
// | 版权所有 2014~2021 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: https://thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 代码仓库https://gitee.com/zoujingli/ThinkAdmin
// | github 代码仓库https://github.com/zoujingli/ThinkAdmin
// +----------------------------------------------------------------------
namespace app\admin\controller\api;
use think\admin\Controller;
use think\admin\service\AdminService;
use think\admin\service\SystemService;
use think\exception\HttpResponseException;
/**
* 系统运行控制管理
* Class Runtime
* @package app\admin\controller\api
*/
class Runtime extends Controller
{
/**
* 网站压缩发布
* @login true
*/
public function push()
{
if (AdminService::instance()->isSuper()) try {
AdminService::instance()->clearCache();
SystemService::instance()->pushRuntime();
sysoplog('系统运维管理', '刷新并创建网站路由缓存');
$this->success('网站缓存加速成功!');
} catch (HttpResponseException $exception) {
throw $exception;
} catch (\Exception $exception) {
$this->error($exception->getMessage());
} else {
$this->error('只有超级管理员才能操作!');
}
}
/**
* 清理运行缓存
* @login true
*/
public function clear()
{
if (AdminService::instance()->isSuper()) try {
AdminService::instance()->clearCache();
SystemService::instance()->clearRuntime();
sysoplog('系统运维管理', '清理网站日志及缓存数据');
$this->success('清空缓存日志成功!');
} catch (HttpResponseException $exception) {
throw $exception;
} catch (\Exception $exception) {
$this->error($exception->getMessage());
} else {
$this->error('只有超级管理员才能操作!');
}
}
/**
* 当前运行模式
* @login true
*/
public function debug()
{
if (AdminService::instance()->isSuper()) if (input('state')) {
SystemService::instance()->setRuntime('product');
sysoplog('系统运维管理', '由开发模式切换为生产模式');
$this->success('已切换为生产模式!');
} else {
SystemService::instance()->setRuntime('debug');
sysoplog('系统运维管理', '由生产模式切换为开发模式');
$this->success('已切换为开发模式!');
} else {
$this->error('只有超级管理员才能操作!');
}
}
/**
* 清理系统配置
* @login true
*/
public function config()
{
if (AdminService::instance()->isSuper()) try {
$this->app->db->transaction(function () {
[$tmpdata, $newdata] = [[], []];
foreach ($this->app->db->name('SystemConfig')->order('type,name asc')->cursor() as $item) {
$tmpdata[$item['type']][$item['name']] = $item['value'];
}
foreach ($tmpdata as $type => $items) foreach ($items as $name => $value) {
$newdata[] = ['type' => $type, 'name' => $name, 'value' => $value];
}
$this->_query('SystemConfig')->empty()->insertAll($newdata);
});
$this->app->cache->delete('SystemConfig');
sysoplog('系统运维管理', '清理系统参数配置成功');
$this->success('清理系统配置成功!');
} catch (HttpResponseException $exception) {
throw $exception;
} catch (\Exception $exception) {
$this->error($exception->getMessage());
} else {
$this->error('只有超级管理员才能操作!');
}
}
}

View File

@ -2,7 +2,7 @@
{block name="button"}
<!--{if session('user.username') eq 'admin'}-->
<a class="layui-btn layui-btn-sm layui-btn-primary" data-load="{:url('admin/api.plugs/clearConfig')}">清理无效配置</a>
<a class="layui-btn layui-btn-sm layui-btn-primary" data-load="{:url('admin/api.runtime/config')}">清理无效配置</a>
<!--{/if}-->
<!--{if auth('system')}-->
@ -20,9 +20,9 @@
<div class="layui-btn-group shadow-mini nowrap">
<!--{if $app->isDebug()}-->
<a class="layui-btn layui-btn-sm layui-btn-active">以开发模式运行</a>
<a class="layui-btn layui-btn-sm layui-btn-primary" data-confirm="确定要切换到生产模式运行吗?" data-load="{:url('admin/api.plugs/debug')}?state=1">以生产模式运行</a>
<a class="layui-btn layui-btn-sm layui-btn-primary" data-confirm="确定要切换到生产模式运行吗?" data-load="{:url('admin/api.runtime/debug')}?state=1">以生产模式运行</a>
<!--{else}-->
<a class="layui-btn layui-btn-sm layui-btn-primary" data-confirm="确定要切换到开发模式运行吗?" data-load="{:url('admin/api.plugs/debug')}?state=0">以开发模式运行</a>
<a class="layui-btn layui-btn-sm layui-btn-primary" data-confirm="确定要切换到开发模式运行吗?" data-load="{:url('admin/api.runtime/debug')}?state=0">以开发模式运行</a>
<a class="layui-btn layui-btn-sm layui-btn-active">以生产模式运行</a>
<!--{/if}-->
</div>

View File

@ -27,8 +27,8 @@
<dd lay-unselect><a data-modal="{:url('admin/index/info',['id'=>session('user.id')])}"><i class="layui-icon layui-icon-set-fill"></i> 基本资料</a></dd>
<dd lay-unselect><a data-modal="{:url('admin/index/pass',['id'=>session('user.id')])}"><i class="layui-icon layui-icon-component"></i> 安全设置</a></dd>
{if session('user.username') eq 'admin'}
<dd lay-unselect><a data-load="{:url('admin/api.plugs/pushRuntime')}"><i class="layui-icon layui-icon-template-1"></i> 缓存加速</a></dd>
<dd lay-unselect><a data-load="{:url('admin/api.plugs/clearRuntime')}"><i class="layui-icon layui-icon-fonts-clear"></i> 清理缓存</a></dd>
<dd lay-unselect><a data-load="{:url('admin/api.runtime/push')}"><i class="layui-icon layui-icon-template-1"></i> 缓存加速</a></dd>
<dd lay-unselect><a data-load="{:url('admin/api.runtime/clear')}"><i class="layui-icon layui-icon-fonts-clear"></i> 清理缓存</a></dd>
{/if}
<dd lay-unselect><a data-load="{:url('admin/login/out')}" data-confirm="确定要退出登录吗?"><i class="layui-icon layui-icon-release"></i> 退出登录</a></dd>
</dl>

View File

@ -32,7 +32,7 @@ private static $installed = array (
'aliases' =>
array (
),
'reference' => '2cdefb1932c282dcacd0233e4d356c5c253da870',
'reference' => '9a07a03e6b43261a8e672fd5aabb036341009e9b',
'name' => 'zoujingli/thinkadmin',
),
'versions' =>
@ -180,7 +180,7 @@ private static $installed = array (
'aliases' =>
array (
),
'reference' => '2cdefb1932c282dcacd0233e4d356c5c253da870',
'reference' => '9a07a03e6b43261a8e672fd5aabb036341009e9b',
),
'zoujingli/wechat-developer' =>
array (

View File

@ -198,6 +198,7 @@ return array(
'app\\admin\\controller\\User' => $baseDir . '/app/admin/controller/User.php',
'app\\admin\\controller\\api\\Plugs' => $baseDir . '/app/admin/controller/api/Plugs.php',
'app\\admin\\controller\\api\\Queue' => $baseDir . '/app/admin/controller/api/Queue.php',
'app\\admin\\controller\\api\\Runtime' => $baseDir . '/app/admin/controller/api/Runtime.php',
'app\\admin\\controller\\api\\Update' => $baseDir . '/app/admin/controller/api/Update.php',
'app\\admin\\controller\\api\\Upload' => $baseDir . '/app/admin/controller/api/Upload.php',
'app\\data\\command\\OrderClean' => $baseDir . '/app/data/command/OrderClean.php',

View File

@ -327,6 +327,7 @@ class ComposerStaticInit3e3e984682c06e656fe76c5d84347fb3
'app\\admin\\controller\\User' => __DIR__ . '/../..' . '/app/admin/controller/User.php',
'app\\admin\\controller\\api\\Plugs' => __DIR__ . '/../..' . '/app/admin/controller/api/Plugs.php',
'app\\admin\\controller\\api\\Queue' => __DIR__ . '/../..' . '/app/admin/controller/api/Queue.php',
'app\\admin\\controller\\api\\Runtime' => __DIR__ . '/../..' . '/app/admin/controller/api/Runtime.php',
'app\\admin\\controller\\api\\Update' => __DIR__ . '/../..' . '/app/admin/controller/api/Update.php',
'app\\admin\\controller\\api\\Upload' => __DIR__ . '/../..' . '/app/admin/controller/api/Upload.php',
'app\\data\\command\\OrderClean' => __DIR__ . '/../..' . '/app/data/command/OrderClean.php',

View File

@ -6,7 +6,7 @@
'aliases' =>
array (
),
'reference' => '2cdefb1932c282dcacd0233e4d356c5c253da870',
'reference' => '9a07a03e6b43261a8e672fd5aabb036341009e9b',
'name' => 'zoujingli/thinkadmin',
),
'versions' =>
@ -154,7 +154,7 @@
'aliases' =>
array (
),
'reference' => '2cdefb1932c282dcacd0233e4d356c5c253da870',
'reference' => '9a07a03e6b43261a8e672fd5aabb036341009e9b',
),
'zoujingli/wechat-developer' =>
array (

2
vendor/services.php vendored
View File

@ -1,5 +1,5 @@
<?php
// This file is automatically generated at:2021-05-08 15:50:24
// This file is automatically generated at:2021-05-10 10:55:24
declare (strict_types = 1);
return array (
0 => 'think\\admin\\Library',