基础功能

This commit is contained in:
wuyanwen
2019-12-06 08:24:07 +08:00
parent 6b4dd70752
commit 397c8bb7f7
614 changed files with 57215 additions and 216 deletions

View File

@@ -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);
}
}

View File

@@ -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);

View File

@@ -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;
}
}

View File

@@ -11,7 +11,7 @@ return [
'LogLevel' => [],
'LogWrite' => [],
'RouteLoaded' => [
\app\event\LoadModuleRoutes::class,
catcher\event\LoadModuleRoutes::class,
],
],

View File

@@ -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();
});
}
}

View File

@@ -1,7 +0,0 @@
<?php
namespace app\exceptions;
class LoginFailedException extends \Exception
{
protected $code = 10002;
}

View File

@@ -1,7 +0,0 @@
<?php
namespace app\exceptions;
class ValidateFailedException extends \Exception
{
protected $code = 10001;
}