delete:删除冗余
This commit is contained in:
parent
0bbb39696b
commit
6630058508
@ -176,33 +176,7 @@ class Permission extends CatchController
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$this->permissions->show($id);
|
||||
|
||||
return CatchResponse::success();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2020年06月05日
|
||||
* @param $id
|
||||
* @param ParseClass $parseClass
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @return Json
|
||||
*/
|
||||
public function getMethods($id, ParseClass $parseClass)
|
||||
{
|
||||
$permission = Permissions::where('id', $id)->find();
|
||||
$module = $permission->module;
|
||||
$controller = explode('@', $permission->permission_mark)[0];
|
||||
|
||||
try {
|
||||
$methods = $parseClass->setModule('catch')->setRule($module, $controller)->onlySelfMethods();
|
||||
return CatchResponse::success($methods);
|
||||
}catch (\Exception $e) {
|
||||
return CatchResponse::success([]);
|
||||
}
|
||||
return CatchResponse::success($this->permissions->show($id));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
<?php
|
||||
namespace catchAdmin\permissions\controller;
|
||||
|
||||
use catchAdmin\permissions\model\Permissions;
|
||||
use catchAdmin\permissions\model\Roles;
|
||||
use catcher\base\CatchRequest as Request;
|
||||
use catcher\base\CatchController;
|
||||
@ -156,37 +155,4 @@ class Role extends CatchController
|
||||
|
||||
return CatchResponse::success();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月11日
|
||||
* @param Request $request
|
||||
* @param \catchAdmin\permissions\model\Permissions $permission
|
||||
* @return Json
|
||||
*/
|
||||
public function getPermissions(Request $request, \catchAdmin\permissions\model\Permissions $permission): Json
|
||||
{
|
||||
$parentRoleHasPermissionIds = [];
|
||||
if ($request->param('parent_id')) {
|
||||
$this->role->findBy($request->param('parent_id'))
|
||||
->getPermissions()
|
||||
->each(function ($permission) use (&$parentRoleHasPermissionIds){
|
||||
$parentRoleHasPermissionIds[] = $permission->pivot->permission_id;
|
||||
});
|
||||
}
|
||||
|
||||
$permissionIds = [];
|
||||
if ($request->param('role_id')) {
|
||||
$this->role->findBy($request->param('role_id'))
|
||||
->getPermissions()
|
||||
->each(function ($permission) use (&$roleHasPermissions){
|
||||
$permissionIds[] = $permission->pivot->permission_id;
|
||||
});
|
||||
}
|
||||
|
||||
return CatchResponse::success([
|
||||
'permissions' => Permissions::whereIn('id', $parentRoleHasPermissionIds)->select()->toTree(),
|
||||
'hasPermissions' => $permissionIds,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -171,51 +171,6 @@ class User extends CatchController
|
||||
return CatchResponse::success([], '操作成功');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月07日
|
||||
* @param $id
|
||||
* @return \think\response\Json
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
*/
|
||||
public function recover($id): \think\response\Json
|
||||
{
|
||||
$trashedUser = $this->user->findBy($id, ['*'], true);
|
||||
|
||||
if ($this->user->where('email', $trashedUser->email)->find()) {
|
||||
return CatchResponse::fail(sprintf('该恢复用户的邮箱 [%s] 已被占用', $trashedUser->email));
|
||||
}
|
||||
|
||||
return CatchResponse::success($this->user->recover($id));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月11日
|
||||
* @param Request $request
|
||||
* @param Roles $roles
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function getRoles(Request $request, Roles $roles): \think\response\Json
|
||||
{
|
||||
$roles = Tree::done($roles->getList());
|
||||
|
||||
$roleIds = [];
|
||||
if ($request->param('uid')) {
|
||||
$userHasRoles = $this->user->findBy($request->param('uid'))->getRoles();
|
||||
foreach ($userHasRoles as $role) {
|
||||
$roleIds[] = $role->pivot->role_id;
|
||||
}
|
||||
}
|
||||
|
||||
return CatchResponse::success([
|
||||
'roles' => $roles,
|
||||
'hasRoles' => $roleIds,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出
|
||||
*
|
||||
|
@ -5,13 +5,9 @@
|
||||
$router->group(function () use ($router){
|
||||
// 角色
|
||||
$router->resource('roles', '\catchAdmin\permissions\controller\Role');
|
||||
// 角色列表
|
||||
$router->get('/role/get/permissions', '\catchAdmin\permissions\controller\Role@getPermissions');
|
||||
// 权限
|
||||
$router->resource('permissions', '\catchAdmin\permissions\controller\Permission');
|
||||
$router->put('permissions/show/<id>', '\catchAdmin\permissions\controller\Permission@show');
|
||||
$router->get('controller/methods/<id>', '\catchAdmin\permissions\controller\Permission@getMethods');
|
||||
|
||||
// 部门
|
||||
$router->resource('departments', '\catchAdmin\permissions\controller\Department');
|
||||
// 所有职位
|
||||
@ -22,9 +18,7 @@ $router->group(function () use ($router){
|
||||
$router->resource('users', '\catchAdmin\permissions\controller\User');
|
||||
// 切换状态
|
||||
$router->put('users/switch/status/<id>', '\catchAdmin\permissions\controller\User@switchStatus');
|
||||
$router->put('users/recover/<id>', '\catchAdmin\permissions\controller\User@recover');
|
||||
$router->put('user/profile', '\catchAdmin\permissions\controller\User@profile');
|
||||
$router->get('users/get/roles', '\catchAdmin\permissions\controller\User@getRoles');
|
||||
$router->get('user/info', '\catchAdmin\permissions\controller\User@info');
|
||||
$router->get('user/export', '\catchAdmin\permissions\controller\User@export');
|
||||
})->middleware('auth');
|
@ -25,8 +25,8 @@ class Department extends CatchTable
|
||||
HeaderItem::label('状态')->prop('status')->withSwitchComponent(),
|
||||
HeaderItem::label('创建时间')->prop('created_at'),
|
||||
HeaderItem::label('操作')->width(260)->actions([
|
||||
Actions::update(''),
|
||||
Actions::delete(''),
|
||||
Actions::update(),
|
||||
Actions::delete(),
|
||||
])
|
||||
])->withApiRoute('departments')->withActions([
|
||||
Actions::create()
|
||||
|
@ -20,8 +20,8 @@ class Job extends CatchTable
|
||||
HeaderItem::label('状态')->prop('status')->withSwitchComponent(),
|
||||
HeaderItem::label('创建时间')->prop('created_at'),
|
||||
HeaderItem::label('操作')->width(250)->actions([
|
||||
Actions::update(''),
|
||||
Actions::delete('')
|
||||
Actions::update(),
|
||||
Actions::delete()
|
||||
])
|
||||
])
|
||||
->withActions([
|
||||
|
@ -20,8 +20,8 @@ class Permission extends CatchTable
|
||||
HeaderItem::label('状态')->prop('hidden')->component('status'),
|
||||
HeaderItem::label('创建时间')->prop('created_at'),
|
||||
HeaderItem::label('操作')->width(250)->actions([
|
||||
Actions::update(''),
|
||||
Actions::delete('')
|
||||
Actions::update(),
|
||||
Actions::delete()
|
||||
])
|
||||
])
|
||||
->withActions([
|
||||
|
@ -20,7 +20,7 @@ class Role extends CatchTable
|
||||
HeaderItem::label('角色描述')->prop('description'),
|
||||
HeaderItem::label('创建时间')->prop('created_at'),
|
||||
HeaderItem::label('操作')->width(250)->actions([
|
||||
Actions::update(''), Actions::delete('')
|
||||
Actions::update(), Actions::delete()
|
||||
])
|
||||
])
|
||||
->withSearch([
|
||||
|
@ -20,8 +20,8 @@ class User extends CatchTable
|
||||
HeaderItem::label('邮箱')->prop('email'),
|
||||
HeaderItem::label('状态')->prop('status')->component('status', 'status'),
|
||||
HeaderItem::label('创建时间')->prop('created_at'),
|
||||
HeaderItem::label('操作')->width(150)->actions([
|
||||
Actions::update(''), Actions::delete('')
|
||||
HeaderItem::label('操作')->width(200)->actions([
|
||||
Actions::update(), Actions::delete()
|
||||
])
|
||||
])
|
||||
->withSearch([
|
||||
@ -31,8 +31,11 @@ class User extends CatchTable
|
||||
])
|
||||
->withApiRoute('users')
|
||||
->withActions([
|
||||
Actions::create()
|
||||
Actions::create(),
|
||||
Actions::export(),
|
||||
Actions::import()
|
||||
])
|
||||
->withExportRoute('user/export')
|
||||
->withFilterParams([
|
||||
'username' => '',
|
||||
'email' => '',
|
||||
|
Loading…
x
Reference in New Issue
Block a user