diff --git a/app/ExceptionHandle.php b/app/ExceptionHandle.php index e826589..ba360b2 100644 --- a/app/ExceptionHandle.php +++ b/app/ExceptionHandle.php @@ -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, + ]; /** * 记录异常信息(包括日志或者其它方式记录) * @@ -45,16 +54,17 @@ class ExceptionHandle extends Handle * Render an exception into an HTTP response. * * @access public - * @param \think\Request $request + * @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); } diff --git a/app/Request.php b/app/Request.php index df3670d..097ac2d 100644 --- a/app/Request.php +++ b/app/Request.php @@ -3,7 +3,12 @@ namespace app; // 应用请求对象类 +use catchAdmin\user\Auth; + class Request extends \think\Request { - + public function user() + { + return Auth::user(); + } } diff --git a/catchAdmin/index/view/dashboard.html b/catchAdmin/index/view/dashboard.html new file mode 100644 index 0000000..566549b --- /dev/null +++ b/catchAdmin/index/view/dashboard.html @@ -0,0 +1,10 @@ + + + + + Title + + + + + \ No newline at end of file diff --git a/catchAdmin/index/view/error.html b/catchAdmin/index/view/error.html new file mode 100644 index 0000000..7a7a87d --- /dev/null +++ b/catchAdmin/index/view/error.html @@ -0,0 +1,48 @@ + + + + + + + 403 + + + + + + + + +
+
+ +
+
+ + +
+ +
+

403

+
抱歉,你无权访问此页面
+
+ +
+
+
+ + + + + + + \ No newline at end of file diff --git a/catchAdmin/login/validate/LoginValidate.php b/catchAdmin/login/validate/LoginValidate.php deleted file mode 100644 index d4b7099..0000000 --- a/catchAdmin/login/validate/LoginValidate.php +++ /dev/null @@ -1,18 +0,0 @@ - 'require|max:25', - 'password|密码' => 'require', - 'captcha|验证码' => 'require|captcha' - ]; - } -} \ No newline at end of file diff --git a/catchAdmin/permissions/controller/Permissions.php b/catchAdmin/permissions/controller/Permission.php similarity index 92% rename from catchAdmin/permissions/controller/Permissions.php rename to catchAdmin/permissions/controller/Permission.php index c1430c0..5defd2d 100644 --- a/catchAdmin/permissions/controller/Permissions.php +++ b/catchAdmin/permissions/controller/Permission.php @@ -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'], diff --git a/catchAdmin/permissions/controller/Roles.php b/catchAdmin/permissions/controller/Role.php similarity index 88% rename from catchAdmin/permissions/controller/Roles.php rename to catchAdmin/permissions/controller/Role.php index f9dae32..43b81ae 100644 --- a/catchAdmin/permissions/controller/Roles.php +++ b/catchAdmin/permissions/controller/Role.php @@ -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')) { diff --git a/catchAdmin/permissions/view/permissions/create.html b/catchAdmin/permissions/view/permission/create.html similarity index 100% rename from catchAdmin/permissions/view/permissions/create.html rename to catchAdmin/permissions/view/permission/create.html diff --git a/catchAdmin/permissions/view/permissions/edit.html b/catchAdmin/permissions/view/permission/edit.html similarity index 100% rename from catchAdmin/permissions/view/permissions/edit.html rename to catchAdmin/permissions/view/permission/edit.html diff --git a/catchAdmin/permissions/view/permissions/index.html b/catchAdmin/permissions/view/permission/index.html similarity index 98% rename from catchAdmin/permissions/view/permissions/index.html rename to catchAdmin/permissions/view/permission/index.html index 77ec12b..2327f54 100644 --- a/catchAdmin/permissions/view/permissions/index.html +++ b/catchAdmin/permissions/view/permission/index.html @@ -21,7 +21,7 @@ {/block} diff --git a/catchAdmin/permissions/view/roles/create.html b/catchAdmin/permissions/view/role/create.html similarity index 94% rename from catchAdmin/permissions/view/roles/create.html rename to catchAdmin/permissions/view/role/create.html index e27f062..9325b59 100644 --- a/catchAdmin/permissions/view/roles/create.html +++ b/catchAdmin/permissions/view/role/create.html @@ -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', diff --git a/catchAdmin/permissions/view/roles/edit.html b/catchAdmin/permissions/view/role/edit.html similarity index 96% rename from catchAdmin/permissions/view/roles/edit.html rename to catchAdmin/permissions/view/role/edit.html index ce1d7d0..ceaa644 100644 --- a/catchAdmin/permissions/view/roles/edit.html +++ b/catchAdmin/permissions/view/role/edit.html @@ -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[]', diff --git a/catchAdmin/permissions/view/roles/index.html b/catchAdmin/permissions/view/role/index.html similarity index 98% rename from catchAdmin/permissions/view/roles/index.html rename to catchAdmin/permissions/view/role/index.html index e1da354..5687279 100644 --- a/catchAdmin/permissions/view/roles/index.html +++ b/catchAdmin/permissions/view/role/index.html @@ -21,7 +21,7 @@ {/block} @@ -125,7 +125,6 @@ setTimeout(function () { treeTb.expand(mRole.id) }, 200) - } else { if (mRole) { treeTb.reload(); diff --git a/catchAdmin/login/Auth.php b/catchAdmin/user/Auth.php similarity index 100% rename from catchAdmin/login/Auth.php rename to catchAdmin/user/Auth.php diff --git a/config/catch.php b/config/catch.php new file mode 100644 index 0000000..b3d9bbc --- /dev/null +++ b/config/catch.php @@ -0,0 +1 @@ +