fix(*): 全量 UI 审查与 undefined 展示异常修复

This commit is contained in:
zhanjunhao
2026-11-20 10:18:17 +08:00
parent 04cc45bbb7
commit 605cff1d58
65 changed files with 507 additions and 274 deletions
+28 -29
View File
@@ -56,6 +56,7 @@ import { Lock, Bot as FastGPT, Image as Jimeng } from 'lucide-react';
import { Modal, Tag, Typography } from '@/components/ui';
import { copy, getCurrencySymbol, showSuccess } from './utils';
import { visit } from 'unist-util-visit';
import { toFiniteNumber } from './safeDisplay';
// Full Avatar/Text/Combine variants are loaded only when configured icons render.
const LobeHubIcon = lazy(() => import('../components/common/LobeHubIcon'));
@@ -783,35 +784,30 @@ export function renderNumber(num) {
}
export function getQuotaPerUnit() {
let quotaPerUnit = localStorage.getItem('quota_per_unit');
quotaPerUnit = parseFloat(quotaPerUnit);
return quotaPerUnit;
const quotaPerUnit = toFiniteNumber(localStorage.getItem('quota_per_unit'));
return quotaPerUnit !== null && quotaPerUnit > 0 ? quotaPerUnit : 500000;
}
export function renderUnitWithQuota(quota) {
let quotaPerUnit = localStorage.getItem('quota_per_unit');
quotaPerUnit = parseFloat(quotaPerUnit);
quota = parseFloat(quota);
return quotaPerUnit * quota;
return getQuotaPerUnit() * (toFiniteNumber(quota) ?? 0);
}
export function getQuotaWithUnit(quota, digits = 6) {
let quotaPerUnit = localStorage.getItem('quota_per_unit');
quotaPerUnit = parseFloat(quotaPerUnit);
return (quota / quotaPerUnit).toFixed(digits);
return ((toFiniteNumber(quota) ?? 0) / getQuotaPerUnit()).toFixed(digits);
}
export function renderQuotaWithAmount(amount) {
const normalizedAmount = toFiniteNumber(amount) ?? 0;
const quotaDisplayType = localStorage.getItem('quota_display_type') || 'USD';
if (quotaDisplayType === 'TOKENS') {
return renderNumber(renderUnitWithQuota(amount));
return renderNumber(renderUnitWithQuota(normalizedAmount));
}
if (quotaDisplayType === 'CNY') {
return getCurrencySymbol('CNY') + amount;
return getCurrencySymbol('CNY') + normalizedAmount;
} else if (quotaDisplayType === 'CUSTOM') {
return getCurrencySymbol('CUSTOM') + amount;
return getCurrencySymbol('CUSTOM') + normalizedAmount;
}
return getCurrencySymbol('USD') + amount;
return getCurrencySymbol('USD') + normalizedAmount;
}
/**
@@ -830,11 +826,8 @@ export function getCurrencyConfig() {
try {
if (statusStr) {
const s = JSON.parse(statusStr);
// 注意:如果设置了汇率值(包括1),使用设置值;只有未设置(undefined/null)时才用默认值1
rate =
s?.usd_exchange_rate !== undefined && s?.usd_exchange_rate !== null
? s.usd_exchange_rate
: 1;
const parsedRate = toFiniteNumber(s?.usd_exchange_rate);
rate = parsedRate !== null && parsedRate > 0 ? parsedRate : 1;
}
} catch (e) {}
} else if (quotaDisplayType === 'CUSTOM') {
@@ -842,7 +835,8 @@ export function getCurrencyConfig() {
if (statusStr) {
const s = JSON.parse(statusStr);
symbol = getCurrencySymbol('CUSTOM', s?.custom_currency_symbol);
rate = s?.custom_currency_exchange_rate || 1;
const parsedRate = toFiniteNumber(s?.custom_currency_exchange_rate);
rate = parsedRate !== null && parsedRate > 0 ? parsedRate : 1;
}
} catch (e) {
symbol = getCurrencySymbol('CUSTOM');
@@ -860,18 +854,18 @@ export function getCurrencyConfig() {
*/
export function convertUSDToCurrency(usdAmount, digits = 2) {
const { symbol, rate } = getCurrencyConfig();
const convertedAmount = usdAmount * rate;
const convertedAmount = (toFiniteNumber(usdAmount) ?? 0) * rate;
return symbol + convertedAmount.toFixed(digits);
}
export function renderQuota(quota, digits = 2) {
let quotaPerUnit = localStorage.getItem('quota_per_unit');
const normalizedQuota = toFiniteNumber(quota) ?? 0;
const quotaDisplayType = localStorage.getItem('quota_display_type') || 'USD';
quotaPerUnit = parseFloat(quotaPerUnit);
const quotaPerUnit = getQuotaPerUnit();
if (quotaDisplayType === 'TOKENS') {
return renderNumber(quota);
return renderNumber(normalizedQuota);
}
const resultUSD = quota / quotaPerUnit;
const resultUSD = normalizedQuota / quotaPerUnit;
let symbol = getCurrencySymbol('USD');
let value = resultUSD;
if (quotaDisplayType === 'CNY') {
@@ -880,7 +874,8 @@ export function renderQuota(quota, digits = 2) {
try {
if (statusStr) {
const s = JSON.parse(statusStr);
usdRate = s?.usd_exchange_rate || 1;
const parsedRate = toFiniteNumber(s?.usd_exchange_rate);
usdRate = parsedRate !== null && parsedRate > 0 ? parsedRate : 1;
}
} catch (e) {}
value = resultUSD * usdRate;
@@ -893,14 +888,15 @@ export function renderQuota(quota, digits = 2) {
if (statusStr) {
const s = JSON.parse(statusStr);
symbolCustom = getCurrencySymbol('CUSTOM', s?.custom_currency_symbol);
rate = s?.custom_currency_exchange_rate || rate;
const parsedRate = toFiniteNumber(s?.custom_currency_exchange_rate);
rate = parsedRate !== null && parsedRate > 0 ? parsedRate : 1;
}
} catch (e) {}
value = resultUSD * rate;
symbol = symbolCustom;
}
const fixedResult = value.toFixed(digits);
if (parseFloat(fixedResult) === 0 && quota > 0 && value > 0) {
if (parseFloat(fixedResult) === 0 && normalizedQuota > 0 && value > 0) {
const minValue = Math.pow(10, -digits);
return symbol + minValue.toFixed(digits);
}
@@ -947,7 +943,10 @@ export function renderExportQuota(quota, digits = 6) {
if (!Number.isFinite(quotaPerUnit) || quotaPerUnit <= 0) {
quotaPerUnit = 500000;
}
return getCurrencySymbol() + (quota / quotaPerUnit).toFixed(digits);
return (
getCurrencySymbol() +
((toFiniteNumber(quota) ?? 0) / quotaPerUnit).toFixed(digits)
);
}
function isValidGroupRatio(ratio) {