mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-01 15:32:48 +08:00
格式化代码;新增全局数据存储工具;
This commit is contained in:
9
app/common/tools/StoreValueTools.php
Normal file
9
app/common/tools/StoreValueTools.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\tools;
|
||||
|
||||
use base\common\tools\StoreValueToolsBase;
|
||||
|
||||
class StoreValueTools extends StoreValueToolsBase
|
||||
{
|
||||
}
|
||||
@@ -4,25 +4,26 @@ declare(strict_types=1);
|
||||
|
||||
namespace base;
|
||||
|
||||
use app\common\tools\StoreValueTools;
|
||||
use think\App;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Log;
|
||||
use think\Validate;
|
||||
|
||||
/**
|
||||
* 控制器基础类
|
||||
* 控制器基础类.
|
||||
*/
|
||||
abstract class BaseControllerBase
|
||||
{
|
||||
/**
|
||||
* Request实例
|
||||
* Request实例.
|
||||
* @var \think\Request
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* 应用实例
|
||||
* @var \think\App
|
||||
* 应用实例.
|
||||
* @var App
|
||||
*/
|
||||
protected $app;
|
||||
|
||||
@@ -33,14 +34,13 @@ abstract class BaseControllerBase
|
||||
protected $batchValidate = false;
|
||||
|
||||
/**
|
||||
* 控制器中间件
|
||||
* 控制器中间件.
|
||||
* @var array
|
||||
*/
|
||||
protected $middleware = [];
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
* @access public
|
||||
* 构造方法.
|
||||
* @param App $app 应用对象
|
||||
*/
|
||||
public function __construct(App $app)
|
||||
@@ -55,13 +55,12 @@ abstract class BaseControllerBase
|
||||
// 初始化
|
||||
protected function initialize()
|
||||
{
|
||||
|
||||
Log::debug('request url :' . $this->request->url());
|
||||
StoreValueTools::set('request_uid', uniqid());
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证数据
|
||||
* @access protected
|
||||
* 验证数据.
|
||||
* @param array $data 数据
|
||||
* @param string|array $validate 验证器名或者验证规则数组
|
||||
* @param array $message 提示信息
|
||||
@@ -74,7 +73,7 @@ abstract class BaseControllerBase
|
||||
if (is_array($validate)) {
|
||||
$v = new Validate();
|
||||
$v->rule($validate);
|
||||
} else if ($validate instanceof Validate) {
|
||||
} elseif ($validate instanceof Validate) {
|
||||
$v = $validate;
|
||||
} else {
|
||||
if (strpos($validate, '.')) {
|
||||
|
||||
@@ -125,7 +125,8 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td>当前版本</td>
|
||||
<td data-toggle="copy-text" data-clipboard-text="{:\\app\\common\\command\\admin\\Version::VERSION}">{:\\app\\common\\command\\admin\\Version::VERSION} <i class="fa fa-copy"></i></td>
|
||||
<td data-toggle="copy-text" data-clipboard-text="{:\\app\\common\\command\\admin\\Version::VERSION}">
|
||||
{:\\app\\common\\command\\admin\\Version::VERSION} <i class="fa fa-copy"></i></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>最新修改</td>
|
||||
@@ -139,8 +140,10 @@
|
||||
<td>Gitee</td>
|
||||
<td style="padding-bottom: 0;">
|
||||
<div class="layui-btn-container">
|
||||
<a href='https://gitee.com/ulthon/ulthon_admin/stargazers'><img src='https://gitee.com/ulthon/ulthon_admin/badge/star.svg?theme=dark' alt='star'></img></a>
|
||||
<a href='https://gitee.com/ulthon/ulthon_admin/members'><img src='https://gitee.com/ulthon/ulthon_admin/badge/fork.svg?theme=dark' alt='fork'></img></a>
|
||||
<a href='https://gitee.com/ulthon/ulthon_admin/stargazers'><img
|
||||
src='https://gitee.com/ulthon/ulthon_admin/badge/star.svg?theme=dark' alt='star'></img></a>
|
||||
<a href='https://gitee.com/ulthon/ulthon_admin/members'><img
|
||||
src='https://gitee.com/ulthon/ulthon_admin/badge/fork.svg?theme=dark' alt='fork'></img></a>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -159,7 +162,11 @@
|
||||
<tr>
|
||||
<td>日志</td>
|
||||
<td>
|
||||
<div layuimini-content-href="{:url('admin/Debug.Log/index',['create_time'=>date('Y-m-d 00:00:00').','])}" data-title="日志管理" class="layui-btn layui-btn-xs layui-btn-primary">今日日志</div>
|
||||
<div layuimini-content-href="{:url('admin/debug.Log/index',['create_time'=>date('Y-m-d 00:00:00').','])}"
|
||||
data-title="日志管理" class="layui-btn layui-btn-xs layui-btn-primary">
|
||||
今日日志
|
||||
</div>
|
||||
<div class="layui-badge">请求ID:{:get_store_value('request_uid')}</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -170,8 +177,10 @@
|
||||
<div class="layui-card">
|
||||
<div class="layui-card-header"><i class="fa fa-paper-plane-o icon"></i>作者心语</div>
|
||||
<div class="layui-card-body layui-text layadmin-text">
|
||||
<p>本模板基于layui{:\\app\\common\\command\\admin\\Version::LAYUI_VERSION}以及font-awesome-4.7.0进行实现。layui开发文档地址:<a class="layui-btn layui-btn-xs layui-btn-danger" target="_blank" href="https://layui.gitee.io/v2/">layui文档</a></p>
|
||||
<p>技术交流QQ群:<a target="_blank" href="https://jq.qq.com/?_wv=1027&k=TULvsosz"><img border="0" src="//pub.idqqimg.com/wpa/images/group.png" alt="ulthon_admin" title="ulthon_admin"></a>(加群请备注来源:如gitee、github、官网等)</p>
|
||||
<p>本模板基于layui{:\\app\\common\\command\\admin\\Version::LAYUI_VERSION}以及font-awesome-4.7.0进行实现。layui开发文档地址:<a
|
||||
class="layui-btn layui-btn-xs layui-btn-danger" target="_blank" href="https://layui.gitee.io/v2/">layui文档</a></p>
|
||||
<p>技术交流QQ群:<a target="_blank" href="https://jq.qq.com/?_wv=1027&k=TULvsosz"><img border="0" src="//pub.idqqimg.com/wpa/images/group.png"
|
||||
alt="ulthon_admin" title="ulthon_admin"></a>(加群请备注来源:如gitee、github、官网等)</p>
|
||||
<p>喜欢此后台模板的可以给我的GitHub和Gitee加个Star支持一下</p>
|
||||
<p class="layui-red">备注:此后台框架永久开源,但请勿进行出售或者上传到任何素材网站,否则将追究相应的责任。</p>
|
||||
</div>
|
||||
|
||||
33
extend/base/common/tools/StoreValueToolsBase.php
Normal file
33
extend/base/common/tools/StoreValueToolsBase.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace base\common\tools;
|
||||
|
||||
use think\helper\Arr;
|
||||
|
||||
/**
|
||||
* 全局数据存储工具.
|
||||
*
|
||||
* 可以在当前生命周期内,存储一些全局数据,
|
||||
* 相比SESSION,性能更高,但是只能在当前生命周期内使用(常驻内存服务时除外)
|
||||
*/
|
||||
class StoreValueToolsBase
|
||||
{
|
||||
protected static $store = [];
|
||||
|
||||
public static function set($key, $value)
|
||||
{
|
||||
return Arr::set(static::$store, $key, $value);
|
||||
}
|
||||
|
||||
public static function get($key, $default = null)
|
||||
{
|
||||
return Arr::get(static::$store, $key, $default);
|
||||
}
|
||||
|
||||
public static function __callStatic($name, $arguments)
|
||||
{
|
||||
$arguments = array_merge([static::$store], $arguments);
|
||||
|
||||
return call_user_func_array([Arr::class, $name], $arguments);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
use app\common\exception\EventException;
|
||||
use app\common\service\AuthService;
|
||||
use app\common\tools\StoreValueTools;
|
||||
use think\exception\HttpResponseException;
|
||||
use think\facade\App;
|
||||
use think\facade\Cache;
|
||||
@@ -349,3 +350,13 @@ function format_bytes($size, $delimiter = '')
|
||||
|
||||
return round($size, 2) . $delimiter . $units[$i];
|
||||
}
|
||||
|
||||
function get_store_value($key, $default = null)
|
||||
{
|
||||
return StoreValueTools::get($key, $default);
|
||||
}
|
||||
|
||||
function set_store_value($key, $value)
|
||||
{
|
||||
return StoreValueTools::set($key, $value);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user