[name, parent_name, top_name],供数据目录取中文名称和业务分组。 */ public static function menuIndex(): array { if (self::$menus !== null) { return self::$menus; } $rows = SystemMenu::where('is_disable', 0)->field('id,pid,type,name,perms')->select()->toArray(); $byId = array_column($rows, null, 'id'); $index = []; foreach ($rows as $row) { if ((string) $row['perms'] === '') { continue; } $parent = $byId[$row['pid']] ?? null; $top = $parent; $guard = 0; while ($top && !empty($byId[$top['pid']] ?? null) && $guard++ < 10) { $top = $byId[$top['pid']]; } foreach (explode(':', (string) $row['perms']) as $perm) { $key = self::normalize($perm); if ($key === '' || isset($index[$key])) { continue; } $index[$key] = [ 'name' => (string) $row['name'], 'type' => (string) $row['type'], 'parent' => $parent ? (string) $parent['name'] : '', 'top' => $top ? (string) $top['name'] : '', ]; } } return self::$menus = $index; } /** 测试用:清空本请求内的缓存 */ public static function reset(): void { self::$enabled = null; self::$adminPerms = []; self::$menus = null; } }