新增后台基础公共库

This commit is contained in:
wuyanwen 2019-12-12 18:54:07 +08:00
parent 4a5993160f
commit d53b0bae73
6 changed files with 54 additions and 16 deletions

View File

@ -126,6 +126,25 @@ class CatchAdmin
return $modules; return $modules;
} }
/**
*
* @time 2019年12月12日
* @return array
*/
public static function getModulesInfo(): array
{
$modules = [];
foreach (self::getModulesDirectory() as $module) {
$moduleInfo = self::getModuleInfo($module);
$modules[] = [
'value' => $moduleInfo['alias'],
'title' => $moduleInfo['name'],
];
}
return $modules;
}
/** /**
* *
* @time 2019年11月30日 * @time 2019年11月30日

View File

@ -355,12 +355,12 @@ class CatchForm
*/ */
private function selectField($field) private function selectField($field)
{ {
$select = sprintf('<select name="%s">', $field['name']); $select = sprintf('<select name="%s" %s>', $field['name'], $field['verify'] ?? '');
$default = $field['default'] ?? ''; $default = $field['default'] ?? '';
foreach ($field['options'] as $key => $option) { foreach ($field['options'] as $key => $option) {
$select .= sprintf('<option value="%s"%s>%s</option>', $key, $default == $key ? ' selected' : '',$option); $select .= sprintf('<option value="%s"%s>%s</option>', $option['value'], $default == $key ? ' selected' : '',$option['title']);
} }
return $select . '</select>'; return $select . '</select>';

View File

@ -1,7 +1,9 @@
<?php <?php
namespace catcher; namespace catcher;
use think\facade\View;
use think\Paginator; use think\Paginator;
use think\Response;
class CatchResponse class CatchResponse
{ {
@ -16,11 +18,13 @@ class CatchResponse
*/ */
public static function success($data = [], $msg = 'success', $code = 10000): \think\response\Json public static function success($data = [], $msg = 'success', $code = 10000): \think\response\Json
{ {
return json([ if (request()->isAjax()) {
'code' => $code, return json([
'msg' => $msg, 'code' => $code,
'data' => $data, 'msg' => $msg,
]); 'data' => $data,
]);
}
} }
/** /**
@ -47,13 +51,18 @@ class CatchResponse
* @time 2019年12月02日 * @time 2019年12月02日
* @param string $msg * @param string $msg
* @param int $code * @param int $code
* @return \think\response\Json * @return mixed
* @throws \Exception
*/ */
public static function fail($msg = '', $code = 10001): \think\response\Json public static function fail($msg = '', $code = 10001)
{ {
return json([ if (request()->isAjax()) {
'code' => $code, return json([
'msg' => $msg, 'code' => $code,
]); 'msg' => $msg,
]);
}
return Response::create(config('catch.error'), 'view', $code)->assign(['msg' => $msg]);
} }
} }

View File

@ -6,6 +6,8 @@ use think\facade\View;
abstract class CatchController abstract class CatchController
{ {
protected $middleware = ['check_auth'];
/** /**
* *
* @time 2019年11月28日 * @time 2019年11月28日

View File

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

View File

@ -1 +1,9 @@
<?php <?php
namespace catcher\exceptions;
class PermissionForbiddenException extends \Exception
{
protected $code = 10005;
protected $message = 'permission forbidden';
}