mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-10-03 15:39:57 +08:00
优化后台管理
This commit is contained in:
parent
9a07a03e6b
commit
91af7bb7f9
@ -17,8 +17,6 @@ namespace app\admin\controller\api;
|
|||||||
|
|
||||||
use think\admin\Controller;
|
use think\admin\Controller;
|
||||||
use think\admin\service\AdminService;
|
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'));
|
$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
|
* @login true
|
||||||
@ -71,73 +50,4 @@ class Plugs extends Controller
|
|||||||
$this->error('只有超级管理员才能操作!');
|
$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('只有超级管理员才能操作!');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
119
app/admin/controller/api/Runtime.php
Normal file
119
app/admin/controller/api/Runtime.php
Normal 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('只有超级管理员才能操作!');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
{block name="button"}
|
{block name="button"}
|
||||||
<!--{if session('user.username') eq 'admin'}-->
|
<!--{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}-->
|
||||||
|
|
||||||
<!--{if auth('system')}-->
|
<!--{if auth('system')}-->
|
||||||
@ -20,9 +20,9 @@
|
|||||||
<div class="layui-btn-group shadow-mini nowrap">
|
<div class="layui-btn-group shadow-mini nowrap">
|
||||||
<!--{if $app->isDebug()}-->
|
<!--{if $app->isDebug()}-->
|
||||||
<a class="layui-btn layui-btn-sm layui-btn-active">以开发模式运行</a>
|
<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}-->
|
<!--{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>
|
<a class="layui-btn layui-btn-sm layui-btn-active">以生产模式运行</a>
|
||||||
<!--{/if}-->
|
<!--{/if}-->
|
||||||
</div>
|
</div>
|
||||||
|
@ -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/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>
|
<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'}
|
{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.runtime/push')}"><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/clear')}"><i class="layui-icon layui-icon-fonts-clear"></i> 清理缓存</a></dd>
|
||||||
{/if}
|
{/if}
|
||||||
<dd lay-unselect><a data-load="{:url('admin/login/out')}" data-confirm="确定要退出登录吗?"><i class="layui-icon layui-icon-release"></i> 退出登录</a></dd>
|
<dd lay-unselect><a data-load="{:url('admin/login/out')}" data-confirm="确定要退出登录吗?"><i class="layui-icon layui-icon-release"></i> 退出登录</a></dd>
|
||||||
</dl>
|
</dl>
|
||||||
|
4
vendor/composer/InstalledVersions.php
vendored
4
vendor/composer/InstalledVersions.php
vendored
@ -32,7 +32,7 @@ private static $installed = array (
|
|||||||
'aliases' =>
|
'aliases' =>
|
||||||
array (
|
array (
|
||||||
),
|
),
|
||||||
'reference' => '2cdefb1932c282dcacd0233e4d356c5c253da870',
|
'reference' => '9a07a03e6b43261a8e672fd5aabb036341009e9b',
|
||||||
'name' => 'zoujingli/thinkadmin',
|
'name' => 'zoujingli/thinkadmin',
|
||||||
),
|
),
|
||||||
'versions' =>
|
'versions' =>
|
||||||
@ -180,7 +180,7 @@ private static $installed = array (
|
|||||||
'aliases' =>
|
'aliases' =>
|
||||||
array (
|
array (
|
||||||
),
|
),
|
||||||
'reference' => '2cdefb1932c282dcacd0233e4d356c5c253da870',
|
'reference' => '9a07a03e6b43261a8e672fd5aabb036341009e9b',
|
||||||
),
|
),
|
||||||
'zoujingli/wechat-developer' =>
|
'zoujingli/wechat-developer' =>
|
||||||
array (
|
array (
|
||||||
|
1
vendor/composer/autoload_classmap.php
vendored
1
vendor/composer/autoload_classmap.php
vendored
@ -198,6 +198,7 @@ return array(
|
|||||||
'app\\admin\\controller\\User' => $baseDir . '/app/admin/controller/User.php',
|
'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\\Plugs' => $baseDir . '/app/admin/controller/api/Plugs.php',
|
||||||
'app\\admin\\controller\\api\\Queue' => $baseDir . '/app/admin/controller/api/Queue.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\\Update' => $baseDir . '/app/admin/controller/api/Update.php',
|
||||||
'app\\admin\\controller\\api\\Upload' => $baseDir . '/app/admin/controller/api/Upload.php',
|
'app\\admin\\controller\\api\\Upload' => $baseDir . '/app/admin/controller/api/Upload.php',
|
||||||
'app\\data\\command\\OrderClean' => $baseDir . '/app/data/command/OrderClean.php',
|
'app\\data\\command\\OrderClean' => $baseDir . '/app/data/command/OrderClean.php',
|
||||||
|
1
vendor/composer/autoload_static.php
vendored
1
vendor/composer/autoload_static.php
vendored
@ -327,6 +327,7 @@ class ComposerStaticInit3e3e984682c06e656fe76c5d84347fb3
|
|||||||
'app\\admin\\controller\\User' => __DIR__ . '/../..' . '/app/admin/controller/User.php',
|
'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\\Plugs' => __DIR__ . '/../..' . '/app/admin/controller/api/Plugs.php',
|
||||||
'app\\admin\\controller\\api\\Queue' => __DIR__ . '/../..' . '/app/admin/controller/api/Queue.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\\Update' => __DIR__ . '/../..' . '/app/admin/controller/api/Update.php',
|
||||||
'app\\admin\\controller\\api\\Upload' => __DIR__ . '/../..' . '/app/admin/controller/api/Upload.php',
|
'app\\admin\\controller\\api\\Upload' => __DIR__ . '/../..' . '/app/admin/controller/api/Upload.php',
|
||||||
'app\\data\\command\\OrderClean' => __DIR__ . '/../..' . '/app/data/command/OrderClean.php',
|
'app\\data\\command\\OrderClean' => __DIR__ . '/../..' . '/app/data/command/OrderClean.php',
|
||||||
|
4
vendor/composer/installed.php
vendored
4
vendor/composer/installed.php
vendored
@ -6,7 +6,7 @@
|
|||||||
'aliases' =>
|
'aliases' =>
|
||||||
array (
|
array (
|
||||||
),
|
),
|
||||||
'reference' => '2cdefb1932c282dcacd0233e4d356c5c253da870',
|
'reference' => '9a07a03e6b43261a8e672fd5aabb036341009e9b',
|
||||||
'name' => 'zoujingli/thinkadmin',
|
'name' => 'zoujingli/thinkadmin',
|
||||||
),
|
),
|
||||||
'versions' =>
|
'versions' =>
|
||||||
@ -154,7 +154,7 @@
|
|||||||
'aliases' =>
|
'aliases' =>
|
||||||
array (
|
array (
|
||||||
),
|
),
|
||||||
'reference' => '2cdefb1932c282dcacd0233e4d356c5c253da870',
|
'reference' => '9a07a03e6b43261a8e672fd5aabb036341009e9b',
|
||||||
),
|
),
|
||||||
'zoujingli/wechat-developer' =>
|
'zoujingli/wechat-developer' =>
|
||||||
array (
|
array (
|
||||||
|
2
vendor/services.php
vendored
2
vendor/services.php
vendored
@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?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);
|
declare (strict_types = 1);
|
||||||
return array (
|
return array (
|
||||||
0 => 'think\\admin\\Library',
|
0 => 'think\\admin\\Library',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user