修改权限管理
This commit is contained in:
@@ -3,6 +3,7 @@ namespace catchAdmin\permissions;
|
||||
|
||||
use app\Request;
|
||||
use catchAdmin\permissions\model\Permissions;
|
||||
use catcher\Code;
|
||||
use catcher\exceptions\PermissionForbiddenException;
|
||||
use think\helper\Str;
|
||||
|
||||
@@ -34,7 +35,7 @@ class PermissionsMiddleware
|
||||
}
|
||||
|
||||
if (!$request->user()) {
|
||||
throw new PermissionForbiddenException('Login is invalid', 10006);
|
||||
throw new PermissionForbiddenException('Login is invalid', Code::LOST_LOGIN);
|
||||
}
|
||||
|
||||
// toad
|
||||
@@ -95,4 +96,4 @@ class PermissionsMiddleware
|
||||
{
|
||||
return ['login'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -20,24 +20,13 @@ class Permission extends CatchController
|
||||
$this->permissions = $permissions;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月11日
|
||||
* @throws \Exception
|
||||
* @return string
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月11日
|
||||
* @param Request $request
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function list(Request $request)
|
||||
public function index(Request $request)
|
||||
{
|
||||
return CatchResponse::success(Tree::done($this->permissions->getList($request->param())));
|
||||
}
|
||||
@@ -49,29 +38,7 @@ class Permission extends CatchController
|
||||
* @return string
|
||||
*/
|
||||
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(Permissions::GET)->options([
|
||||
['value' => Permissions::GET, 'title' => 'get'],
|
||||
['value' => Permissions::POST, 'title' => 'post'],
|
||||
['value' => Permissions::PUT, 'title' => 'put'],
|
||||
['value' => Permissions::DELETE, 'title' => 'delete'],
|
||||
]);
|
||||
$form->text('permission_mark', '权限标识', true)->verify('required')->placeholder('请输入权限标识controller:action');
|
||||
$form->radio('type', '类型', true)->default(Permissions::BTN_TYPE)->options([
|
||||
['value' => Permissions::MENU_TYPE, 'title' => '菜单'],
|
||||
['value' => Permissions::BTN_TYPE, 'title' => '按钮'],
|
||||
]);
|
||||
$form->text('sort', '排序')->verify('numberX')->default(1)->placeholder('倒叙排序');
|
||||
$form->formBtn('submitPermission');
|
||||
|
||||
return $this->fetch(['form' => $form->render()]);
|
||||
}
|
||||
{}
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -95,39 +62,7 @@ class Permission extends CatchController
|
||||
* @return string
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$permission = $this->permissions->findBy($id);
|
||||
|
||||
$form = new CatchForm();
|
||||
$form->formId('permission');
|
||||
$form->text('permission_name', '菜单名称', true)
|
||||
->default($permission->permission_name)
|
||||
->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)->verify('required')->default($permission->method)->options([
|
||||
['value' => Permissions::GET, 'title' => 'get'],
|
||||
['value' => Permissions::POST, 'title' => 'post'],
|
||||
['value' => Permissions::PUT, 'title' => 'put'],
|
||||
['value' => Permissions::DELETE, 'title' => 'delete'],
|
||||
]);
|
||||
$form->text('permission_mark', '权限标识', true)
|
||||
->default($permission->permission_mark)
|
||||
->verify('required')->placeholder('请输入权限标识controller:action');
|
||||
$form->radio('type', '类型', true)->default($permission->type)->options([
|
||||
['value' => Permissions::MENU_TYPE, 'title' => '菜单'],
|
||||
['value' => Permissions::BTN_TYPE, 'title' => '按钮'],
|
||||
]);
|
||||
$form->text('sort', '排序')->verify('numberX')->default($permission->sort)->placeholder('倒叙排序');
|
||||
$form->formBtn('submitPermission');
|
||||
|
||||
return $this->fetch([
|
||||
'form' => $form->render(),
|
||||
'permission_id' => $permission->id,
|
||||
]);
|
||||
}
|
||||
{}
|
||||
|
||||
/**
|
||||
*
|
||||
|
@@ -18,15 +18,15 @@ class Role extends CatchController
|
||||
$this->role = $role;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月09日
|
||||
* @throws \Exception
|
||||
* @return string
|
||||
*/
|
||||
public function index()
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月09日
|
||||
* @param Request $request
|
||||
* @return string
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
return $this->fetch();
|
||||
return CatchResponse::success(Tree::done($this->role->getList($request->param())));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -36,20 +36,7 @@ class Role extends CatchController
|
||||
* @return string
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$form = new CatchForm();
|
||||
$form->formId('role');
|
||||
$form->text('role_name', '角色名称', true)->verify('required')->placeholder('请输入角色名称');
|
||||
$form->hidden('parent_id')->default(\request()->param('id') ?? 0);
|
||||
$form->textarea('description', '角色描述')->placeholder('请输入角色描述');
|
||||
$form->dom('<div id="permissions"></div>', '权限');
|
||||
$form->formBtn('submitRole');
|
||||
|
||||
return $this->fetch([
|
||||
'form' => $form->render(),
|
||||
'parent_id' => \request()->param('id') ?? 0,
|
||||
]);
|
||||
}
|
||||
{}
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -149,17 +136,6 @@ class Role extends CatchController
|
||||
return CatchResponse::success();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月11日
|
||||
* @param Request $request
|
||||
* @return Json
|
||||
*/
|
||||
public function list(Request $request)
|
||||
{
|
||||
return CatchResponse::success(Tree::done($this->role->getList($request->param())));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月11日
|
||||
@@ -194,4 +170,4 @@ class Role extends CatchController
|
||||
'hasPermissions' => $permissionIds,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -21,8 +21,8 @@ class Roles extends CatchModel
|
||||
|
||||
public function getList($search = [])
|
||||
{
|
||||
return $this->when($search['name'] ?? false, function ($query) use ($search){
|
||||
$query->whereLike('name', $search['name']);
|
||||
return $this->when($search['role_name'] ?? false, function ($query) use ($search){
|
||||
$query->whereLike('role_name', $search['role_name']);
|
||||
})
|
||||
->when($search['id'] ?? false, function ($query) use ($search){
|
||||
$query->where('parent_id', $search['id'])
|
||||
@@ -104,4 +104,4 @@ class Roles extends CatchModel
|
||||
|
||||
return $this->permissions()->detach($roles);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,11 +1,8 @@
|
||||
<?php
|
||||
// 角色
|
||||
$router->resource('role', '\catchAdmin\permissions\controller\Role');
|
||||
$router->resource('roles', '\catchAdmin\permissions\controller\Role');
|
||||
// 角色列表
|
||||
$router->get('roles', '\catchAdmin\permissions\controller\Role@list');
|
||||
$router->get('/role/get/permissions', '\catchAdmin\permissions\controller\Role@getPermissions');
|
||||
|
||||
// 权限
|
||||
$router->resource('permission', '\catchAdmin\permissions\controller\Permission');
|
||||
// 权限列表
|
||||
$router->get('permissions', '\catchAdmin\permissions\controller\Permission@list');
|
||||
$router->resource('permissions', '\catchAdmin\permissions\controller\Permission');
|
||||
|
Reference in New Issue
Block a user