Move cache discount UI to main site only

This commit is contained in:
abingyyds committed 2026-04-22 12:44:01 +08:00
1 parent 122060661a
commit 2d03e2536f
4 files changed
+2 -56

No files matched your search

-1
View File
@@ -244,7 +244,6 @@
"pricing.cacheCreationPrice": "Cache creation / 1M tokens",
"pricing.cacheCreation5m": "5m",
"pricing.cacheCreation1h": "1h",
"pricing.cacheDiscountShort": "Cache discount",
"pricing.perCall": "Per call",
"pricing.perCallUnit": "call",
"pricing.status": "Status",
-1
View File
@@ -244,7 +244,6 @@
"pricing.cacheCreationPrice": "缓存创建 / 百万 token",
"pricing.cacheCreation5m": "5m",
"pricing.cacheCreation1h": "1h",
"pricing.cacheDiscountShort": "缓存优惠",
"pricing.perCall": "按次计费",
"pricing.perCallUnit": "次",
"pricing.status": "状态",
+1 -22
View File
@@ -3,20 +3,6 @@ import { useTranslation } from 'react-i18next';
import { getSiteModels } from '../api';
import { useCurrency } from '../context/SiteContext';
function formatDiscountRateLabel(value) {
if (value == null || Number.isNaN(Number(value))) return null;
return `${Number(value).toFixed(Number(value) >= 100 ? 0 : 1)}%`;
}
function getModelCacheDiscountBadge(model) {
const readRate = Number(model?.cache_read_discount_rate);
const inputPrice = Number(model?.input_price);
const cacheReadPrice = Number(model?.cache_read_price);
if (!Number.isFinite(readRate) || readRate <= 0) return null;
if (!Number.isFinite(inputPrice) || !Number.isFinite(cacheReadPrice) || !(cacheReadPrice < inputPrice - 1e-12)) return null;
return formatDiscountRateLabel(readRate);
}
export default function Pricing() {
const { t } = useTranslation();
const { symbol, rate } = useCurrency();
@@ -171,14 +157,7 @@ export default function Pricing() {
{filtered.map((m, i) => (
<tr key={m.model_name || i} className="border-b border-page-divider last:border-0 hover:bg-page-surface transition-colors">
<td className="px-5 py-3.5">
<div className="flex items-center gap-2 justify-between">
<span className="font-mono text-page">{m.display_name || m.model_name}</span>
{!m.is_per_call && getModelCacheDiscountBadge(m) && (
<span className="shrink-0 inline-flex items-center rounded-full bg-emerald-500/10 text-emerald-600 px-2 py-0.5 text-[11px] font-medium">
{t('pricing.cacheDiscountShort')} {getModelCacheDiscountBadge(m)}
</span>
)}
</div>
<span className="font-mono text-page">{m.display_name || m.model_name}</span>
</td>
<td className="px-5 py-3.5 text-right font-mono text-page-label">
{m.is_per_call ? t('pricing.perCall') : formatTokenPrice(m.input_price)}
+1 -32
View File
@@ -747,14 +747,7 @@ function GroupPricingModal({
<tr key={`${item.model_name}:${item.billing_type}`} className="border-b border-page-divider last:border-0 align-top">
<td className="px-4 py-3.5">
<div className="min-w-0">
<div className="flex items-center gap-2">
<div className="font-medium text-page">{item.display_name || item.model_name}</div>
{item.billing_type !== 'per_call' && shouldShowGroupDiscountBadge(item) && formatDiscountRateRange(item.cache_read_discount_rate_min, item.cache_read_discount_rate_max) && (
<span className="inline-flex items-center rounded-full bg-emerald-500/10 text-emerald-600 px-2 py-0.5 text-[11px] font-medium">
{t('pricing.cacheDiscountShort')} {formatDiscountRateRange(item.cache_read_discount_rate_min, item.cache_read_discount_rate_max)}
</span>
)}
</div>
<div className="font-medium text-page">{item.display_name || item.model_name}</div>
{(item.display_name || item.model_name) !== item.model_name && (
<div className="text-xs text-page-muted font-mono mt-1">{item.model_name}</div>
)}
@@ -827,30 +820,6 @@ function formatGroupPriceRange(min, max, symbol, rate, perCall, t) {
return `${lowText} - ${highText}${suffix}`;
}
function formatDiscountRateRange(min, max) {
if (min == null && max == null) {
return null;
}
const low = Number(min ?? max ?? 0);
const high = Number(max ?? min ?? 0);
const format = (value) => `${value.toFixed(value >= 100 ? 0 : 1)}%`;
if (Math.abs(low - high) <= 1e-9) {
return format(low);
}
return `${format(low)} - ${format(high)}`;
}
function shouldShowGroupDiscountBadge(item) {
const inputMin = Number(item?.input_price_min);
const inputMax = Number(item?.input_price_max);
const cacheMin = Number(item?.cache_read_price_min);
const cacheMax = Number(item?.cache_read_price_max);
if (!Number.isFinite(inputMin) || !Number.isFinite(inputMax) || !Number.isFinite(cacheMin) || !Number.isFinite(cacheMax)) {
return false;
}
return cacheMin < inputMin - 1e-12 || cacheMax < inputMax - 1e-12;
}
function formatGroupCachePriceRange(item, symbol, rate, t) {
const base = formatGroupPriceRange(
item.cache_creation_price_min,