/* Copyright (C) 2025 QuantumNous This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . For commercial licensing, please contact support@quantumnous.com */ import { formatNumber, formatPercent } from '../../helpers/safeDisplay'; import React from 'react'; import { Card } from '@/components/ui'; import { Users, UserPlus, DollarSign, Zap, Activity, Percent, TrendingUp, TrendingDown, } from 'lucide-react'; import { renderQuota, timestamp2string } from '../../helpers'; const OverviewCards = ({ overview, loading = false, t }) => { if (!overview) { return (
{[...Array(6)].map((_, i) => (
))}
); } const cards = [ { title: t('今日活跃'), value: overview.dau?.toLocaleString() || '0', change: overview.dau_change, icon: , color: 'blue', bgColor: 'bg-blue-50 dark:bg-blue-900/20', iconBg: 'bg-blue-500', }, { title: t('今日新增'), value: overview.new_users?.toLocaleString() || '0', change: overview.new_users_change, icon: , color: 'green', bgColor: 'bg-green-50 dark:bg-green-900/20', iconBg: 'bg-green-500', }, { title: t('今日充值'), value: `¥${formatNumber(overview.today_topup, 2, '0.00')}`, change: overview.today_topup_change, icon: , color: 'yellow', bgColor: 'bg-yellow-50 dark:bg-yellow-900/20', iconBg: 'bg-yellow-500', }, { title: t('今日消耗'), value: renderQuota(overview.today_consume || 0), change: overview.today_consume_change, icon: , color: 'purple', bgColor: 'bg-brand/5 dark:bg-brand-deep/20', iconBg: 'bg-brand', }, { title: t('请求次数'), value: overview.today_requests?.toLocaleString() || '0', change: null, icon: , color: 'cyan', bgColor: 'bg-cyan-50 dark:bg-cyan-900/20', iconBg: 'bg-cyan-500', }, { title: t('付费率'), value: formatPercent(overview.pay_rate, 1, '0.0%'), change: null, icon: , color: 'pink', bgColor: 'bg-pink-50 dark:bg-pink-900/20', iconBg: 'bg-pink-500', }, ]; const renderChange = (change) => { if (change === null || change === undefined || isNaN(change)) return null; const isPositive = change >= 0; return (
{isPositive ? ( ) : ( )} {isPositive ? '+' : ''} {formatPercent(change, 1)}
); }; return (
{cards.map((card, index) => (

{card.title}

{card.value}

{renderChange(card.change)}
{card.icon}
))}
{/* 活跃/消耗取自汇总层时会落后一个同步周期(约 30~60 秒),把截止时间标出来, 避免「数字和日志对不上」被当成算错;data_as_of 为 0 表示本次是实时直查。 */} {overview.data_as_of > 0 && (

{t('活跃与消耗数据截至')} {timestamp2string(overview.data_as_of)}

)}
); }; export default OverviewCards;