feat: 参考原型图 ui优化提交 企业端-企业中心 相关的页面
This commit is contained in:
@@ -27,6 +27,8 @@ import {
|
||||
PayPalBrandIcon,
|
||||
} from '../../components/common/icons/BrandIcons';
|
||||
import { getCurrencyConfig } from '../../helpers/render';
|
||||
import { CUSTOMER_SERVICE_OPEN_EVENT } from '../../components/customer-service';
|
||||
import { showInfo } from '../../helpers';
|
||||
import AmountCard from './AmountCard';
|
||||
import { useMinimumLoadingTime } from '../../hooks/common/useMinimumLoadingTime';
|
||||
|
||||
@@ -40,7 +42,17 @@ const formatCny = (value) =>
|
||||
export const InvoiceNote = ({ t }) => (
|
||||
<p className='rc-invoice'>
|
||||
{t('需要发票?')}
|
||||
<span>{t('联系在线客服')}</span>
|
||||
<button
|
||||
type='button'
|
||||
onClick={() => {
|
||||
const handled = !window.dispatchEvent(
|
||||
new CustomEvent(CUSTOMER_SERVICE_OPEN_EVENT, { cancelable: true }),
|
||||
);
|
||||
if (!handled) showInfo(t('暂无可用客服'));
|
||||
}}
|
||||
>
|
||||
{t('联系在线客服')}
|
||||
</button>
|
||||
</p>
|
||||
);
|
||||
|
||||
@@ -146,7 +158,8 @@ const RechargePanel = ({
|
||||
Boolean(preset) &&
|
||||
Boolean(selectedMethod) &&
|
||||
!isMethodDisabled(selectedMethod) &&
|
||||
Boolean(payable);
|
||||
Boolean(payable) &&
|
||||
!amountLoading;
|
||||
|
||||
if (statusLoading) {
|
||||
return (
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -43,6 +43,17 @@
|
||||
--rc-empty-bg: #f7f9fb;
|
||||
--rc-empty-border: #e3e9f0;
|
||||
}
|
||||
.ui-recharge-page.rc-standalone .ui-recharge-content {
|
||||
max-width: none;
|
||||
margin-inline: 0;
|
||||
padding-inline: var(--rc-content-inset, var(--uc-page-pad-x, 36px));
|
||||
}
|
||||
@media (max-width: 768px) {
|
||||
.ui-recharge-page.rc-standalone .ui-recharge-content {
|
||||
padding-inline: var(--uc-page-pad-x, 16px);
|
||||
}
|
||||
}
|
||||
|
||||
html.dark .ui-recharge-page {
|
||||
--rc-border: var(--border-subtle);
|
||||
--rc-border-inner: var(--border-subtle);
|
||||
@@ -124,7 +135,6 @@ html.dark .ui-recharge-page {
|
||||
--rc-empty-border: var(--border-subtle);
|
||||
}
|
||||
|
||||
|
||||
/* 三栏布局:钱包 230px + 主卡;记录卡在下方 */
|
||||
.rc-layout {
|
||||
display: grid;
|
||||
@@ -563,7 +573,12 @@ html.dark .ui-recharge-page {
|
||||
font-size: 12px;
|
||||
line-height: 18px;
|
||||
}
|
||||
.rc-invoice span {
|
||||
.rc-invoice button {
|
||||
padding: 0;
|
||||
border: 0;
|
||||
background: none;
|
||||
font: inherit;
|
||||
cursor: pointer;
|
||||
margin-left: 6px;
|
||||
color: var(--ui-color-primary);
|
||||
}
|
||||
@@ -840,40 +855,3 @@ html.dark .ui-recharge-page {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
}
|
||||
|
||||
/* 充值确认弹窗(原型未定义):Ant Design 默认弹窗 + 统一规范的语义行列表 */
|
||||
.payment-confirm-rows {
|
||||
display: grid;
|
||||
gap: 12px;
|
||||
margin: 16px 0;
|
||||
padding: 16px 0;
|
||||
border-block: 1px solid var(--border-subtle);
|
||||
}
|
||||
.payment-confirm-rows > div {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
}
|
||||
.payment-confirm-rows dt {
|
||||
color: var(--text-secondary);
|
||||
font-size: 13px;
|
||||
}
|
||||
.payment-confirm-rows dd {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin: 0;
|
||||
color: var(--text-primary);
|
||||
font-weight: 600;
|
||||
}
|
||||
.payment-confirm-amount {
|
||||
color: var(--ui-color-primary);
|
||||
font-size: 20px;
|
||||
}
|
||||
.payment-confirm-discount {
|
||||
color: var(--ui-color-success);
|
||||
}
|
||||
.payment-confirm-method .ant-typography {
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user