feat : role
This commit is contained in:
49
app/Service/ServiceTrait/AdminRoleMenuTrait.php
Normal file
49
app/Service/ServiceTrait/AdminRoleMenuTrait.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\ServiceTrait;
|
||||
|
||||
use App\Constants\Admin\AuthCode;
|
||||
|
||||
trait AdminRoleMenuTrait
|
||||
{
|
||||
|
||||
/**
|
||||
* 递归生成合适的数据
|
||||
* @param array $allMenuList
|
||||
* @param int $parentId
|
||||
* @return array
|
||||
*/
|
||||
protected function getDbMenu(array $allMenuList, int $parentId = 0): array
|
||||
{
|
||||
$menuList = [];
|
||||
foreach ($allMenuList as $menu) {
|
||||
if ($menu['parent_id'] == $parentId) {
|
||||
$children = $this->getDbMenu($allMenuList, (int)$menu['id']);
|
||||
if (!empty($children)) {
|
||||
//获取第一个 type 如何是菜单
|
||||
if ($children[0]['type'] == AuthCode::MENU_TYPE_LIST) {
|
||||
$menu['children'] = $children;
|
||||
} else {
|
||||
foreach ($children as $child) {
|
||||
$menu['permissionList'][] = [
|
||||
'id' => $child['id'],
|
||||
'label' => $child['title'],
|
||||
'value' => $child['value'],
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
$menuList[] = $menu;
|
||||
}
|
||||
}
|
||||
return $menuList;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user