/* 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 { Copy as ActionCopy } from '@/components/common/icons/ActionIcons'; import React from 'react'; import { Button, Card, Tag, Tooltip } from 'antd'; import { Lock } from 'lucide-react'; import { getDiscountBadgeText } from '../../../../helpers'; import MarketLogo from './MarketLogo'; /** 计费类型文案:与详情「分组价格」的判定顺序一致 */ export const getBillingLabel = (priceData, t) => { if (priceData?.isPerSecond) return t('按秒计费'); if (priceData?.isPerImageResolution) return t('按分辨率计费'); if (priceData?.isPerToken) return t('按量计费'); return t('按次计费'); }; /** * 把 calculateModelPrice 的结果整理为原型卡片的价格格:主价格(含官方价删除线)与附加价格行。 * 只做展示映射,不重新计算价格。 */ const buildCardPrices = (priceData, t) => { if (priceData.isPerToken) { return { tier: false, main: [ { key: 'input', label: t('输入'), value: priceData.inputPrice, official: priceData.official?.inputPrice, }, { key: 'output', label: t('输出'), value: priceData.completionPrice, official: priceData.official?.completionPrice, }, ], extras: (priceData.extraPrices || []).map((item) => ({ key: item.key, label: t(item.labelKey), value: item.price, })), }; } if (priceData.isPerSecond || priceData.isPerImageResolution) { const tiers = priceData.isPerSecond ? priceData.videoTiers || [] : priceData.imageTiers || []; const unit = priceData.isPerSecond ? t('秒') : t('张'); return { tier: true, main: tiers.length ? tiers.map((tier) => ({ key: tier.key, label: `${tier.label} / ${unit}`, value: tier.price, })) : [{ key: 'none', label: getBillingLabel(priceData, t), value: '-' }], note: getBillingLabel(priceData, t), }; } return { tier: false, main: [ { key: 'price', label: `${t('单价')} / ${t('次')}`, value: priceData.price, official: priceData.official?.price, }, ], note: getBillingLabel(priceData, t), }; }; const trackPointer = (e) => { const rect = e.currentTarget.getBoundingClientRect(); e.currentTarget.style.setProperty( '--pointer-x', `${e.clientX - rect.left}px`, ); e.currentTarget.style.setProperty('--pointer-y', `${e.clientY - rect.top}px`); }; const MarketModelCard = ({ model, priceData, hidePrice, onClick, onCopy, t, }) => { const discountText = getDiscountBadgeText(priceData); const prices = hidePrice ? null : buildCardPrices(priceData, t); const handleKeyDown = (e) => { if (e.target !== e.currentTarget) return; if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); onClick(); } }; return (

{model.model_name}

{model.level_locked && ( } bordered={false}> {t('仅可见')} )}
{prices && ( <>
{prices.main.map((item) => (
{item.label} {item.value} {item.official && {item.official}}
))}
{prices.extras?.map((item) => ( {item.label} {item.value} ))} {prices.note && {prices.note}}
{priceData?.usedGroup ? ( {priceData.usedGroup} ) : ( )} {discountText ? ( {discountText} ) : ( {getBillingLabel(priceData, t)} )}
)}
); }; export default React.memo(MarketModelCard);