diff --git a/server/local-auth.mjs b/server/local-auth.mjs index 1818b27..c5508c9 100644 --- a/server/local-auth.mjs +++ b/server/local-auth.mjs @@ -229,9 +229,26 @@ export function createLocalUserAuth(pool) { async function getAdminSummary() { const [[row]] = await pool.execute( - `SELECT COUNT(*) AS total, SUM(CASE WHEN balance_cents < 0 THEN 1 ELSE 0 END) AS lowBalance FROM auth_users`, + `SELECT + COUNT(*) AS total, + SUM(CASE WHEN status = 'active' THEN 1 ELSE 0 END) AS active, + SUM(CASE WHEN balance_cents < 0 THEN 1 ELSE 0 END) AS lowBalance, + SUM(balance_cents) AS totalBalanceCents + FROM auth_users`, ); - return { users: { total: Number(row.total ?? 0), lowBalance: Number(row.lowBalance ?? 0) }, routes: { total: 0, active: 0 } }; + return { + users: { + total: Number(row.total ?? 0), + active: Number(row.active ?? 0), + lowBalance: Number(row.lowBalance ?? 0), + totalBalanceCents: Number(row.totalBalanceCents ?? 0), + }, + usage24h: { count: 0, costCents: 0 }, + lowBalanceUsers: [], + recentUsage: [], + recentLedger: [], + llm: { keyCount: 0, selectedKeyName: null, globalModel: null }, + }; } return { diff --git a/src/admin/pages/DashboardPage.tsx b/src/admin/pages/DashboardPage.tsx index 5bd46c7..14fbd94 100644 --- a/src/admin/pages/DashboardPage.tsx +++ b/src/admin/pages/DashboardPage.tsx @@ -5,10 +5,10 @@ import type { AdminDashboardSummary } from '../../types'; import { formatTime, formatYuan } from '../utils/format'; const QUICK_LINKS = [ - { to: '/admin/users', label: '用户管理', desc: '创建账号、启用禁用' }, - { to: '/admin/billing/recharge', label: '充值', desc: '为用户账户充值' }, - { to: '/admin/providers', label: 'LLM Provider', desc: '模型 Key 与全局配置' }, - { to: '/admin/capabilities', label: '能力权限', desc: '扩展与工具开关' }, + { to: '/users', label: '用户管理', desc: '创建账号、启用禁用' }, + { to: '/billing/recharge', label: '充值', desc: '为用户账户充值' }, + { to: '/providers', label: 'LLM Provider', desc: '模型 Key 与全局配置' }, + { to: '/capabilities', label: '能力权限', desc: '扩展与工具开关' }, ] as const; export function DashboardPage() { @@ -32,6 +32,15 @@ export function DashboardPage() { void load(); }, [load]); + const safeSummary: AdminDashboardSummary = summary ?? { + users: { total: 0, active: 0, lowBalance: 0, totalBalanceCents: 0 }, + usage24h: { count: 0, costCents: 0 }, + lowBalanceUsers: [], + recentUsage: [], + recentLedger: [], + llm: null, + }; + return (