Files
monkey-ai-web/src/components/analytics/OverviewCards.jsx
T
qiubaishen e3b82b981a merge: 合入总仓库 weiyuan(bfdfb339) web/ 新功能,保留 ui-optimization 的 UI 重构
来源:luoguang/monkey-ai weiyuan@bfdfb339 的 web/(经 sync/main-weiyuan-web-bfdfb339 同步)
同步基准:总仓库 a2ca13cb = 本仓库初始导入 d8f3aee2

冲突处理原则:保留 ui-optimization 的 UI(样式/结构/组件),嫁接 weiyuan 的功能逻辑。
- i18n:按键三方合并;ours 的「令牌→密钥」改名键上移植 theirs 的术语修订
- task-logs / OrgLogs:ours 已手工移植同一功能(6ad95e2),保留 ours
- 删除:OrgCreate(theirs 下线 /org/create)、旧 image 组件与 VideoRegenerateModal(theirs 体验中心重写)、
  OrgAvatarSection / PricingBentoPage / CommissionConsole(ours 重构中已移除)
- 测试:users-pagination 的 i18next mock 补 t();theirs 新增文件补 license header
2026-11-10 12:01:21 +08:00

170 lines
5.2 KiB
React

/*
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 <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
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 (
<div className='grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-4'>
{[...Array(6)].map((_, i) => (
<Card key={i} className='animate-pulse'>
<div className='h-20 bg-gray-200 dark:bg-gray-700 rounded'></div>
</Card>
))}
</div>
);
}
const cards = [
{
title: t('今日活跃'),
value: overview.dau?.toLocaleString() || '0',
change: overview.dau_change,
icon: <Users className='w-5 h-5' />,
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: <UserPlus className='w-5 h-5' />,
color: 'green',
bgColor: 'bg-green-50 dark:bg-green-900/20',
iconBg: 'bg-green-500',
},
{
title: t('今日充值'),
value: `¥${overview.today_topup?.toFixed(2) || '0.00'}`,
change: overview.today_topup_change,
icon: <DollarSign className='w-5 h-5' />,
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: <Zap className='w-5 h-5' />,
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: <Activity className='w-5 h-5' />,
color: 'cyan',
bgColor: 'bg-cyan-50 dark:bg-cyan-900/20',
iconBg: 'bg-cyan-500',
},
{
title: t('付费率'),
value: `${overview.pay_rate?.toFixed(1) || '0.0'}%`,
change: null,
icon: <Percent className='w-5 h-5' />,
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 (
<div
className={`flex items-center gap-1 text-xs font-medium ${
isPositive ? 'text-green-500' : 'text-red-500'
}`}
>
{isPositive ? (
<TrendingUp className='w-3 h-3' />
) : (
<TrendingDown className='w-3 h-3' />
)}
<span>
{isPositive ? '+' : ''}
{change.toFixed(1)}%
</span>
</div>
);
};
return (
<div>
<div
className={`grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-4 transition-opacity ${
loading ? 'opacity-50' : ''
}`}
>
{cards.map((card, index) => (
<Card
key={index}
className={`${card.bgColor} border-none shadow-sm hover:shadow-md transition-shadow`}
bodyStyle={{ padding: '16px' }}
>
<div className='flex items-start justify-between'>
<div className='flex-1'>
<p className='text-xs text-gray-500 dark:text-gray-400 mb-1'>
{card.title}
</p>
<p className='text-xl font-bold text-gray-800 dark:text-gray-100'>
{card.value}
</p>
{renderChange(card.change)}
</div>
<div
className={`${card.iconBg} p-2 rounded-lg text-white shadow-sm`}
>
{card.icon}
</div>
</div>
</Card>
))}
</div>
{/* 活跃/消耗取自汇总层时会落后一个同步周期(约 30~60 秒),把截止时间标出来,
避免「数字和日志对不上」被当成算错;data_as_of 为 0 表示本次是实时直查。 */}
{overview.data_as_of > 0 && (
<p className='mt-2 text-xs text-gray-400 dark:text-gray-500 text-right'>
{t('活跃与消耗数据截至')} {timestamp2string(overview.data_as_of)}
</p>
)}
</div>
);
};
export default OverviewCards;