feat: 参考原型图 ui优化提交 企业端-企业中心 相关的页面

This commit is contained in:
zhanjunhao
2026-11-06 20:19:43 +08:00
parent 43048626a6
commit a075732cb4
147 changed files with 9816 additions and 8768 deletions
+274 -299
View File
@@ -28,17 +28,8 @@ import {
InputNumber,
Select,
} from '@/components/ui';
import {
CreditCard,
Wallet,
TrendingUp,
Coins,
History,
CheckCircle,
Clock,
XCircle,
Pencil,
} from 'lucide-react';
import { Check, CheckCircle, Clock, XCircle } from 'lucide-react';
import { Button as AntButton } from 'antd';
import {
API,
showError,
@@ -48,10 +39,11 @@ import {
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 OrgPanel from './components/OrgPanel';
import '../../styles/org-center.css';
import { orgStatusColor } from './components/orgStatus';
import {
formatPayPalUSD,
@@ -61,7 +53,7 @@ import {
removePayPalReturnState,
} from '../../helpers/paypalPayment';
const { Text, Title } = Typography;
const { Text } = Typography;
const OrgRecharge = ({ orgId }) => {
const { t } = useTranslation();
@@ -85,7 +77,6 @@ const OrgRecharge = ({ orgId }) => {
const [confirmOpen, setConfirmOpen] = useState(false);
const [confirmLoading, setConfirmLoading] = useState(false);
const [amountLoading, setAmountLoading] = useState(false);
const [payPalQuote, setPayPalQuote] = useState(null);
// 自定义充值(与预设档位互斥;自定义金额无折扣,原价到账)
const [isCustomMode, setIsCustomMode] = useState(false);
@@ -108,6 +99,22 @@ const OrgRecharge = ({ orgId }) => {
: 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);
@@ -292,15 +299,7 @@ const OrgRecharge = ({ orgId }) => {
}
setAmountLoading(true);
try {
const response = await API.post(
'/api/org/topup/paypal/amount',
buildPayBody(),
{ headers: orgHeaders },
);
if (!response.data.success) {
throw new Error(response.data.message || t('获取金额失败'));
}
setPayPalQuote(parsePayPalQuote(response));
if (!(await refreshPayPalQuote())) return;
} catch (error) {
showError(error?.message || t('获取金额失败'));
return;
@@ -456,8 +455,8 @@ const OrgRecharge = ({ orgId }) => {
return (
<Tag
color={orgStatusColor(status)}
size='small'
className='flex items-center gap-1'
bordered={false}
className='oc-recharge-status'
>
{s.icon}
{s.text}
@@ -469,341 +468,317 @@ const OrgRecharge = ({ orgId }) => {
{
title: t('订单号'),
dataIndex: 'trade_no',
render: (v) => (
<Text size='small' className='font-mono'>
{v}
</Text>
),
width: 320,
ellipsis: true,
render: (v) => <span className='oc-rc-order-id'>{v}</span>,
},
{
title: t('金额'),
dataIndex: 'money',
render: (v) => <Text size='small'>¥{Number(v).toFixed(2)}</Text>,
width: 90,
width: 140,
render: (v) => `¥${Number(v).toFixed(2)}`,
},
{
title: t('获得额度'),
dataIndex: 'amount',
render: (v) => <Text size='small'>{renderQuota(v)}</Text>,
width: 110,
width: 140,
render: (v) => renderQuota(v),
},
{
title: t('支付方式'),
dataIndex: 'payment_channel',
render: (v) => (
<Text size='small'>
{v === 'paypal_checkout' ? 'PayPal' : v || '-'}
</Text>
),
width: 110,
width: 120,
render: (v) => (v === 'paypal_checkout' ? 'PayPal' : v || '-'),
},
{
title: t('状态'),
dataIndex: 'status',
width: 110,
render: (v) => renderStatus(v),
width: 90,
},
{
title: t('时间'),
dataIndex: 'create_time',
render: (v) => <Text size='small'>{timestamp2string(v)}</Text>,
width: 160,
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 space-y-6'>
<div className='uc-page oc-page oc-recharge'>
<OrgPageHeader title={t('企业充值')} subtitle={t('为企业账户充值额度')} />
{/* 签名时刻:余额展示区(本页唯一的品牌渐变区,渐变走 --brand-* token 随预设切换) */}
<div className='relative overflow-hidden bg-gradient-to-r from-brand-from via-brand-via to-brand-to rounded-xl p-5 shadow-[var(--elevation-md)]'>
<div className='flex items-center justify-between gap-4 flex-wrap'>
<div className='flex items-center gap-3'>
<div className='p-2 bg-white/15 rounded-lg'>
<Wallet size={20} className='text-white' />
<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>
<Text className='!text-white/80 text-xs font-medium block'>
{t('企业可用余额')}
</Text>
<Title heading={4} className='!text-white !mb-0 tabular-nums'>
{renderQuota(orgQuota)}
</Title>
<span>{t('累计消耗')}</span>
<strong>{renderQuota(orgUsedQuota)}</strong>
</div>
</div>
<div className='w-px h-10 bg-white/20 flex-shrink-0' />
<div className='flex items-center gap-3'>
<div className='p-2 bg-white/10 rounded-lg'>
<TrendingUp size={18} className='text-white/80' />
</div>
<div>
<Text className='!text-white/60 text-xs block'>
{t('累计消耗')}
</Text>
<Text className='!text-white font-semibold text-sm tabular-nums'>
{renderQuota(orgUsedQuota)}
</Text>
</div>
<div className='oc-rc-rail-foot'>
<i aria-hidden='true' />
<span>{t('余额用于模型调用')}</span>
</div>
</div>
</div>
</aside>
{/* 充值区域 */}
<OrgPanel icon={Coins} title={t('选择充值档位')}>
{infoLoading ? (
<div className='py-10 flex justify-center'>
<Spin />
</div>
) : presetAmounts.length > 0 ? (
<>
<div className='grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 gap-2.5 mb-4'>
{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>
{/* 充值工作区(原型 .rlc-workspace) */}
<section className='oc-rc-workspace'>
<header className='oc-rc-workspace-head'>
<h2>{t('为下一次调用补充能量')}</h2>
<p>{t('为企业账户补充额度,支持团队持续调用模型。')}</p>
</header>
{/* 自定义充值(与档位互斥;自定义金额无折扣,原价到账) */}
<div
className={`mb-5 rounded-xl border-2 border-dashed transition-all ${
isCustomMode
? 'border-emerald-400 bg-gradient-to-br from-emerald-50/60 to-emerald-50/25 dark:from-emerald-900/15 dark:to-emerald-900/10 dark:border-emerald-600 shadow-sm shadow-emerald-500/5'
: 'border-gray-200 dark:border-neutral-700 hover:border-emerald-300 dark:hover:border-emerald-700'
}`}
>
{/* 头部 */}
<div className='px-4 pt-3.5 pb-2.5 flex items-center justify-between flex-wrap gap-1.5'>
<div className='flex items-center gap-1.5'>
<div className='p-1 rounded-md bg-emerald-100 dark:bg-emerald-900/40'>
<Pencil
size={12}
className='text-emerald-600 dark:text-emerald-400'
{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>
<Text
strong
className='text-gray-800 dark:text-gray-200 text-sm'
<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}
>
{t('自定义充值')}
</Text>
{isCustomMode && (
<Tag color='green' size='small'>
{t('已选')}
</Tag>
{customInvalid
? `${t('当前 ¥')}${customEffectiveAmount.toLocaleString()}${t(',未达到最低 ¥1,000')}`
: `${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>
<Text type='tertiary' size='small'>
{t('原价到账,不参与折扣')}
</Text>
</div>
{/* 输入区 */}
<div className='px-4 pb-3'>
<div className='flex items-center gap-2'>
<InputNumber
value={customAmount}
onChange={handleCustomAmountChange}
min={1}
precision={0}
hideButtons
size='large'
placeholder={t('请输入整数,如 1、5、10')}
className='!flex-1'
style={{ width: '100%' }}
/>
<Select
value={customUnit}
onChange={handleCustomUnitChange}
size='large'
style={{ width: 96 }}
optionList={[
{ label: t('千'), value: 1000 },
{ label: t('万'), value: 10000 },
]}
/>
</div>
{/* 快速选择 */}
<div className='mt-2.5 flex items-center gap-1.5 flex-wrap'>
<Text
type='tertiary'
size='small'
className='!text-xs flex-shrink-0'
>
{t('快速选择:')}
</Text>
{customQuickPicks.map((pick) => {
const active =
isCustomMode &&
Number(customAmount) === pick.amount &&
customUnit === pick.unit;
const label = `${pick.amount}${pick.unit === 1000 ? t('千') : t('万')}`;
return (
<button
key={`${pick.amount}-${pick.unit}`}
type='button'
onClick={() =>
applyCustomQuickPick(pick.amount, pick.unit)
}
className={`px-2.5 py-0.5 rounded-md text-xs font-medium transition-colors border ${
active
? 'bg-emerald-500 text-white border-emerald-500 shadow-sm shadow-emerald-500/20'
: 'bg-white dark:bg-neutral-800 text-gray-600 dark:text-gray-300 border-gray-200 dark:border-neutral-700 hover:border-emerald-300 hover:text-emerald-600 dark:hover:border-emerald-700 dark:hover:text-emerald-400'
}`}
>
{label}
</button>
);
})}
</div>
</div>
{/* 实时预览(仅在金额合法时显示) */}
{customEffectiveAmount > 0 && customValid && (
<div className='mx-4 mb-3 rounded-lg p-3 bg-[var(--surface-card)] border border-[var(--border-subtle)]'>
<div className='flex items-center justify-between gap-3 flex-wrap'>
<div className='flex items-center gap-2'>
<div className='w-7 h-7 rounded-lg bg-rose-500/10 text-rose-600 dark:text-rose-400 flex items-center justify-center'>
<Wallet size={14} />
</div>
<div>
<Text
type='tertiary'
size='small'
className='!text-xs block leading-tight'
>
{t('实付金额')}
</Text>
<Text
strong
className='!text-rose-600 dark:!text-rose-400 text-base leading-tight'
>
¥{customEffectiveAmount.toLocaleString()}
</Text>
</div>
</div>
<div className='flex items-center gap-2'>
<div className='w-7 h-7 rounded-lg bg-amber-500/10 text-amber-600 dark:text-amber-400 flex items-center justify-center'>
<Coins size={14} />
</div>
<div className='text-right'>
<Text
type='tertiary'
size='small'
className='!text-xs block leading-tight'
>
{t('获得额度')}
</Text>
<Text
strong
className='!text-amber-600 dark:!text-amber-400 text-base leading-tight'
>
{renderQuota(customPreviewQuota)}
</Text>
</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>
)}
{/* 底部说明(金额不达标时变橙色) */}
<div className='px-4 pb-3'>
<Text
size='small'
className={`!text-xs ${
customEffectiveAmount > 0 && !customValid
? '!text-amber-600 dark:!text-amber-400'
: '!text-gray-400 dark:!text-gray-500'
}`}
<Button
type='primary'
size='large'
block
disabled={!canCheckout}
loading={amountLoading || quoteLoading}
onClick={() => handlePreTopUp(payWay)}
>
{customEffectiveAmount > 0 && !customValid
? `${t('当前 ¥')}${customEffectiveAmount.toLocaleString()}${t(',未达到最低 ¥1,000')}`
: t('最少 1000 元,必须为 1000 元的整倍数')}
</Text>
</div>
{t('立即充值')}
</Button>
</aside>
</div>
) : (
<p className='oc-rc-pay-empty'>
{t('暂无充值档位,请联系管理员配置')}
</p>
)}
</section>
</div>
{/* 支付方式 */}
<div className='flex items-center gap-2 mb-3'>
<div className='p-1.5 rounded-lg bg-brand/10 text-brand'>
<CreditCard size={14} />
</div>
<Text strong className='text-gray-800 dark:text-gray-200'>
{t('支付方式')}
</Text>
</div>
{hasAnyPayment ? (
<div className='flex flex-wrap gap-3'>
{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);
return (
<Button
key={method.type}
theme={payWay === method.type ? 'solid' : 'light'}
type={payWay === method.type ? 'primary' : 'tertiary'}
disabled={disabled}
loading={amountLoading && payWay === method.type}
onClick={() => handlePreTopUp(method.type)}
className={`!rounded-lg !px-5 !py-2.5 !h-auto transition-colors ${
payWay === method.type
? ''
: 'hover:!bg-brand/5 dark:hover:!bg-brand-deep/20 hover:!border-brand-from'
}`}
>
{method.name}
</Button>
);
})}
</div>
) : (
<Text type='tertiary' size='small'>
{t('暂无可用的支付方式,请联系管理员配置')}
</Text>
)}
</>
) : (
<Text type='tertiary'>{t('暂无充值档位,请联系管理员配置')}</Text>
)}
</OrgPanel>
{/* 充值记录 */}
<OrgPanel
icon={History}
title={t('充值记录')}
bodyClassName='overflow-x-auto'
>
{/* 充值记录(原型 .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: 10,
onPageChange: setHistoryPage,
showTotal: (n) => t('共 {{total}} 条', { total: n }),
}}
size='small'
empty={<Text type='tertiary'>{t('暂无充值记录')}</Text>}
/>
</OrgPanel>
</section>
{/* 支付确认弹窗 */}
<PaymentConfirmModal
@@ -823,7 +798,7 @@ const OrgRecharge = ({ orgId }) => {
const baseQuota = effectiveAmountYuan * quotaPerUnit;
return renderQuota(baseQuota + effectiveBonus);
}}
amountLoading={amountLoading}
amountLoading={amountLoading || quoteLoading}
renderAmount={renderAmount}
payWay={payWay}
payMethods={payMethods}