157 lines
4.5 KiB
React
157 lines
4.5 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 } from '../../helpers';
|
|
|
|
const OverviewCards = ({ overview, 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 className='grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-4'>
|
|
{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>
|
|
);
|
|
};
|
|
|
|
export default OverviewCards;
|