基础功能
This commit is contained in:
@@ -93,26 +93,4 @@ abstract class BaseController
|
||||
|
||||
return $v->failException(true)->check($data);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年11月28日
|
||||
* @param string $template
|
||||
* @throws \Exception
|
||||
* @return string
|
||||
*/
|
||||
protected function fetch($template = ''): string
|
||||
{
|
||||
if (Str::contains($template, '::')) {
|
||||
[$module, $template] = explode('::', $template);
|
||||
|
||||
View::config([
|
||||
'view_path' => CatchAdmin::getViews()[$module]
|
||||
]);
|
||||
|
||||
return View::fetch($template);
|
||||
}
|
||||
|
||||
return View::fetch($template);
|
||||
}
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
namespace app;
|
||||
|
||||
use catcher\JsonResponse;
|
||||
use catcher\CatchResponse;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\exception\Handle;
|
||||
@@ -53,7 +53,7 @@ class ExceptionHandle extends Handle
|
||||
{
|
||||
// 添加自定义异常处理机制
|
||||
if ($request->isAjax()) {
|
||||
return JsonResponse::fail($e->getMessage(), $e->getCode());
|
||||
return CatchResponse::fail($e->getMessage(), $e->getCode());
|
||||
}
|
||||
// 其他错误交给系统处理
|
||||
return parent::render($request, $e);
|
||||
|
@@ -2,39 +2,8 @@
|
||||
namespace app;
|
||||
|
||||
// 应用请求对象类
|
||||
use app\exceptions\ValidateFailedException;
|
||||
|
||||
class Request extends \think\Request
|
||||
{
|
||||
/**
|
||||
* Request constructor.
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->validate();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化验证
|
||||
*
|
||||
* @time 2019年11月27日
|
||||
* @throws \Exception
|
||||
* @return mixed
|
||||
*/
|
||||
protected function validate()
|
||||
{
|
||||
if (method_exists($this, 'getValidate')) {
|
||||
$validate = $this->getValidate();
|
||||
|
||||
if (!$validate->check(request()->param())) {
|
||||
throw new ValidateFailedException($validate->getError());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@@ -11,7 +11,7 @@ return [
|
||||
'LogLevel' => [],
|
||||
'LogWrite' => [],
|
||||
'RouteLoaded' => [
|
||||
\app\event\LoadModuleRoutes::class,
|
||||
catcher\event\LoadModuleRoutes::class,
|
||||
],
|
||||
],
|
||||
|
||||
|
@@ -1,25 +0,0 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\event;
|
||||
|
||||
use catcher\CatchAdmin;
|
||||
use think\Route;
|
||||
|
||||
class LoadModuleRoutes
|
||||
{
|
||||
/**
|
||||
* 处理
|
||||
*
|
||||
* @time 2019年11月29日
|
||||
* @return void
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
$router = app(Route::class);
|
||||
|
||||
$router->group(function () use ($router) {
|
||||
include CatchAdmin::getRoutes();
|
||||
});
|
||||
}
|
||||
}
|
@@ -1,7 +0,0 @@
|
||||
<?php
|
||||
namespace app\exceptions;
|
||||
|
||||
class LoginFailedException extends \Exception
|
||||
{
|
||||
protected $code = 10002;
|
||||
}
|
@@ -1,7 +0,0 @@
|
||||
<?php
|
||||
namespace app\exceptions;
|
||||
|
||||
class ValidateFailedException extends \Exception
|
||||
{
|
||||
protected $code = 10001;
|
||||
}
|
Reference in New Issue
Block a user