mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-07 10:32:48 +08:00
调整统一provider目录;增加content事件的快速登录案例;
This commit is contained in:
23
app/common/event/AdminLoginType/DemoEvent.php
Normal file
23
app/common/event/AdminLoginType/DemoEvent.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\event\AdminLoginType;
|
||||
|
||||
use think\facade\Env;
|
||||
use think\facade\View;
|
||||
|
||||
class DemoEvent
|
||||
{
|
||||
public function handle()
|
||||
{
|
||||
$content = '';
|
||||
|
||||
if (Env::get('adminsystem.is_demo', false)) {
|
||||
$content = View::layout(false)->fetch('login/ext/demo');
|
||||
}
|
||||
|
||||
// 事件监听处理
|
||||
return [
|
||||
'view_content' => $content,
|
||||
];
|
||||
}
|
||||
}
|
||||
9
app/common/exception/EventException.php
Normal file
9
app/common/exception/EventException.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace app\commno\exception;
|
||||
|
||||
use Exception;
|
||||
|
||||
class EventException extends Exception
|
||||
{
|
||||
}
|
||||
58
app/common/provider/ExceptionHandle.php
Normal file
58
app/common/provider/ExceptionHandle.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
namespace app\common\provider;
|
||||
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\exception\Handle;
|
||||
use think\exception\HttpException;
|
||||
use think\exception\HttpResponseException;
|
||||
use think\exception\ValidateException;
|
||||
use think\Response;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* 应用异常处理类
|
||||
*/
|
||||
class ExceptionHandle extends Handle
|
||||
{
|
||||
/**
|
||||
* 不需要记录信息(日志)的异常类列表
|
||||
* @var array
|
||||
*/
|
||||
protected $ignoreReport = [
|
||||
HttpException::class,
|
||||
HttpResponseException::class,
|
||||
ModelNotFoundException::class,
|
||||
DataNotFoundException::class,
|
||||
ValidateException::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* 记录异常信息(包括日志或者其它方式记录)
|
||||
*
|
||||
* @access public
|
||||
* @param Throwable $exception
|
||||
* @return void
|
||||
*/
|
||||
public function report(Throwable $exception): void
|
||||
{
|
||||
// 使用内置的方式记录异常日志
|
||||
parent::report($exception);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an exception into an HTTP response.
|
||||
*
|
||||
* @access public
|
||||
* @param \think\Request $request
|
||||
* @param Throwable $e
|
||||
* @return Response
|
||||
*/
|
||||
public function render($request, Throwable $e): Response
|
||||
{
|
||||
// 添加自定义异常处理机制
|
||||
|
||||
// 其他错误交给系统处理
|
||||
return parent::render($request, $e);
|
||||
}
|
||||
}
|
||||
9
app/common/provider/Request.php
Normal file
9
app/common/provider/Request.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\provider;
|
||||
|
||||
// 应用请求对象类
|
||||
class Request extends \think\Request
|
||||
{
|
||||
protected $filter = ['ua_htmlspecialchars'];
|
||||
}
|
||||
39
app/common/provider/View.php
Normal file
39
app/common/provider/View.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\provider;
|
||||
|
||||
use think\View as ThinkView;
|
||||
|
||||
class View extends ThinkView
|
||||
{
|
||||
/**
|
||||
* 设置布局
|
||||
* ! 注意,layout并非view类的标准方法,仅仅是think-view和think-template的特性方法
|
||||
* ! 但是,如果在provider中定制,则view的所有操作预期会发生错误
|
||||
* ! 同时,由于后台从设计支出就完全依赖think-view,所以专门为此扩展和特性定义方法时没有问题的.
|
||||
* @param bool|string $name 布局模板名称 false 则关闭布局
|
||||
* @param string $replace 布局模板内容替换标识
|
||||
* @return $this
|
||||
*/
|
||||
public function layout(bool|string $name, string $replace = ''): static
|
||||
{
|
||||
if (false === $name) {
|
||||
// 关闭布局
|
||||
$this->config(['layout_on' => false]);
|
||||
} else {
|
||||
// 开启布局
|
||||
$this->config(['layout_on' => true]);
|
||||
|
||||
// 名称必须为字符串
|
||||
if (is_string($name)) {
|
||||
$this->config(['layout_name' => $name]);
|
||||
}
|
||||
|
||||
if (!empty($replace)) {
|
||||
$this->config(['layout_item' => $replace]);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user