Files
monkey-ai-web/src/pages/Organization/OrgRecharge.jsx
T
qiubaishen 61294dc597 merge: 合入总仓库 weiyuan(bfdfb339) web/ 新功能,保留 ui-optimization 的 UI 重构
来源:luoguang/monkey-ai weiyuan@bfdfb339 的 web/(经 sync/main-weiyuan-web-bfdfb339 同步)
同步基准:总仓库 a2ca13cb = 本仓库初始导入 d8f3aee2

冲突处理原则:保留 ui-optimization 的 UI(样式/结构/组件),嫁接 weiyuan 的功能逻辑。
- i18n:按键三方合并;ours 的「令牌→密钥」改名键上移植 theirs 的术语修订
- task-logs / OrgLogs:ours 已手工移植同一功能(6ad95e2),保留 ours
- 删除:OrgCreate(theirs 下线 /org/create)、旧 image 组件与 VideoRegenerateModal(theirs 体验中心重写)、
  OrgAvatarSection / PricingBentoPage / CommissionConsole(ours 重构中已移除)
- 测试:users-pagination 的 i18next mock 补 t();theirs 新增文件补 license header
2026-11-10 12:01:21 +08:00

843 lines
29 KiB
React
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
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 <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
import React, { useEffect, useState, useCallback, useMemo } from 'react';
import { timestamp2string } from '../../helpers/utils';
import { useTranslation } from 'react-i18next';
import {
Typography,
Button,
Spin,
Table,
Tag,
InputNumber,
Select,
} from '@/components/ui';
import { Check, CheckCircle, Clock, XCircle } from 'lucide-react';
import { Button as AntButton } from 'antd';
import {
API,
showError,
showInfo,
showSuccess,
renderQuota,
getQuotaPerUnit,
} from '../../helpers';
import AmountCard from '../Recharge/AmountCard';
import usePayPalQuote from '../../hooks/common/usePayPalQuote';
import WechatQRModal from '../../components/topup/modals/WechatQRModal';
import PaymentConfirmModal from '../../components/topup/modals/PaymentConfirmModal';
import OrgPageHeader from './components/OrgPageHeader';
import '../../styles/org-center.css';
import { orgStatusColor } from './components/orgStatus';
import {
formatPayPalUSD,
getPayPalReturnState,
parsePayPalQuote,
requestPayPalOrder,
removePayPalReturnState,
} from '../../helpers/paypalPayment';
const { Text } = Typography;
const OrgRecharge = ({ orgId }) => {
const { t } = useTranslation();
// 企业信息
const [orgQuota, setOrgQuota] = useState(0);
const [orgUsedQuota, setOrgUsedQuota] = useState(0);
// 充值配置
const [presetAmounts, setPresetAmounts] = useState([]);
const [payMethods, setPayMethods] = useState([]);
const [enableWechatTopUp, setEnableWechatTopUp] = useState(false);
const [enableAlipayTopUp, setEnableAlipayTopUp] = useState(false);
const [enablePayPalTopUp, setEnablePayPalTopUp] = useState(false);
const [infoLoading, setInfoLoading] = useState(true);
// 充值交互状态
const [selectedPreset, setSelectedPreset] = useState(null);
const [selectedPresetObj, setSelectedPresetObj] = useState(null);
const [payWay, setPayWay] = useState('');
const [confirmOpen, setConfirmOpen] = useState(false);
const [confirmLoading, setConfirmLoading] = useState(false);
const [amountLoading, setAmountLoading] = useState(false);
// 自定义充值(与预设档位互斥;自定义金额无折扣,原价到账)
const [isCustomMode, setIsCustomMode] = useState(false);
const [customAmount, setCustomAmount] = useState(null);
const [customUnit, setCustomUnit] = useState(1000); // 1000=千 / 10000=万
const customEffectiveAmount = useMemo(() => {
if (!customAmount || customAmount < 1) return 0;
return Math.floor(Number(customAmount)) * customUnit;
}, [customAmount, customUnit]);
const customValid = customEffectiveAmount >= 1000;
// 当前生效的金额/折扣/赠送(自定义优先)
const effectiveAmountYuan = isCustomMode
? customEffectiveAmount
: selectedPresetObj?.value || 0;
const effectiveDiscount = isCustomMode
? 1.0
: selectedPresetObj?.discount || 1.0;
const effectiveBonus = isCustomMode ? 0 : selectedPresetObj?.bonus || 0;
const {
quote: payPalQuote,
setQuote: setPayPalQuote,
loading: quoteLoading,
refresh: refreshPayPalQuote,
} = usePayPalQuote(
'/api/org/topup/paypal/amount',
isCustomMode
? { custom_amount: customEffectiveAmount }
: { amount_option_id: selectedPresetObj?.id },
payWay === 'paypal' &&
effectiveAmountYuan > 0 &&
(!isCustomMode || customValid),
orgId,
);
// 微信二维码
const [wechatQRVisible, setWechatQRVisible] = useState(false);
const [wechatOrderData, setWechatOrderData] = useState(null);
// 充值记录
const [history, setHistory] = useState([]);
const [historyTotal, setHistoryTotal] = useState(0);
const [historyPage, setHistoryPage] = useState(1);
const [historyPageSize, setHistoryPageSize] = useState(10);
const [historyLoading, setHistoryLoading] = useState(false);
const [refreshHistory, setRefreshHistory] = useState(0);
const orgHeaders = { 'X-Org-Id': String(orgId) };
// 获取企业配额
const fetchOrgQuota = useCallback(async () => {
try {
const res = await API.get('/api/org/quota', { headers: orgHeaders });
if (res.data.success) {
const { quota, used_quota } = res.data.data;
setOrgQuota(quota || 0);
setOrgUsedQuota(used_quota || 0);
}
} catch (e) {
// ignore
}
}, [orgId]);
// 获取充值配置
const fetchTopUpInfo = useCallback(async () => {
setInfoLoading(true);
try {
const res = await API.get('/api/org/topup/info', { headers: orgHeaders });
if (res.data.success) {
const data = res.data.data;
setEnableWechatTopUp(data.enable_wechat_topup || false);
setEnableAlipayTopUp(data.enable_alipay_topup || false);
setEnablePayPalTopUp(data.enable_paypal_topup || false);
setPayMethods(data.pay_methods || []);
if (data.amount_options_v2 && data.amount_options_v2.length > 0) {
const sorted = [...data.amount_options_v2].sort(
(a, b) => (a.sort || 0) - (b.sort || 0),
);
setPresetAmounts(
sorted.map((opt) => ({
id: opt.id,
value: opt.amount,
discount: opt.discount || 1.0,
label: opt.label,
badge: opt.badge,
badgeColor: opt.badge_color,
isRecommend: opt.is_recommend,
isHot: opt.is_hot,
bonus: opt.bonus,
minVipLevel: opt.min_vip_level,
})),
);
}
}
} catch (e) {
showError(t('获取充值配置失败'));
} finally {
setInfoLoading(false);
}
}, [orgId]);
// 获取充值记录
const fetchHistory = useCallback(
async (page = 1) => {
setHistoryLoading(true);
try {
const res = await API.get(
`/api/org/topup?p=${page}&page_size=${historyPageSize}`,
{
headers: orgHeaders,
},
);
if (res.data.success) {
const data = res.data.data;
setHistory(data.items || []);
setHistoryTotal(data.total || 0);
} else {
showError(res.data.message);
}
} catch (e) {
showError(e.message);
} finally {
setHistoryLoading(false);
}
},
[orgId, historyPageSize],
);
useEffect(() => {
fetchOrgQuota();
fetchTopUpInfo();
}, [fetchOrgQuota, fetchTopUpInfo]);
useEffect(() => {
fetchHistory(historyPage);
}, [fetchHistory, historyPage, refreshHistory]);
useEffect(() => {
const result = getPayPalReturnState(window.location.search);
if (!result) return;
if (result.status === 'success') showSuccess(t('PayPal 充值成功'));
else if (result.status === 'pending')
showInfo(t('PayPal 支付处理中,请稍后查看充值记录'));
else if (result.status === 'cancelled') showInfo(t('已取消 PayPal 支付'));
else showError(t('PayPal 支付确认失败,请稍后重试'));
fetchOrgQuota();
setRefreshHistory((previous) => previous + 1);
window.history.replaceState(
{},
'',
removePayPalReturnState(window.location.href),
);
// The callback query must be consumed exactly once on page entry.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
const selectPreset = (preset) => {
setSelectedPreset(preset.id);
setSelectedPresetObj(preset);
setIsCustomMode(false);
setCustomAmount(null);
};
const handleCustomAmountChange = (v) => {
setCustomAmount(v);
if (v && Number(v) > 0) {
setIsCustomMode(true);
setSelectedPreset(null);
setSelectedPresetObj(null);
} else {
setIsCustomMode(false);
}
};
const handleCustomUnitChange = (v) => {
setCustomUnit(v);
if (customAmount && Number(customAmount) > 0) {
setIsCustomMode(true);
setSelectedPreset(null);
setSelectedPresetObj(null);
}
};
// 自定义充值快速选择档位
const customQuickPicks = [
{ amount: 1, unit: 1000 },
{ amount: 5, unit: 1000 },
{ amount: 1, unit: 10000 },
{ amount: 5, unit: 10000 },
{ amount: 10, unit: 10000 },
];
const applyCustomQuickPick = (amount, unit) => {
setCustomAmount(amount);
setCustomUnit(unit);
setIsCustomMode(true);
setSelectedPreset(null);
setSelectedPresetObj(null);
};
// 自定义充值预览额度(与后端 service.CalculateQuota 一致:originalMoney * QuotaPerUnit + bonus,自定义 bonus=0)
const customPreviewQuota =
customEffectiveAmount > 0
? customEffectiveAmount * (getQuotaPerUnit() || 500000)
: 0;
const handlePreTopUp = async (paymentType) => {
if (isCustomMode) {
if (!customValid) {
showError(t('自定义充值金额最少为 1000 元'));
return;
}
} else if (!selectedPresetObj) {
showError(t('请先选择充值金额'));
return;
}
setPayWay(paymentType);
if (paymentType === 'paypal') {
if (!enablePayPalTopUp) {
showError(t('管理员未开启 PayPal 充值!'));
return;
}
setAmountLoading(true);
try {
if (!(await refreshPayPalQuote())) return;
} catch (error) {
showError(error?.message || t('获取金额失败'));
return;
} finally {
setAmountLoading(false);
}
}
setConfirmOpen(true);
};
const buildPayBody = () =>
isCustomMode
? { custom_amount: customEffectiveAmount }
: { amount_option_id: selectedPresetObj.id };
const isMobile = /iPhone|Android|iPad|Mobile/i.test(navigator.userAgent);
const handleConfirmPay = async () => {
if (!isCustomMode && !selectedPresetObj) return;
if (isCustomMode && !customValid) return;
setConfirmLoading(true);
try {
let res;
const payBody = buildPayBody();
if (payWay === 'wxpay' && enableWechatTopUp) {
const wechatEndpoint = isMobile
? '/api/org/topup/wechat/h5'
: '/api/org/topup/wechat/native';
res = await API.post(wechatEndpoint, payBody, { headers: orgHeaders });
if (res.data.success) {
if (isMobile) {
// H5:直接跳转微信支付页
window.location.href = res.data.data.h5_url;
setConfirmOpen(false);
const onFocus = () => {
fetchOrgQuota();
setRefreshHistory((p) => p + 1);
window.removeEventListener('focus', onFocus);
};
window.addEventListener('focus', onFocus);
} else {
// Native:弹出二维码
setWechatOrderData(res.data.data);
setConfirmOpen(false);
setWechatQRVisible(true);
}
return;
}
} else if (payWay === 'paypal' && enablePayPalTopUp) {
res = await requestPayPalOrder(
API,
'/api/org/topup/paypal',
{ ...payBody, quote_token: payPalQuote?.quoteToken },
{ headers: orgHeaders, skipErrorHandler: true },
);
if (res.data.success && res.data.data?.approval_url) {
setPayPalQuote(parsePayPalQuote(res));
window.location.href = res.data.data.approval_url;
return;
}
if (
res.status === 202 &&
res.data?.message === 'PAYPAL_ORDER_CREATING'
) {
showInfo(t('PayPal 订单创建中,请稍后重试'));
return;
}
} else if (payWay === 'alipay' && enableAlipayTopUp) {
const alipayEndpoint = isMobile
? '/api/org/topup/alipay/wap'
: '/api/org/topup/alipay/pc';
res = await API.post(alipayEndpoint, payBody, { headers: orgHeaders });
if (res.data.success) {
// Safari 会拦截 await 之后的 window.open(用户手势已过期),改为同标签跳转
const isSafari =
navigator.userAgent.indexOf('Safari') > -1 &&
navigator.userAgent.indexOf('Chrome') < 1;
if (isSafari) {
window.location.href = res.data.data.pay_url;
return;
}
window.open(res.data.data.pay_url, '_blank');
setConfirmOpen(false);
// 用户从支付宝标签页切回时自动刷新余额和记录
const onFocus = () => {
fetchOrgQuota();
setRefreshHistory((p) => p + 1);
window.removeEventListener('focus', onFocus);
};
window.addEventListener('focus', onFocus);
return;
}
}
// 失败处理
const msg = res?.data?.message || t('支付请求失败');
showError(msg);
} catch (e) {
const code = e?.response?.data?.message;
if (payWay === 'paypal' && code?.startsWith('PAYPAL_QUOTE_')) {
try {
const response = await API.post(
'/api/org/topup/paypal/amount',
buildPayBody(),
{ headers: orgHeaders },
);
if (!response.data.success) throw new Error(response.data.message);
setPayPalQuote(parsePayPalQuote(response));
showInfo(t('PayPal 报价已更新,请重新确认'));
} catch {
showError(t('获取金额失败'));
}
} else {
showError(e?.response?.data?.message || t('支付请求失败'));
}
} finally {
setConfirmLoading(false);
}
};
const handleWechatComplete = (success) => {
setWechatQRVisible(false);
setWechatOrderData(null);
if (success) {
showSuccess(t('充值成功!'));
fetchOrgQuota();
setRefreshHistory((p) => p + 1);
}
};
const renderAmount = () => {
if (payWay === 'paypal') {
return formatPayPalUSD(payPalQuote?.payAmount);
}
if (effectiveAmountYuan <= 0) return '';
const pay = effectiveAmountYuan * effectiveDiscount;
return `${pay.toFixed(2)} ${t('元')}`;
};
// 充值记录状态渲染
const renderStatus = (status) => {
const map = {
success: {
icon: <CheckCircle size={12} />,
text: t('成功'),
},
pending: {
icon: <Clock size={12} />,
text: t('待支付'),
},
expired: { icon: <XCircle size={12} />, text: t('已过期') },
};
const s = map[status] || { icon: null, text: status };
return (
<Tag
color={orgStatusColor(status)}
bordered={false}
className='oc-recharge-status'
>
{s.icon}
{s.text}
</Tag>
);
};
const historyColumns = [
{
title: t('订单号'),
dataIndex: 'trade_no',
width: 320,
ellipsis: true,
render: (v) => <span className='oc-rc-order-id'>{v}</span>,
},
{
title: t('金额'),
dataIndex: 'money',
width: 140,
render: (v) => `¥${Number(v).toFixed(2)}`,
},
{
title: t('获得额度'),
dataIndex: 'amount',
width: 140,
render: (v) => renderQuota(v),
},
{
title: t('支付方式'),
dataIndex: 'payment_channel',
width: 120,
render: (v) => (v === 'paypal_checkout' ? 'PayPal' : v || '-'),
},
{
title: t('状态'),
dataIndex: 'status',
width: 110,
render: (v) => renderStatus(v),
},
{
title: t('时间'),
dataIndex: 'create_time',
width: 190,
render: (v) => timestamp2string(v),
},
];
const hasAnyPayment =
enableWechatTopUp || enableAlipayTopUp || enablePayPalTopUp;
// 充值订单卡(原型 .rp-checkout):展示当前选择的到账额度 / 支付方式 / 应付金额;
// “立即充值”与点击支付方式相同,进入原有 handlePreTopUp 预充值校验与确认弹窗
const selectedMethod = payMethods.find((m) => m.type === payWay);
const quotaPerUnit = getQuotaPerUnit() || 500000;
// 到账额度:自定义沿用原实时预览 customPreviewQuota;档位与确认弹窗 renderQuotaWithAmount 同口径
const arrivalQuota =
effectiveAmountYuan <= 0
? '-'
: isCustomMode
? renderQuota(customPreviewQuota)
: renderQuota(effectiveAmountYuan * quotaPerUnit + effectiveBonus);
const payableYuan = effectiveAmountYuan * effectiveDiscount;
const payableValue =
payWay === 'paypal' ? payPalQuote?.payAmount : payableYuan;
const canCheckout =
effectiveAmountYuan > 0 &&
(!isCustomMode || customValid) &&
Boolean(selectedMethod) &&
!amountLoading &&
!quoteLoading &&
(payWay !== 'paypal' || Boolean(payPalQuote));
const customInvalid = customEffectiveAmount > 0 && !customValid;
const renderPayIcon = (type) =>
type === 'wxpay' ? (
<i className='oc-pay-dot' aria-hidden='true' />
) : type === 'paypal' ? (
<strong className='oc-pay-pal' aria-hidden='true'>
P
</strong>
) : null;
return (
<div className='uc-page oc-page oc-recharge'>
<OrgPageHeader title={t('企业充值')} subtitle={t('为企业账户充值额度')} />
<div className='oc-rc-layout'>
{/* 企业钱包(原型 .rlc-account-rail) */}
<aside className='oc-rc-rail'>
<h2>{t('企业钱包')}</h2>
<div className='oc-rc-rule' />
<div className='oc-rc-account'>
<div>
<span>{t('企业可用余额')}</span>
<strong className='oc-rc-balance'>{renderQuota(orgQuota)}</strong>
</div>
<div>
<span>{t('累计消耗')}</span>
<strong>{renderQuota(orgUsedQuota)}</strong>
</div>
</div>
<div className='oc-rc-rail-foot'>
<i aria-hidden='true' />
<span>{t('余额用于模型调用')}</span>
</div>
</aside>
{/* 充值工作区(原型 .rlc-workspace) */}
<section className='oc-rc-workspace'>
<header className='oc-rc-workspace-head'>
<h2>{t('为下一次调用补充能量')}</h2>
<p>{t('为企业账户补充额度,支持团队持续调用模型。')}</p>
</header>
{infoLoading ? (
<div className='oc-rc-loading'>
<Spin />
</div>
) : presetAmounts.length > 0 ? (
<div className='oc-rc-purchase'>
<div className='oc-rc-content'>
<div className='oc-rc-section-heading'>
<h3>{t('选择充值额度')}</h3>
<p>{t('为企业账户充值,额度用于团队模型调用。')}</p>
</div>
<div className='oc-rc-amount-grid'>
{presetAmounts.map((preset, idx) => (
<AmountCard
key={idx}
preset={preset}
selected={selectedPreset === preset.id}
onClick={() => selectPreset(preset)}
topupInfo={{ amount_options: [], discount: {} }}
priceRatio={1}
t={t}
/>
))}
</div>
{/* 自定义充值(与档位互斥;自定义金额无折扣,原价到账) */}
<div
className={`oc-rc-custom${isCustomMode ? ' selected' : ''}`}
>
<h3>
{t('自定义充值')}
{isCustomMode && (
<Tag color='green' bordered={false}>
{t('已选')}
</Tag>
)}
</h3>
<div className='oc-rc-custom-input'>
<InputNumber
value={customAmount}
onChange={handleCustomAmountChange}
min={1}
precision={0}
hideButtons
placeholder={t('请输入整数,如 1、5、10')}
status={customInvalid ? 'error' : undefined}
style={{ width: '100%' }}
/>
<Select
value={customUnit}
onChange={handleCustomUnitChange}
optionList={[
{ label: t('千'), value: 1000 },
{ label: t('万'), value: 10000 },
]}
/>
</div>
<div className='oc-rc-quick'>
<span>{t('快速选择:')}</span>
{customQuickPicks.map((pick) => {
const active =
isCustomMode &&
Number(customAmount) === pick.amount &&
customUnit === pick.unit;
return (
<AntButton
key={`${pick.amount}-${pick.unit}`}
size='small'
aria-pressed={active}
className={active ? 'is-active' : ''}
onClick={() =>
applyCustomQuickPick(pick.amount, pick.unit)
}
>
{`${pick.amount}${pick.unit === 1000 ? t('千') : t('万')}`}
</AntButton>
);
})}
</div>
{/* 底部说明(金额不达标时变为错误提示) */}
<p
className={customInvalid ? 'oc-rc-error' : ''}
role={customInvalid ? 'alert' : undefined}
>
{customInvalid
? t('当前 ¥{{amount}},未达到最低 ¥1,000', {
amount: customEffectiveAmount.toLocaleString(),
})
: `${t('最少 1000 元,必须为 1000 元的整倍数')};${t('原价到账,不参与折扣')}`}
</p>
</div>
{/* 支付方式(点击沿用 handlePreTopUp:校验后进入确认弹窗) */}
<div className='oc-rc-pay'>
<h3>{t('支付方式')}</h3>
{hasAnyPayment ? (
<div className='oc-rc-pay-methods'>
{payMethods.map((method) => {
const isWechat = method.type === 'wxpay';
const isAlipay = method.type === 'alipay';
const isPayPal = method.type === 'paypal';
const disabled =
(isWechat && !enableWechatTopUp) ||
(isAlipay && !enableAlipayTopUp) ||
(isPayPal && !enablePayPalTopUp);
const selected = payWay === method.type;
return (
<AntButton
key={method.type}
disabled={disabled}
loading={amountLoading && selected}
aria-pressed={selected}
icon={renderPayIcon(method.type)}
className={`oc-rc-pay-method${selected ? ' is-selected' : ''}`}
onClick={() => handlePreTopUp(method.type)}
>
{method.name}
{selected && <Check size={14} />}
</AntButton>
);
})}
</div>
) : (
<p className='oc-rc-pay-empty'>
{t('暂无可用的支付方式,请联系管理员配置')}
</p>
)}
</div>
</div>
{/* 企业充值订单(原型 .rlc-checkout-card) */}
<aside className='oc-rc-checkout'>
<h3>{t('企业充值订单')}</h3>
<dl>
<div>
<dt>{t('到账额度')}</dt>
<dd>{arrivalQuota}</dd>
</div>
<div>
<dt>{t('优惠金额')}</dt>
<dd>¥{(effectiveAmountYuan - payableYuan).toFixed(2)}</dd>
</div>
<div>
<dt>{t('支付方式')}</dt>
<dd>{selectedMethod?.name || '-'}</dd>
</div>
{payWay === 'paypal' && payPalQuote && (
<div>
<dt>{t('支付服务费')}</dt>
<dd>{formatPayPalUSD(payPalQuote.serviceFee)}</dd>
</div>
)}
</dl>
<div className='oc-rc-payable'>
<span>{t('应付金额')}</span>
<strong>
{payableValue > 0 ? (
<>
<span>{payWay === 'paypal' ? '$' : '¥'}</span>
<b>
{payableValue.toLocaleString('en-US', {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
})}
</b>
{payWay === 'paypal' && <span> USD</span>}
</>
) : (
'-'
)}
</strong>
</div>
<Button
type='primary'
size='large'
block
disabled={!canCheckout}
loading={amountLoading || quoteLoading}
onClick={() => handlePreTopUp(payWay)}
>
{t('立即充值')}
</Button>
</aside>
</div>
) : (
<p className='oc-rc-pay-empty'>
{t('暂无充值档位,请联系管理员配置')}
</p>
)}
</section>
</div>
{/* 充值记录(原型 .rlc-history) */}
<section className='oc-rc-history' aria-label={t('充值记录')}>
<Table
rowKey={(record) => record.id ?? record.trade_no}
columns={historyColumns}
dataSource={history}
loading={historyLoading}
scroll={{ x: 900 }}
pagination={{
currentPage: historyPage,
total: historyTotal,
pageSize: historyPageSize,
onPageChange: setHistoryPage,
onPageSizeChange: (size) => {
setHistoryPage(1);
setHistoryPageSize(size);
},
showTotal: (n) => t('共 {{total}} 条', { total: n }),
}}
empty={<Text type='tertiary'>{t('暂无充值记录')}</Text>}
/>
</section>
{/* 支付确认弹窗 */}
<PaymentConfirmModal
t={t}
open={confirmOpen}
onlineTopUp={handleConfirmPay}
handleCancel={() => setConfirmOpen(false)}
confirmLoading={confirmLoading}
topUpCount={effectiveAmountYuan}
renderQuotaWithAmount={() => {
if (payWay === 'paypal' && payPalQuote?.quota) {
return renderQuota(payPalQuote.quota);
}
if (effectiveAmountYuan <= 0) return renderQuota(0);
// 额度 = 原始金额 × QuotaPerUnit + 赠送额度(与后端 CalculateQuota 逻辑一致,折扣只影响实付金额,不影响获得的额度)
const quotaPerUnit = getQuotaPerUnit() || 500000;
const baseQuota = effectiveAmountYuan * quotaPerUnit;
return renderQuota(baseQuota + effectiveBonus);
}}
amountLoading={amountLoading || quoteLoading}
renderAmount={renderAmount}
payWay={payWay}
payMethods={payMethods}
amountNumber={
payWay === 'paypal' ? 0 : effectiveAmountYuan * effectiveDiscount
}
discountRate={payWay === 'paypal' ? 1 : effectiveDiscount}
payPalQuote={payPalQuote}
/>
{/* 微信二维码弹窗 */}
<WechatQRModal
visible={wechatQRVisible}
onClose={handleWechatComplete}
orderData={wechatOrderData}
pollFn={async (tradeNo) => {
const res = await API.get(
`/api/org/topup?p=1&page_size=1&keyword=${tradeNo}`,
{ headers: orgHeaders },
);
const items = res.data.data?.items || [];
return items.length > 0 ? items[0] : null;
}}
/>
</div>
);
};
export default OrgRecharge;