/* 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 React, { useState, useRef, useEffect } from 'react'; import { Card, Tag, Tooltip, Checkbox, Empty, Pagination, Button, Skeleton } from '@douyinfe/semi-ui'; import { IconHelpCircle, IconCopy } from '@douyinfe/semi-icons'; import { IllustrationNoResult, IllustrationNoResultDark } from '@douyinfe/semi-illustrations'; import { stringToColor, getModelCategories, calculateModelPrice, formatPriceInfo } from '../../../../helpers'; const PricingCardView = ({ filteredModels, loading, rowSelection, pageSize, setPageSize, currentPage, setCurrentPage, selectedGroup, groupRatio, copyText, setModalImageUrl, setIsModalOpenurl, currency, tokenUnit, setTokenUnit, displayPrice, showRatio, t }) => { const [showSkeleton, setShowSkeleton] = useState(loading); const [skeletonCount] = useState(10); const loadingStartRef = useRef(Date.now()); useEffect(() => { if (loading) { loadingStartRef.current = Date.now(); setShowSkeleton(true); } else { const elapsed = Date.now() - loadingStartRef.current; const remaining = Math.max(0, 1000 - elapsed); if (remaining === 0) { setShowSkeleton(false); } else { const timer = setTimeout(() => setShowSkeleton(false), remaining); return () => clearTimeout(timer); } } }, [loading]); // 计算当前页面要显示的数据 const startIndex = (currentPage - 1) * pageSize; const endIndex = startIndex + pageSize; const paginatedModels = filteredModels.slice(startIndex, endIndex); // 渲染骨架屏卡片 const renderSkeletonCards = () => { const placeholder = (
{Array.from({ length: skeletonCount }).map((_, index) => ( {/* 头部:图标 + 模型名称 + 操作按钮 */}
{/* 模型图标骨架 */}
{/* 模型名称骨架 */}
{/* 操作按钮骨架 */} {rowSelection && ( )}
{/* 价格信息骨架 */}
{/* 模型描述骨架 */}
{/* 标签区域骨架 */}
{Array.from({ length: 3 + (index % 2) }).map((_, tagIndex) => ( ))}
{/* 倍率信息骨架(可选) */} {showRatio && (
{Array.from({ length: 3 }).map((_, ratioIndex) => ( ))}
)}
))}
{/* 分页骨架 */}
); return ( ); }; // 获取模型图标 const getModelIcon = (modelName) => { const categories = getModelCategories(t); let icon = null; // 遍历分类,找到匹配的模型图标 for (const [key, category] of Object.entries(categories)) { if (key !== 'all' && category.filter({ model_name: modelName })) { icon = category.icon; break; } } // 如果找到了匹配的图标,返回包装后的图标 if (icon) { return (
{React.cloneElement(icon, { size: 32 })}
); } // 默认图标(如果没有匹配到任何分类) return (
{/* 默认的螺旋图案 */}
); }; // 获取模型描述 const getModelDescription = (modelName) => { // 根据模型名称返回描述,这里可以扩展 if (modelName.includes('gpt-3.5-turbo')) { return t('该模型目前指向gpt-35-turbo-0125模型,综合能力强,过去使用最广泛的文本模型。'); } if (modelName.includes('gpt-4')) { return t('更强大的GPT-4模型,具有更好的推理能力和更准确的输出。'); } if (modelName.includes('claude')) { return t('Anthropic开发的Claude模型,以安全性和有用性著称。'); } return t('高性能AI模型,适用于各种文本生成和理解任务。'); }; // 渲染价格信息 const renderPriceInfo = (record) => { const priceData = calculateModelPrice({ record, selectedGroup, groupRatio, tokenUnit, displayPrice, currency, precision: 4 }); return formatPriceInfo(priceData, t); }; // 渲染标签 const renderTags = (record) => { const tags = []; // 计费类型标签 if (record.quota_type === 1) { tags.push( {t('按次计费')} ); } else { tags.push( {t('按量计费')} ); } // 热度标签(示例) if (record.model_name.includes('gpt-3.5-turbo') || record.model_name.includes('gpt-4')) { tags.push( {t('热')} ); } // 端点类型标签 if (record.supported_endpoint_types && record.supported_endpoint_types.length > 0) { record.supported_endpoint_types.slice(0, 2).forEach((endpoint, index) => { tags.push( {endpoint} ); }); } // 上下文长度标签(示例) if (record.model_name.includes('16k')) { tags.push(16K); } else if (record.model_name.includes('32k')) { tags.push(32K); } else { tags.push(4K); } return tags; }; // 显示骨架屏 if (showSkeleton) { return renderSkeletonCards(); } if (!filteredModels || filteredModels.length === 0) { return (
} darkModeImage={} description={t('搜索无结果')} />
); } return (
{paginatedModels.map((model, index) => { const isSelected = rowSelection?.selectedRowKeys?.includes(model.id); return ( {/* 头部:图标 + 模型名称 + 操作按钮 */}
{getModelIcon(model.model_name)}

{model.model_name}

{/* 复制按钮 */}
{/* 价格信息 */}
{renderPriceInfo(model)}
{/* 模型描述 */}

{getModelDescription(model.model_name)}

{/* 标签区域 */}
{renderTags(model)}
{/* 倍率信息(可选) */} {showRatio && (
{t('倍率信息')} { setModalImageUrl('/ratio.png'); setIsModalOpenurl(true); }} />
{t('模型')}: {model.quota_type === 0 ? model.model_ratio : t('无')}
{t('补全')}: {model.quota_type === 0 ? parseFloat(model.completion_ratio.toFixed(3)) : t('无')}
{t('分组')}: {groupRatio[selectedGroup]}
)}
); })}
{/* 分页 */} {filteredModels.length > 0 && (
setCurrentPage(page)} onPageSizeChange={(size) => { setPageSize(size); setCurrentPage(1); }} />
)}
); }; export default PricingCardView;