first commit
This commit is contained in:
@@ -5,7 +5,7 @@ use think\helper\Arr;
|
||||
|
||||
class CatchAdmin
|
||||
{
|
||||
public const NAME = 'catchAdmin';
|
||||
public const NAME = 'catch';
|
||||
|
||||
/**
|
||||
*
|
||||
|
@@ -16,7 +16,7 @@ class CatchResponse
|
||||
* @param int $code
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public static function success($data = [], $msg = 'success', $code = 10000): \think\response\Json
|
||||
public static function success($data = [], $msg = 'success', $code = Code::SUCCESS): \think\response\Json
|
||||
{
|
||||
return json([
|
||||
'code' => $code,
|
||||
@@ -39,6 +39,7 @@ class CatchResponse
|
||||
'msg' => 'success',
|
||||
'count' => $list->total(),
|
||||
'current' => $list->currentPage(),
|
||||
'limit' => $list->listRows(),
|
||||
'data' => $list->getCollection(),
|
||||
]);
|
||||
}
|
||||
|
13
extend/catcher/Code.php
Normal file
13
extend/catcher/Code.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
namespace catcher;
|
||||
|
||||
class Code
|
||||
{
|
||||
public const SUCCESS = 10000; // 成功
|
||||
public const LOST_LOGIN = 10001; // 登录失效
|
||||
public const VALIDATE_FAILED = 10002; // 验证错误
|
||||
public const PERMISSION_FORBIDDEN = 10003; // 权限禁止
|
||||
public const LOGIN_FAILED = 10004; // 登录失败
|
||||
public const FAILED = 10005; // 操作失败
|
||||
|
||||
}
|
@@ -49,7 +49,7 @@ class CompressPackageCommand extends Command
|
||||
protected function zip($package): void
|
||||
{
|
||||
if (!is_dir(CatchAdmin::directory() . $package)) {
|
||||
$package = $this->output->ask($this->input, sprintf('Can not find [%s] in catchAdmin directory, you should input package again', $package));
|
||||
$package = $this->output->ask($this->input, sprintf('Can not find [%s] in catch directory, you should input package again', $package));
|
||||
}
|
||||
|
||||
if (!is_dir(CatchAdmin::directory() . $package)) {
|
||||
|
@@ -78,7 +78,7 @@ class ModelGeneratorCommand extends Command
|
||||
{
|
||||
return <<<EOT
|
||||
<?php
|
||||
namespace catchAdmin\{Module}\model;
|
||||
namespace catch\{Module}\model;
|
||||
|
||||
use cather\base\BaseModel;
|
||||
|
||||
|
@@ -3,6 +3,7 @@ declare (strict_types = 1);
|
||||
|
||||
namespace catcher\event;
|
||||
|
||||
use catchAdmin\user\AuthTokenMiddleware;
|
||||
use catcher\CatchAdmin;
|
||||
use think\Route;
|
||||
|
||||
@@ -27,14 +28,17 @@ class LoadModuleRoutes
|
||||
foreach ($routes as $route) {
|
||||
include $route;
|
||||
}
|
||||
});
|
||||
})->middleware([AuthTokenMiddleware::class]);
|
||||
} else {
|
||||
$router->group(function () use ($router, $routes) {
|
||||
foreach ($routes as $route) {
|
||||
include $route;
|
||||
}
|
||||
});
|
||||
})->middleware([AuthTokenMiddleware::class]);
|
||||
}
|
||||
|
||||
// 单独加载登录
|
||||
include CatchAdmin::moduleDirectory('login') . 'route.php';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -45,7 +49,7 @@ class LoadModuleRoutes
|
||||
protected function getRoutes(): array
|
||||
{
|
||||
$routes = CatchAdmin::getRoutes();
|
||||
array_push($routes, CatchAdmin::directory() . 'login' . DIRECTORY_SEPARATOR . 'route.php');
|
||||
|
||||
return $routes;
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,20 @@
|
||||
<?php
|
||||
namespace catcher\exceptions;
|
||||
|
||||
abstract class CatchException extends \Exception
|
||||
{}
|
||||
use Exception;
|
||||
use think\exception\HttpException;
|
||||
|
||||
abstract class CatchException extends HttpException
|
||||
{
|
||||
protected const HTTP_SUCCESS = 200;
|
||||
|
||||
public function __construct(string $message = '', int $code = 0, Exception $previous = null, array $headers = [], $statusCode = 0)
|
||||
{
|
||||
parent::__construct($statusCode, $message, $previous, $headers, $code);
|
||||
}
|
||||
|
||||
public function getStatusCode()
|
||||
{
|
||||
return self::HTTP_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
@@ -1,7 +1,9 @@
|
||||
<?php
|
||||
namespace catcher\exceptions;
|
||||
|
||||
use catcher\Code;
|
||||
|
||||
class FailedException extends CatchException
|
||||
{
|
||||
protected $code = 10010;
|
||||
protected $code = Code::FAILED;
|
||||
}
|
||||
|
@@ -1,7 +1,9 @@
|
||||
<?php
|
||||
namespace catcher\exceptions;
|
||||
|
||||
use catcher\Code;
|
||||
|
||||
class LoginFailedException extends CatchException
|
||||
{
|
||||
protected $code = 10010;
|
||||
protected $code = Code::LOGIN_FAILED;
|
||||
}
|
@@ -1,9 +1,11 @@
|
||||
<?php
|
||||
namespace catcher\exceptions;
|
||||
|
||||
use catcher\Code;
|
||||
|
||||
class PermissionForbiddenException extends CatchException
|
||||
{
|
||||
protected $code = 10005;
|
||||
protected $code = Code::PERMISSION_FORBIDDEN;
|
||||
|
||||
protected $message = 'permission forbidden';
|
||||
}
|
||||
|
@@ -1,7 +1,9 @@
|
||||
<?php
|
||||
namespace catcher\exceptions;
|
||||
|
||||
use catcher\Code;
|
||||
|
||||
class ValidateFailedException extends CatchException
|
||||
{
|
||||
protected $code = 10001;
|
||||
protected $code = Code::VALIDATE_FAILED;
|
||||
}
|
||||
|
Reference in New Issue
Block a user