feat : section

This commit is contained in:
2024-11-07 16:17:57 +08:00
parent 7fd07c55d8
commit b6b2627129
11 changed files with 531 additions and 3 deletions

View File

@@ -0,0 +1,27 @@
<?php
namespace App\Service\ServiceTrait\Admin;
trait SectionTrait
{
/**
* 递归生成合适的数据
* @param array $allMenuList
* @param int $parentId
* @return array
*/
protected function getDbList(array $allMenuList, int $parentId = 0): array
{
$menuList = [];
foreach ($allMenuList as $menu) {
if ($menu['pid'] == $parentId) {
$children = $this->getDbList($allMenuList, (int)$menu['id']);
if (!empty($children)) {
$menu['children'] = $children;
}
$menuList[] = $menu;
}
}
return $menuList;
}
}