权限管理
This commit is contained in:
@@ -1 +1,162 @@
|
||||
<?php
|
||||
namespace catchAdmin\permissions\controller;
|
||||
|
||||
|
||||
use app\Request;
|
||||
use catcher\base\CatchController;
|
||||
use catcher\CatchForm;
|
||||
use catcher\CatchResponse;
|
||||
use catcher\exceptions\FailedException;
|
||||
use catcher\Tree;
|
||||
use catchAdmin\permissions\model\Permissions as Permission;
|
||||
|
||||
class Permissions extends CatchController
|
||||
{
|
||||
protected $permissions;
|
||||
|
||||
public function __construct(Permission $permissions)
|
||||
{
|
||||
$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)
|
||||
{
|
||||
return CatchResponse::success(Tree::done($this->permissions->getList($request->param())));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月11日
|
||||
* @throws \Exception
|
||||
* @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->text('route', '路由')->placeholder('请输入路由');
|
||||
$form->radio('method', '请求方法', true)->default(Permission::GET)->options([
|
||||
['value' => Permission::GET, 'title' => 'get'],
|
||||
['value' => Permission::POST, 'title' => 'post'],
|
||||
['value' => Permission::PUT, 'title' => 'put'],
|
||||
['value' => Permission::DELETE, 'title' => 'delete'],
|
||||
]);
|
||||
$form->text('permission_mark', '权限标识', true)->verify('required')->placeholder('请输入权限标识controller:action');
|
||||
$form->radio('type', '类型', true)->default(Permission::BTN_TYPE)->options([
|
||||
['value' => Permission::MENU_TYPE, 'title' => '菜单'],
|
||||
['value' => Permission::BTN_TYPE, 'title' => '按钮'],
|
||||
]);
|
||||
$form->text('sort', '排序')->verify('numberX')->default(1)->placeholder('倒叙排序');
|
||||
$form->formBtn('submitPermission');
|
||||
|
||||
return $this->fetch(['form' => $form->render()]);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月11日
|
||||
* @param Request $request
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function save(Request $request)
|
||||
{
|
||||
return CatchResponse::success($this->permissions->storeBy($request->param()));
|
||||
}
|
||||
|
||||
public function read()
|
||||
{}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月11日
|
||||
* @param $id
|
||||
* @throws \Exception
|
||||
* @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->text('route', '路由')->default($permission->route)->placeholder('请输入路由');
|
||||
$form->radio('method', '请求方法', true)->default($permission->method)->options([
|
||||
['value' => Permission::GET, 'title' => 'get'],
|
||||
['value' => Permission::POST, 'title' => 'post'],
|
||||
['value' => Permission::PUT, 'title' => 'put'],
|
||||
['value' => Permission::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' => Permission::MENU_TYPE, 'title' => '菜单'],
|
||||
['value' => Permission::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,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月11日
|
||||
* @param $id
|
||||
* @param Request $request
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function update($id, Request $request)
|
||||
{
|
||||
return CatchResponse::success($this->permissions->updateBy($id, $request->param()));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月11日
|
||||
* @param $id
|
||||
* @throws FailedException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
if ($this->permissions->where('parent_id', $id)->find()) {
|
||||
throw new FailedException('存在子菜单,无法删除');
|
||||
}
|
||||
|
||||
return CatchResponse::success($this->permissions->deleteBy($id));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@@ -2,11 +2,13 @@
|
||||
namespace catchAdmin\permissions\controller;
|
||||
|
||||
use app\Request;
|
||||
use catcher\base\BaseController;
|
||||
use catcher\base\CatchController;
|
||||
use catcher\CatchForm;
|
||||
use catcher\CatchResponse;
|
||||
use catcher\exceptions\FailedException;
|
||||
use catcher\Tree;
|
||||
|
||||
class Roles extends BaseController
|
||||
class Roles extends CatchController
|
||||
{
|
||||
protected $role;
|
||||
|
||||
@@ -26,54 +28,109 @@ class Roles extends BaseController
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function roles()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月11日
|
||||
* @throws \Exception
|
||||
* @return string
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$form = new CatchForm();
|
||||
$form->formId('roles');
|
||||
$form->text('name', '角色名称');
|
||||
$form->formBtn('submitRoles');
|
||||
$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()
|
||||
]);
|
||||
}
|
||||
|
||||
public function save()
|
||||
{}
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月11日
|
||||
* @param Request $request
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function save(Request $request)
|
||||
{
|
||||
// 添加角色
|
||||
dd($request->param('roleids'));
|
||||
return CatchResponse::success($this->role->storeBy($request->param()));
|
||||
}
|
||||
|
||||
public function read($id)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月11日
|
||||
* @param $id
|
||||
* @throws \Exception
|
||||
* @return string
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$role = $this->role->findBy($id);
|
||||
|
||||
$form = new CatchForm();
|
||||
$form->formId('roles');
|
||||
$form->text('name', '角色名称');
|
||||
$form->formBtn('submitRoles');
|
||||
$form->formId('role');
|
||||
$form->hidden('parent_id')->default($role->parent_id);
|
||||
$form->text('role_name', '角色名称', true)->default($role->name)->verify('required')->placeholder('请输入角色名称');
|
||||
$form->textarea('description', '角色描述')->default($role->description)->placeholder('请输入角色描述');
|
||||
$form->formBtn('submitRole');
|
||||
|
||||
return $this->fetch([
|
||||
'form' => $form->render()
|
||||
'form' => $form->render(),
|
||||
'role_id' => $role->id,
|
||||
]);
|
||||
}
|
||||
|
||||
public function update($id, UpdateRequest $request)
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月11日
|
||||
* @param $id
|
||||
* @param Request $request
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function update($id, Request $request)
|
||||
{
|
||||
return CatchResponse::success($this->role->updateBy($id, $request->param()));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月11日
|
||||
* @param $id
|
||||
* @throws FailedException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
if ($this->role->where('parent_id', $id)->find()) {
|
||||
throw new FailedException('存在子角色,无法删除');
|
||||
}
|
||||
|
||||
// 删除权限
|
||||
return CatchResponse::success($this->role->deleteBy($id));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月11日
|
||||
* @param Request $request
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function list(Request $request)
|
||||
{
|
||||
return CatchResponse::paginate($this->role->getList($request->param()));
|
||||
return CatchResponse::success(Tree::done($this->role->getList($request->param())));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user