修改权限返回数据结构
This commit is contained in:
parent
9ddc932e89
commit
6da68f09cd
@ -22,12 +22,29 @@ class Permission extends CatchController
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @time 2019年12月11日
|
* @time 2019年12月11日
|
||||||
* @param Request $request
|
|
||||||
* @return Json
|
* @return Json
|
||||||
|
* @throws \think\db\exception\DbException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
*/
|
*/
|
||||||
public function index(): Json
|
public function index(): Json
|
||||||
{
|
{
|
||||||
return CatchResponse::success(Tree::done($this->permissions->getList()));
|
// 获取菜单类型
|
||||||
|
$menuList = $this->permissions->getList(true);
|
||||||
|
|
||||||
|
// 获取按钮类型并且重新排列
|
||||||
|
$buttonList = [];
|
||||||
|
$this->permissions
|
||||||
|
->whereIn('parent_id', array_unique($menuList->column('id')))
|
||||||
|
->where('type', Permissions::BTN_TYPE)
|
||||||
|
->select()->each(function ($item) use (&$buttonList){
|
||||||
|
$buttonList[$item['parent_id']][] = $item->toArray();
|
||||||
|
});
|
||||||
|
|
||||||
|
// 返回树结构
|
||||||
|
return CatchResponse::success(Tree::done($menuList->each(function (&$item) use ($buttonList){
|
||||||
|
$item['actionList'] = $buttonList[$item['id']] ?? [];
|
||||||
|
})->toArray()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -39,13 +39,15 @@ class Permissions extends CatchModel
|
|||||||
public const PUT = 'put';
|
public const PUT = 'put';
|
||||||
public const DELETE = 'delete';
|
public const DELETE = 'delete';
|
||||||
|
|
||||||
public function getList()
|
public function getList($isMenu = false)
|
||||||
{
|
{
|
||||||
return $this->catchSearch()
|
return $this->catchSearch()
|
||||||
->order('sort', 'desc')
|
->order('sort', 'desc')
|
||||||
->order('id', 'desc')
|
->order('id', 'desc')
|
||||||
->select()
|
->when($isMenu, function ($query){
|
||||||
->toArray();
|
$query->where('type', self::MENU_TYPE);
|
||||||
|
})
|
||||||
|
->select();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function roles(): \think\model\relation\BelongsToMany
|
public function roles(): \think\model\relation\BelongsToMany
|
||||||
|
Loading…
x
Reference in New Issue
Block a user