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
+75 -27
View File
@@ -17,7 +17,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
import React, { useEffect, useState, useContext } from 'react';
import React, {
useEffect,
useLayoutEffect,
useRef,
useState,
useContext,
} from 'react';
import { useLocation } from 'react-router-dom';
import { Segmented, Tabs } from 'antd';
import { Modal, Toast } from '@/components/ui';
import UserCenterPageHeader from '../../components/common/UserCenterPageHeader';
@@ -35,6 +42,7 @@ import {
import PageBackground from '../../components/common/PageBackground';
import RechargePanel from './RechargePanel';
import usePayPalQuote from '../../hooks/common/usePayPalQuote';
import MembershipPanel from './MembershipPanel';
import HistoryPanel from './HistoryPanel';
import WalletCard from './WalletCard';
@@ -53,6 +61,50 @@ import {
const Recharge = ({ embedded = false }) => {
const { t } = useTranslation();
const { pathname } = useLocation();
const alignStandaloneContent = !embedded && pathname === '/recharge';
const contentRef = useRef(null);
useLayoutEffect(() => {
if (!alignStandaloneContent) return undefined;
const content = contentRef.current;
const topbar = document.querySelector('.ui-topbar');
if (!content || !topbar) return undefined;
const resizeObserver = new ResizeObserver(() => alignContent());
const alignContent = () => {
const label = topbar.querySelector(
'.ui-header-navigation a[href="/market"] > span',
);
if (window.innerWidth > 768 && label?.getClientRects().length) {
const inset = Math.max(
16,
label.getBoundingClientRect().left -
content.getBoundingClientRect().left,
);
content.style.setProperty('--rc-content-inset', `${inset}px`);
} else {
content.style.removeProperty('--rc-content-inset');
}
if (label) resizeObserver.observe(label);
const brand = topbar.querySelector('.ui-header-brand');
if (brand) resizeObserver.observe(brand);
};
// The navigation may finish loading or change language after this page mounts.
const mutationObserver = new MutationObserver(alignContent);
mutationObserver.observe(topbar, { childList: true, subtree: true });
resizeObserver.observe(topbar);
resizeObserver.observe(content);
window.addEventListener('resize', alignContent);
alignContent();
return () => {
resizeObserver.disconnect();
mutationObserver.disconnect();
window.removeEventListener('resize', alignContent);
content.style.removeProperty('--rc-content-inset');
};
}, [alignStandaloneContent]);
const [userState, userDispatch] = useContext(UserContext);
const [statusState] = useContext(StatusContext);
@@ -75,7 +127,6 @@ const Recharge = ({ embedded = false }) => {
const [enableStripeTopUp, setEnableStripeTopUp] = useState(false);
const [enablePayPalTopUp, setEnablePayPalTopUp] = useState(false);
const [payPalMinTopUp, setPayPalMinTopUp] = useState(1);
const [payPalQuote, setPayPalQuote] = useState(null);
const [enableCreemTopUp, setEnableCreemTopUp] = useState(false);
const [creemProducts, setCreemProducts] = useState([]);
const [selectedCreemProduct, setSelectedCreemProduct] = useState(null);
@@ -100,6 +151,19 @@ const Recharge = ({ embedded = false }) => {
const [selectedPreset, setSelectedPreset] = useState(null);
const [selectedPresetObj, setSelectedPresetObj] = useState(null); // 存储完整的预设对象
const {
quote: payPalQuote,
setQuote: setPayPalQuote,
loading: quoteLoading,
refresh: getPayPalAmount,
} = usePayPalQuote(
'/api/user/paypal/amount',
selectedPresetObj?.id !== undefined
? { amount_option_id: selectedPresetObj.id }
: { amount: parseInt(topUpCount) },
payWay === 'paypal' && selectedPreset !== null,
);
// 充值配置信息
const [topupInfo, setTopupInfo] = useState({
amount_options: [],
@@ -200,7 +264,7 @@ const Recharge = ({ embedded = false }) => {
// 如果选择了预设档位,已经在 selectPresetAmount 中计算好了金额(包含折扣和汇率),不需要重新获取
// 只有自定义金额时才需要从后端获取
if (payment === 'paypal') {
await getPayPalAmount();
if (!(await getPayPalAmount())) return;
} else if (!selectedPresetObj) {
if (payment === 'stripe') {
await getStripeAmount();
@@ -634,25 +698,6 @@ const Recharge = ({ embedded = false }) => {
}
};
const getPayPalAmount = async () => {
setAmountLoading(true);
try {
const requestData = selectedPresetObj?.id
? { amount_option_id: selectedPresetObj.id }
: { amount: parseInt(topUpCount) };
const res = await API.post('/api/user/paypal/amount', requestData);
if (!res?.data?.success) {
throw new Error(res?.data?.message || t('获取金额失败'));
}
const quote = parsePayPalQuote(res);
setPayPalQuote(quote);
setAmount(quote.payAmount);
return quote;
} finally {
setAmountLoading(false);
}
};
// 选择预设充值额度
const selectPresetAmount = (preset) => {
setTopUpCount(preset.value);
@@ -681,7 +726,7 @@ const Recharge = ({ embedded = false }) => {
const renderAmount = () => {
if (payWay === 'paypal') {
return formatPayPalUSD(payPalQuote?.payAmount || amount);
return payPalQuote ? formatPayPalUSD(payPalQuote.payAmount) : '-';
}
return amount + ' ' + t('元');
};
@@ -734,7 +779,7 @@ const Recharge = ({ embedded = false }) => {
return (
<div
className={`ui-recharge-page relative w-full min-h-screen pt-[64px] ${embedded ? '' : 'bg-[var(--surface-bg-base)]'}`}
className={`ui-recharge-page ${alignStandaloneContent ? 'rc-standalone' : ''} relative w-full min-h-screen pt-[64px] ${embedded ? '' : 'bg-[var(--surface-bg-base)]'}`}
>
{/* 统一页面背景层 —— 走 bg-glow-* 主题变量。
* embedded(嵌入 UserCenter/topup)时由父 shell 提供背景,此处跳过避免双层叠加;
@@ -754,7 +799,7 @@ const Recharge = ({ embedded = false }) => {
? renderQuota(payPalQuote.quota)
: renderQuotaWithAmount(value)
}
amountLoading={amountLoading}
amountLoading={amountLoading || quoteLoading}
renderAmount={renderAmount}
payWay={payWay}
payMethods={payMethods}
@@ -805,7 +850,10 @@ const Recharge = ({ embedded = false }) => {
/>
{/* 主内容区 */}
<div className='ui-recharge-content uc-page relative z-10 max-w-7xl mx-auto'>
<div
ref={contentRef}
className='ui-recharge-content uc-page relative z-10 max-w-7xl mx-auto'
>
<UserCenterPageHeader
title={t('在线充值')}
subtitle={t('管理账户余额,让每一次模型调用从容开始。')}
@@ -864,7 +912,7 @@ const Recharge = ({ embedded = false }) => {
priceRatio={priceRatio}
topUpCount={topUpCount}
amount={amount}
amountLoading={amountLoading}
amountLoading={amountLoading || quoteLoading}
payMethods={payMethods}
preTopUp={preTopUp}
paymentLoading={paymentLoading}