优化组别列表显示

pull/515/head
Karson 2025-06-26 21:14:14 +08:00
parent 4b6c209575
commit d6d20c6d53
1 changed files with 14 additions and 11 deletions

View File

@ -3,6 +3,7 @@
namespace app\admin\controller\auth;
use app\admin\model\AuthGroup;
use app\admin\model\AuthGroupAccess;
use app\common\controller\Backend;
use fast\Tree;
use think\Db;
@ -38,22 +39,24 @@ class Group extends Backend
$groupList = collection(AuthGroup::where('id', 'in', $this->childrenGroupIds)->select())->toArray();
Tree::instance()->init($groupList);
$groupList = [];
if ($this->auth->isSuperAdmin()) {
$groupList = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0));
$tree = Tree::instance()->init($groupList);
$groupList = $tree->getTreeList($tree->getTreeArray(0));
} else {
$groups = $this->auth->getGroups();
$groupIds = [];
foreach ($groups as $m => $n) {
if (in_array($n['id'], $groupIds) || in_array($n['pid'], $groupIds)) {
continue;
}
$groupList = array_merge($groupList, Tree::instance()->getTreeList(Tree::instance()->getTreeArray($n['pid'])));
foreach ($groupList as $index => $item) {
$groupIds[] = $item['id'];
$allIds = array_column($groups, 'id');
foreach ($groups as &$item) {
$item['parent_id'] = $item['pid'];
if (!in_array($item['parent_id'], $allIds)) {
$item['parent_id'] = 0;
}
$item['status'] = 'normal';
}
unset($item);
$tree = Tree::instance()->init($groups, 'parent_id');
$groupList = $tree->getTreeList($tree->getTreeArray(0));
}
$groupName = [];
foreach ($groupList as $k => $v) {