diff --git a/packages/webui/src/components/pages/overview-page.tsx b/packages/webui/src/components/pages/overview-page.tsx index 033b365e..023af6a0 100644 --- a/packages/webui/src/components/pages/overview-page.tsx +++ b/packages/webui/src/components/pages/overview-page.tsx @@ -511,6 +511,23 @@ function StatTileWidget({ id }: { id: string }) { const HOST_GRID_COLS: Record = { 1: 'lg:grid-cols-1', 2: 'lg:grid-cols-2', 3: 'lg:grid-cols-3' }; +function bestGrid(n: number, maxCols = 48): { cols: number; rows: number; waste: number } { + let best = { cols: 2, rows: Math.ceil(n / 2), waste: 0 }; + let bestScore = Infinity; + const limit = Math.min(maxCols, n); + for (let cols = 2; cols <= limit; cols++) { + const rows = Math.ceil(n / cols); + const waste = cols * rows - n; + const balance = Math.abs(cols - rows); + const score = waste * 20 + balance; + if (score < bestScore) { + bestScore = score; + best = { cols, rows, waste }; + } + } + return best; +} + function HostBlock({ config }: { config: HostConfig }) { const { systemInfo, refreshSystem } = useAppState(); const panelCount = [config.cpu, config.memory, config.runtime].filter(Boolean).length; @@ -547,13 +564,32 @@ function HostBlock({ config }: { config: HostConfig }) { 负载: {systemInfo ? systemInfo.cpu.loadAvg.map((v) => v.toFixed(2)).join(' / ') : '—'}

{systemInfo && systemInfo.cpu.perCore.length > 0 && ( -
- {systemInfo.cpu.perCore.map((p, i) => ( -
-
+ (() => { + const n = systemInfo.cpu.perCore.length; + const { cols, rows } = bestGrid(n); + const total = cols * rows; + return ( +
+ {systemInfo.cpu.perCore.map((p, i) => ( +
+
+
+ ))} + {Array.from({ length: total - n }).map((_, i) => ( +
+ ))}
- ))} -
+ ); + })() )}
)}