diff --git a/web/src/components/topup/RechargeCard.jsx b/web/src/components/topup/RechargeCard.jsx index 0a299ffa..ee251a0b 100644 --- a/web/src/components/topup/RechargeCard.jsx +++ b/web/src/components/topup/RechargeCard.jsx @@ -338,7 +338,40 @@ const RechargeCard = ({ )} {(enableOnlineTopUp || enableStripeTopUp) && ( - + + {t('选择充值额度')} + {(() => { + const quotaDisplayType = localStorage.getItem('quota_display_type') || 'USD'; + if (quotaDisplayType === 'USD') return null; + + const statusStr = localStorage.getItem('status'); + let symbol = '¥'; + let rate = 7; + + try { + if (statusStr) { + const s = JSON.parse(statusStr); + if (quotaDisplayType === 'CNY') { + rate = s?.usd_exchange_rate || 7; + symbol = '¥'; + } else if (quotaDisplayType === 'CUSTOM') { + rate = s?.custom_currency_exchange_rate || 1; + symbol = s?.custom_currency_symbol || '¤'; + } + } + } catch (e) {} + + return ( + + (1 $ = {rate.toFixed(2)} {symbol}) + + ); + })()} + + } + >
{presetAmounts.map((preset, index) => { const discount = @@ -351,6 +384,54 @@ const RechargeCard = ({ const actualPay = discountedPrice; const save = originalPrice - discountedPrice; + // 根据当前货币类型换算显示金额和数量 + const quotaDisplayType = localStorage.getItem('quota_display_type') || 'USD'; + let symbol = '¥'; + let displayValue = preset.value; // 显示的数量 + let displayActualPay = actualPay; + let displaySave = save; + + // 获取汇率 + const statusStr = localStorage.getItem('status'); + let usdRate = 7; // 默认汇率 1 USD = 7 CNY + try { + if (statusStr) { + const s = JSON.parse(statusStr); + usdRate = s?.usd_exchange_rate || 7; + } + } catch (e) {} + + if (quotaDisplayType === 'USD') { + symbol = '$'; + // 数量和价格都保持美元(系统默认) + displayValue = preset.value; + displayActualPay = actualPay / usdRate; + displaySave = save / usdRate; + } else if (quotaDisplayType === 'CNY') { + symbol = '¥'; + // 数量需要换算为人民币 + displayValue = preset.value * usdRate; + // 价格已经是人民币,保持不变 + displayActualPay = actualPay; + displaySave = save; + } else if (quotaDisplayType === 'CUSTOM') { + let customSymbol = '¤'; + let customRate = 1; + try { + if (statusStr) { + const s = JSON.parse(statusStr); + customSymbol = s?.custom_currency_symbol || '¤'; + customRate = s?.custom_currency_exchange_rate || 1; + } + } catch (e) {} + symbol = customSymbol; + // 数量从USD转为自定义货币 + displayValue = preset.value * customRate; + // 价格从CNY先转USD再转自定义货币 + displayActualPay = (actualPay / usdRate) * customRate; + displaySave = (save / usdRate) * customRate; + } + return ( - {formatLargeNumber(preset.value)} + {formatLargeNumber(preset.value)} $ {hasDiscount && ( {t('折').includes('off') @@ -398,10 +479,10 @@ const RechargeCard = ({ margin: '4px 0', }} > - {t('实付')} {actualPay.toFixed(2)}, + {t('实付')} {symbol}{displayActualPay.toFixed(2)}, {hasDiscount - ? `${t('节省')} ${save.toFixed(2)}` - : `${t('节省')} 0.00`} + ? `${t('节省')} ${symbol}${displaySave.toFixed(2)}` + : `${t('节省')} ${symbol}0.00`}