|
|
@@ -49,20 +49,20 @@ class MenuService
|
|
|
{
|
|
|
/** @var Collection $authorities */
|
|
|
if (!$authorities)$authorities = app("AuthorityService")->getUserAuthority();
|
|
|
- $authMap = [];
|
|
|
- foreach ($authorities as $authority){
|
|
|
- $item = $authority->toArray();
|
|
|
- $item["child"] = [];
|
|
|
- $authMap[$authority->id] = $item;
|
|
|
- }
|
|
|
- foreach ($authorities as $authority){
|
|
|
- if ($authority->id_parent){
|
|
|
- if (isset($authMap[$authority->id_parent]))$authMap[$authority->id_parent]["child"][] = $authMap[$authority->id];
|
|
|
- else $authMap = $this->formatAuthority($authMap,$authMap[$authority->id]);
|
|
|
- unset($authMap[$authority->id]);
|
|
|
- }
|
|
|
- }
|
|
|
- $menus = $this->getMenu();
|
|
|
+ $authMap = app("AuthorityService")->format($authorities);
|
|
|
+ $menus = $this->format($this->getMenu());
|
|
|
+ return array_values($this->formatMenu($menus,$authMap,$mapping));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 格式化为树状结构
|
|
|
+ *
|
|
|
+ * @param Collection $menus
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function format($menus)
|
|
|
+ {
|
|
|
$menuMap = [];
|
|
|
foreach ($menus as $menu){
|
|
|
$menuMap[$menu->id] = [
|
|
|
@@ -80,37 +80,8 @@ class MenuService
|
|
|
unset($menuMap[$menu->id]);
|
|
|
}
|
|
|
}
|
|
|
- return array_values($this->formatMenu($menuMap,$authMap,$mapping));
|
|
|
+ return $menuMap;
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * 递归格式化权限组
|
|
|
- *
|
|
|
- * @param array $authMap
|
|
|
- * @param array $authorities
|
|
|
- *
|
|
|
- * @return array|bool
|
|
|
- */
|
|
|
- private function formatAuthority(array $authMap,array $authorities)
|
|
|
- {
|
|
|
- foreach ($authMap as $index=>$data){
|
|
|
- if ($data["id"]==$authorities["id_parent"]){
|
|
|
- $authMap[$index]["child"][] = $authorities;
|
|
|
- unset($authMap[$authorities["id"]]);
|
|
|
- return $authMap;
|
|
|
- }else{
|
|
|
- if ($authMap[$index]["child"]){
|
|
|
- $re = $this->formatAuthority($authMap[$index]["child"],$authorities);
|
|
|
- if ($re){
|
|
|
- $authMap[$index]["child"] = $re;
|
|
|
- return $authMap;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 递归格式化菜单组
|
|
|
*
|