增加基础
This commit is contained in:
parent
ca4272d7a6
commit
5f6a7cf24e
@ -2,6 +2,9 @@
|
||||
namespace app;
|
||||
|
||||
use catcher\CatchResponse;
|
||||
use catcher\exceptions\FailedException;
|
||||
use catcher\exceptions\LoginFailedException;
|
||||
use catcher\exceptions\PermissionForbiddenException;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\exception\Handle;
|
||||
@ -28,6 +31,12 @@ class ExceptionHandle extends Handle
|
||||
ValidateException::class,
|
||||
];
|
||||
|
||||
protected $catchExceptions = [
|
||||
FailedException::class,
|
||||
LoginFailedException::class,
|
||||
ValidateException::class,
|
||||
PermissionForbiddenException::class,
|
||||
];
|
||||
/**
|
||||
* 记录异常信息(包括日志或者其它方式记录)
|
||||
*
|
||||
@ -48,13 +57,14 @@ class ExceptionHandle extends Handle
|
||||
* @param \think\Request $request
|
||||
* @param Throwable $e
|
||||
* @return Response
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function render($request, Throwable $e): Response
|
||||
{
|
||||
// 添加自定义异常处理机制
|
||||
if ($request->isAjax()) {
|
||||
if (in_array(get_class($e), $this->catchExceptions)) {
|
||||
return CatchResponse::fail($e->getMessage(), $e->getCode());
|
||||
}
|
||||
|
||||
// 其他错误交给系统处理
|
||||
return parent::render($request, $e);
|
||||
}
|
||||
|
@ -3,7 +3,12 @@ namespace app;
|
||||
|
||||
// 应用请求对象类
|
||||
|
||||
use catchAdmin\user\Auth;
|
||||
|
||||
class Request extends \think\Request
|
||||
{
|
||||
|
||||
public function user()
|
||||
{
|
||||
return Auth::user();
|
||||
}
|
||||
}
|
||||
|
10
catchAdmin/index/view/dashboard.html
Normal file
10
catchAdmin/index/view/dashboard.html
Normal file
@ -0,0 +1,10 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
</body>
|
||||
</html>
|
48
catchAdmin/index/view/error.html
Normal file
48
catchAdmin/index/view/error.html
Normal file
@ -0,0 +1,48 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
|
||||
<title>403</title>
|
||||
<link rel="stylesheet" href="__CATCH_ADMIN_LIBS__/layui/css/layui.css"/>
|
||||
<link rel="stylesheet" href="__CATCH_ADMIN_MODULE__/admin.css?v=315"/>
|
||||
<link rel="stylesheet" href="__CATCH_ADMIN_CSS__/error-page.css"/>
|
||||
<!--[if lt IE 9]>
|
||||
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
|
||||
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
|
||||
<![endif]-->
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<!-- 加载动画 -->
|
||||
<div class="page-loading">
|
||||
<div class="ball-loader">
|
||||
<span></span><span></span><span></span><span></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 正文开始 -->
|
||||
<div class="error-page">
|
||||
<img class="error-page-img" src="__CATCH_ADMIN_IMAGES__/ic_403.png">
|
||||
<div class="error-page-info">
|
||||
<h1>403</h1>
|
||||
<div class="error-page-info-desc">抱歉,你无权访问此页面</div>
|
||||
<div>
|
||||
<button ew-href="/" class="layui-btn">返回首页</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- js部分 -->
|
||||
<script type="text/javascript" src="__CATCH_ADMIN_LIBS__/layui/layui.js"></script>
|
||||
<script type="text/javascript" src="__CATCH_ADMIN_JS__/common.js?v=315"></script>
|
||||
<script>
|
||||
layui.use(['admin'], function () {
|
||||
var $ = layui.jquery;
|
||||
var admin = layui.admin;
|
||||
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace catchAdmin\login\validate;
|
||||
|
||||
use catcher\base\BaseValidate;
|
||||
|
||||
class LoginValidate extends BaseValidate
|
||||
{
|
||||
protected function getRules(): array
|
||||
{
|
||||
// TODO: Implement getRules() method.
|
||||
return [
|
||||
'name|用户名' => 'require|max:25',
|
||||
'password|密码' => 'require',
|
||||
'captcha|验证码' => 'require|captcha'
|
||||
];
|
||||
}
|
||||
}
|
@ -4,13 +4,14 @@ namespace catchAdmin\permissions\controller;
|
||||
|
||||
use app\Request;
|
||||
use catcher\base\CatchController;
|
||||
use catcher\CatchAdmin;
|
||||
use catcher\CatchForm;
|
||||
use catcher\CatchResponse;
|
||||
use catcher\exceptions\FailedException;
|
||||
use catcher\Tree;
|
||||
use catchAdmin\permissions\model\Permissions as Permission;
|
||||
|
||||
class Permissions extends CatchController
|
||||
class Permission extends CatchController
|
||||
{
|
||||
protected $permissions;
|
||||
|
||||
@ -50,10 +51,10 @@ class Permissions extends CatchController
|
||||
public function create()
|
||||
{
|
||||
$form = new CatchForm();
|
||||
|
||||
$form->formId('permission');
|
||||
$form->text('permission_name', '菜单名称', true)->verify('required')->placeholder('请输入菜单名称');
|
||||
$form->hidden('parent_id')->default(\request()->param('id') ?? 0);
|
||||
$form->select('module', '模块', true)->verify('required')->options(CatchAdmin::getModulesInfo());
|
||||
$form->text('route', '路由')->placeholder('请输入路由');
|
||||
$form->radio('method', '请求方法', true)->default(Permission::GET)->options([
|
||||
['value' => Permission::GET, 'title' => 'get'],
|
||||
@ -104,8 +105,9 @@ class Permissions extends CatchController
|
||||
->verify('required')
|
||||
->placeholder('请输入菜单名称');
|
||||
$form->hidden('parent_id')->default($permission->parent_id);
|
||||
$form->select('module', '模块', true)->default($permission->module)->options(CatchAdmin::getModulesInfo());
|
||||
$form->text('route', '路由')->default($permission->route)->placeholder('请输入路由');
|
||||
$form->radio('method', '请求方法', true)->default($permission->method)->options([
|
||||
$form->radio('method', '请求方法', true)->verify('required')->default($permission->method)->options([
|
||||
['value' => Permission::GET, 'title' => 'get'],
|
||||
['value' => Permission::POST, 'title' => 'post'],
|
||||
['value' => Permission::PUT, 'title' => 'put'],
|
@ -46,7 +46,8 @@ class Roles extends CatchController
|
||||
$form->formBtn('submitRole');
|
||||
|
||||
return $this->fetch([
|
||||
'form' => $form->render()
|
||||
'form' => $form->render(),
|
||||
'parent_id' => \request()->param('id') ?? 0,
|
||||
]);
|
||||
}
|
||||
|
||||
@ -95,6 +96,7 @@ class Roles extends CatchController
|
||||
return $this->fetch([
|
||||
'form' => $form->render(),
|
||||
'role_id' => $role->id,
|
||||
'parent_id' => $role->parent_id
|
||||
]);
|
||||
}
|
||||
|
||||
@ -167,7 +169,17 @@ class Roles extends CatchController
|
||||
*/
|
||||
public function getPermissions(Request $request, \catchAdmin\permissions\model\Permissions $permission): Json
|
||||
{
|
||||
$permissions = Tree::done($permission->getList());
|
||||
$parentRoleHasPermissionIds = null;
|
||||
if ($request->param('parent_id')) {
|
||||
$permissions = $this->role->findBy($request->param('parent_id'))->getPermissions();
|
||||
foreach ($permissions as $_permission) {
|
||||
$parentRoleHasPermissionIds[] = $_permission->pivot->permission_id;
|
||||
}
|
||||
}
|
||||
|
||||
$permissions = Tree::done($permission->getList([
|
||||
'permission_ids' => $parentRoleHasPermissionIds
|
||||
]));
|
||||
|
||||
$permissionIds = [];
|
||||
if ($request->param('role_id')) {
|
@ -21,7 +21,7 @@
|
||||
<!-- 表格操作列 -->
|
||||
<script type="text/html" id="tableBarAuth">
|
||||
<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
|
||||
<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="add">新增子菜单</a>
|
||||
<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="add">新增子菜单</a>
|
||||
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
|
||||
</script>
|
||||
{/block}
|
@ -23,7 +23,7 @@
|
||||
}, 'post');
|
||||
return false;
|
||||
});
|
||||
admin.req('{:url("/role/get/permissions")}',{}, function (response) {
|
||||
admin.req('{:url("/role/get/permissions")}',{parent_id:"{$parent_id}"}, function (response) {
|
||||
authtree.render('#permissions', response.data.permissions,{
|
||||
inputname: 'permissionids[]',
|
||||
layfilter: 'lay-check-auth',
|
@ -10,7 +10,7 @@
|
||||
|
||||
// 回显数据
|
||||
form.val('role', mUser);
|
||||
admin.req('{:url("/role/get/permissions")}',{role_id:"{$role_id}"}, function (response) {
|
||||
admin.req('{:url("/role/get/permissions")}',{role_id:"{$role_id}", parent_id:"{$parent_id}"}, function (response) {
|
||||
console.log(response.data)
|
||||
authtree.render('#permissions', response.data.permissions,{
|
||||
inputname: 'permissionids[]',
|
@ -21,7 +21,7 @@
|
||||
<!-- 表格操作列 -->
|
||||
<script type="text/html" id="tableBarAuth">
|
||||
<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
|
||||
<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="add">新增子角色</a>
|
||||
<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="add">新增子角色</a>
|
||||
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
|
||||
</script>
|
||||
{/block}
|
||||
@ -125,7 +125,6 @@
|
||||
setTimeout(function () {
|
||||
treeTb.expand(mRole.id)
|
||||
}, 200)
|
||||
|
||||
} else {
|
||||
if (mRole) {
|
||||
treeTb.reload();
|
1
config/catch.php
Normal file
1
config/catch.php
Normal file
@ -0,0 +1 @@
|
||||
<?php
|
@ -0,0 +1 @@
|
||||
<?php
|
Loading…
x
Reference in New Issue
Block a user