Show provider pricing details in usage logs

This commit is contained in:
abingyyds committed 2026-04-12 13:29:44 +08:00
1 parent d6b0d65ce2
commit 2d411cf309
3 files changed
+41 -2

No files matched your search

+5
View File
@@ -204,6 +204,11 @@
"pricing.unknown": "Unknown",
"pricing.vendor": "Vendor",
"pricing.allVendors": "All",
"供应商": "Provider",
"供应商介绍": "Provider introduction",
"供应商定价": "Provider pricing",
"按次计费": "Per call",
"按量计费": "Pay as you go",
"packages.title": "Packages & Plans",
"packages.subtitle": "Choose a package that fits your usage. All plans include access to all available models.",
+5
View File
@@ -204,6 +204,11 @@
"pricing.unknown": "未知",
"pricing.vendor": "厂商",
"pricing.allVendors": "全部",
"供应商": "供应商",
"供应商介绍": "供应商介绍",
"供应商定价": "供应商定价",
"按次计费": "按次计费",
"按量计费": "按量计费",
"packages.title": "套餐方案",
"packages.subtitle": "选择适合您用量的套餐。所有方案均可访问全部可用模型。",
+31 -2
View File
@@ -20,6 +20,24 @@ function getLogOther(otherStr) {
}
}
function formatProviderPriceSnapshot(other, symbol, rate, t) {
if (!other?.provider_billing_mode) return '-';
const formatUSD = (amount) => `${symbol}${(Number(amount || 0) * rate).toFixed(6)}`;
if (other.provider_billing_mode === 'per_call') {
const fixedPrice = Number(other?.provider_fixed_price || 0);
if (fixedPrice <= 0) return t('按次计费');
return `${t('按次计费')} · ${formatUSD(fixedPrice)} / ${t('pricing.perCallUnit')}`;
}
const inputPrice = Number(other?.provider_input_price || 0);
const outputPrice = Number(other?.provider_output_price || 0);
const parts = [t('按量计费')];
if (inputPrice > 0) parts.push(`${t('输入')} ${formatUSD(inputPrice)} / 1M tokens`);
if (outputPrice > 0) parts.push(`${t('输出')} ${formatUSD(outputPrice)} / 1M tokens`);
return parts.join(' · ');
}
export default function Logs() {
const { t } = useTranslation();
const { symbol, rate } = useCurrency();
@@ -55,7 +73,7 @@ export default function Logs() {
setExpandedRows(prev => ({ ...prev, [logId]: !prev[logId] }));
};
const getExpandData = (log) => {
const getExpandData = useCallback((log) => {
const other = getLogOther(log.other);
if (!other) return [];
@@ -92,8 +110,19 @@ export default function Logs() {
data.push({ key: t('计费方式'), value: t('订阅抵扣') });
}
if (other.provider_name) {
data.push({ key: t('供应商'), value: other.provider_name });
data.push({
key: t('供应商定价'),
value: formatProviderPriceSnapshot(other, symbol, rate, t),
});
if (other.provider_description) {
data.push({ key: t('供应商介绍'), value: other.provider_description });
}
}
return data;
};
}, [rate, symbol, t]);
return (
<div className="max-w-6xl mx-auto px-6 py-10">