Initial import of weiyuan frontend

This commit is contained in:
qiubaishen
2026-10-15 16:33:46 +08:00
commit d8f3aee261
774 changed files with 374914 additions and 0 deletions
+544
View File
@@ -0,0 +1,544 @@
/*
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 from 'react';
import {
Card,
Typography,
Button,
Input,
Spin,
Tooltip,
Skeleton,
Banner,
} from '@douyinfe/semi-ui';
import { IconGift } from '@douyinfe/semi-icons';
import {
CreditCard,
Wallet,
Coins,
Sparkles,
TrendingUp,
Gift,
Zap,
ExternalLink,
Receipt,
Headphones,
} from 'lucide-react';
import {
AlipayBrandIcon,
WechatBrandIcon,
StripeBrandIcon,
PayPalBrandIcon,
} from '../../components/common/icons/BrandIcons';
import AmountCard from './AmountCard';
import { useMinimumLoadingTime } from '../../hooks/common/useMinimumLoadingTime';
const { Text, Title } = Typography;
const RechargePanel = ({
t,
userState,
renderQuota,
renderQuotaWithAmount,
statusLoading,
balanceLoading,
enableOnlineTopUp,
enableWechatTopUp,
enableAlipayTopUp,
enableStripeTopUp,
enablePayPalTopUp,
enableCreemTopUp,
creemProducts,
creemPreTopUp,
presetAmounts,
selectedPreset,
selectPresetAmount,
formatLargeNumber,
priceRatio,
topUpCount,
minTopUp,
getAmount,
setTopUpCount,
setSelectedPreset,
setSelectedPresetObj,
renderAmount,
amountLoading,
payMethods,
preTopUp,
paymentLoading,
payWay,
redemptionCode,
setRedemptionCode,
topUp,
isSubmitting,
topUpLink,
openTopUpLink,
topupInfo,
}) => {
useMinimumLoadingTime(amountLoading);
const showBalanceSkeleton = useMinimumLoadingTime(balanceLoading);
// Creem 使用独立产品选择;其余渠道共用金额和支付方式区块。
const hasStandardOnlinePayment =
enableOnlineTopUp ||
enableWechatTopUp ||
enableAlipayTopUp ||
enableStripeTopUp ||
enablePayPalTopUp;
const hasAnyOnlinePayment = hasStandardOnlinePayment || enableCreemTopUp;
// 渲染支付方式图标
const renderPayIcon = (type, color) => {
if (type === 'alipay') {
return <AlipayBrandIcon size={18} color='#1677FF' />;
} else if (type === 'wxpay') {
return <WechatBrandIcon size={18} color='#07C160' />;
} else if (type === 'stripe') {
return <StripeBrandIcon size={18} color='#635BFF' />;
} else if (type === 'paypal') {
return <PayPalBrandIcon size={18} />;
} else {
return (
<CreditCard size={18} color={color || 'var(--semi-color-text-2)'} />
);
}
};
return (
<div className='relative'>
{/* 外层发光效果 */}
<div className='absolute -inset-0.5 bg-gradient-to-br from-blue-400/20 via-brand-via/20 to-brand-to/20 rounded-[20px] blur-md opacity-60' />
<Card className='relative !rounded-2xl shadow-xl border border-white/60 dark:border-neutral-800/60 bg-white/70 dark:bg-neutral-900/70 backdrop-blur-xl h-full overflow-hidden'>
{/* 顶部装饰线 */}
<div className='absolute top-0 left-0 right-0 h-1 bg-gradient-to-r from-blue-500 via-brand-via to-brand-to' />
{/* 背景装饰 */}
<div className='absolute top-0 right-0 w-64 h-64 bg-gradient-to-br from-blue-400/10 to-brand-to/10 rounded-full blur-3xl -mr-32 -mt-32 pointer-events-none' />
<div className='absolute bottom-0 left-0 w-48 h-48 bg-gradient-to-br from-brand-from/10 to-brand-to/10 rounded-full blur-3xl -ml-24 -mb-24 pointer-events-none' />
<div className='relative'>
{/* 头部:余额展示 */}
<div className='flex items-center justify-between mb-4'>
<div className='flex items-center gap-3'>
<div className='relative'>
<div className='absolute -inset-1 bg-gradient-to-br from-blue-500/40 to-brand-to/40 rounded-xl blur-md' />
<div className='relative w-10 h-10 rounded-xl bg-gradient-to-br from-blue-500 to-brand-to flex items-center justify-center shadow-lg shadow-blue-500/30'>
<CreditCard size={20} className='text-white' />
</div>
<Sparkles
size={12}
className='absolute -top-1 -right-1 text-amber-400'
/>
</div>
<div>
<Title
heading={5}
className='!mb-0 bg-clip-text text-transparent bg-gradient-to-r from-blue-600 to-brand-to dark:from-blue-400 dark:to-brand-to'
>
{t('在线充值')}
</Title>
<Text type='tertiary' size='small'>
{t('多种支付方式,安全便捷')}
</Text>
</div>
</div>
</div>
{/* 余额卡片 */}
<div className='relative overflow-hidden bg-gradient-to-r from-blue-500 via-brand-via to-brand-to rounded-2xl p-4 mb-4 shadow-xl shadow-blue-500/20'>
{/* 装饰元素 */}
<div className='absolute top-0 right-0 w-32 h-32 bg-white/10 rounded-full -mr-8 -mt-8 blur-2xl' />
<div className='absolute bottom-0 left-0 w-24 h-24 bg-black/10 rounded-full -ml-8 -mb-8 blur-xl' />
<div className='relative z-10 flex items-center justify-between gap-4'>
{/* 左侧:余额信息 */}
<div className='flex items-center gap-3 min-w-0'>
<div className='p-2 bg-white/20 rounded-xl backdrop-blur-md flex-shrink-0'>
<Wallet size={18} className='text-white' />
</div>
<div className='min-w-0'>
<Text className='!text-white/80 text-xs font-medium'>
{t('当前余额')}
</Text>
<Skeleton
loading={showBalanceSkeleton}
placeholder={
<Skeleton.Title
style={{
width: 100,
height: 28,
backgroundColor: 'rgba(255,255,255,0.2)',
}}
/>
}
>
<Title
heading={4}
className='!text-white !mb-0 drop-shadow-sm truncate'
>
{renderQuota(userState?.user?.quota)}
</Title>
</Skeleton>
</div>
</div>
{/* 分隔线 */}
<div className='w-px h-10 bg-white/20 flex-shrink-0' />
{/* 右侧:历史消耗 */}
<div className='flex items-center gap-3 min-w-0'>
<div className='p-2 bg-white/10 rounded-xl backdrop-blur-md flex-shrink-0'>
<TrendingUp size={18} className='text-white/80' />
</div>
<div className='min-w-0'>
<Text className='!text-white/60 text-xs'>
{t('历史消耗')}
</Text>
<Text className='!text-white font-semibold text-sm block truncate'>
{renderQuota(userState?.user?.used_quota)}
</Text>
</div>
</div>
</div>
</div>
{/* 开票服务公告 */}
<div className='relative mb-4 overflow-hidden rounded-xl border border-amber-200/80 dark:border-amber-700/40 bg-amber-50/80 dark:bg-amber-950/20 backdrop-blur-sm'>
{/* 左侧强调色条 */}
<div className='absolute left-0 top-0 bottom-0 w-1 bg-gradient-to-b from-amber-400 to-orange-400' />
<div className='flex items-center gap-3 pl-4 pr-4 py-3'>
{/* 图标区 */}
<div className='flex-shrink-0 w-9 h-9 rounded-xl bg-gradient-to-br from-amber-400 to-orange-500 flex items-center justify-center shadow-md shadow-amber-400/30'>
<Receipt size={16} className='text-white' />
</div>
{/* 文字区 */}
<div className='flex-1 min-w-0'>
<div className='flex items-center gap-2 mb-0.5'>
<span className='text-xs font-bold text-amber-700 dark:text-amber-400 tracking-wide uppercase'>
{t('发票服务')}
</span>
<span className='text-[10px] px-1.5 py-0.5 rounded-full bg-amber-100 dark:bg-amber-900/50 text-amber-600 dark:text-amber-400 border border-amber-200 dark:border-amber-700/60 font-medium'>
{t('温馨提示')}
</span>
</div>
<Text
size='small'
className='!text-gray-600 dark:!text-gray-300 leading-relaxed'
>
{t('需要开发票的用户,请联系')}&nbsp;
<span className='inline-flex items-center gap-1 font-semibold text-amber-700 dark:text-amber-400'>
<Headphones size={12} />
{t('在线客服')}
</span>
&nbsp;{t('进行申请处理')}
</Text>
</div>
</div>
</div>
{statusLoading ? (
<div className='py-12 flex flex-col items-center justify-center'>
<Spin size='large' />
<Text type='tertiary' className='mt-4'>
{t('加载中...')}
</Text>
</div>
) : hasAnyOnlinePayment ? (
<div className='space-y-3.5'>
{/* 充值金额选择 */}
{hasStandardOnlinePayment && (
<div className='relative group'>
<div className='absolute -inset-0.5 bg-gradient-to-r from-emerald-400/20 to-teal-400/20 rounded-2xl blur-sm opacity-0 group-hover:opacity-100 transition-opacity' />
<div className='relative bg-white/50 dark:bg-neutral-800/40 backdrop-blur-md rounded-xl p-3.5 border border-white/70 dark:border-neutral-700/50 shadow-sm'>
<div className='flex items-center gap-2 mb-3'>
<div className='p-1.5 bg-gradient-to-br from-emerald-500 to-teal-500 rounded-lg shadow-md shadow-emerald-500/20'>
<Coins size={14} className='text-white' />
</div>
<Text strong className='text-gray-800 dark:text-gray-200'>
{t('选择充值金额')}
</Text>
</div>
<div className='grid grid-cols-2 sm:grid-cols-4 gap-2.5'>
{presetAmounts.slice(0, 8).map((preset, index) => (
<AmountCard
key={index}
preset={preset}
selected={selectedPreset === preset.value}
onClick={() => selectPresetAmount(preset)}
topupInfo={topupInfo}
priceRatio={priceRatio}
t={t}
/>
))}
</div>
</div>
</div>
)}
{/* 支付方式 */}
{hasStandardOnlinePayment && (
<div className='relative group'>
<div className='absolute -inset-0.5 bg-gradient-to-r from-brand-from/20 to-brand-to/20 rounded-2xl blur-sm opacity-0 group-hover:opacity-100 transition-opacity' />
<div className='relative bg-white/50 dark:bg-neutral-800/40 backdrop-blur-md rounded-xl p-3.5 border border-white/70 dark:border-neutral-700/50 shadow-sm'>
<div className='flex items-center gap-2 mb-3'>
<div className='p-1.5 bg-gradient-to-br from-brand-from to-brand-to rounded-lg shadow-md shadow-brand/20'>
<CreditCard size={14} className='text-white' />
</div>
<Text strong className='text-gray-800 dark:text-gray-200'>
{t('支付方式')}
</Text>
</div>
{payMethods && payMethods.length > 0 ? (
<div className='flex flex-wrap gap-3'>
{payMethods.map((method) => {
const minTopupVal = Number(method.min_topup) || 0;
const isStripe = method.type === 'stripe';
const isPayPal = method.type === 'paypal';
const isWechat = method.type === 'wxpay';
const isAlipay = method.type === 'alipay';
const disabled =
(!enableOnlineTopUp &&
!isStripe &&
!isPayPal &&
!isWechat &&
!isAlipay) ||
(!enableStripeTopUp && isStripe) ||
(!enablePayPalTopUp && isPayPal) ||
(!enableWechatTopUp && isWechat) ||
(!enableAlipayTopUp && isAlipay) ||
minTopupVal > Number(topUpCount || 0);
const button = (
<Button
key={method.type}
theme={payWay === method.type ? 'solid' : 'light'}
type={
payWay === method.type ? 'primary' : 'tertiary'
}
onClick={() => preTopUp(method.type)}
disabled={disabled}
loading={paymentLoading && payWay === method.type}
icon={renderPayIcon(method.type, method.color)}
className={`!rounded-xl !px-5 !py-2.5 !h-auto transition-all ${
payWay === method.type
? '!bg-gradient-to-r !from-brand-from !to-brand-to !shadow-lg !shadow-brand/30'
: 'hover:!bg-brand/5 dark:hover:!bg-brand-deep/20 hover:!border-brand-from'
}`}
>
{method.name}
</Button>
);
if (
disabled &&
minTopupVal > Number(topUpCount || 0)
) {
return (
<Tooltip
key={method.type}
content={
t('此支付方式最低充值金额为') +
' ' +
minTopupVal
}
>
{button}
</Tooltip>
);
}
return button;
})}
</div>
) : (
<div className='text-gray-500 text-sm p-4 bg-gray-100/50 dark:bg-gray-800/50 rounded-xl border border-dashed border-gray-300 dark:border-gray-600 flex items-center gap-2'>
<Zap size={16} className='text-gray-400' />
{t('暂无可用的支付方式,请联系管理员配置')}
</div>
)}
</div>
</div>
)}
{/* Creem 充值 */}
{enableCreemTopUp && creemProducts.length > 0 && (
<div className='relative group'>
<div className='absolute -inset-0.5 bg-gradient-to-r from-cyan-400/20 to-blue-400/20 rounded-2xl blur-sm opacity-0 group-hover:opacity-100 transition-opacity' />
<div className='relative bg-white/50 dark:bg-neutral-800/40 backdrop-blur-md rounded-xl p-3.5 border border-white/70 dark:border-neutral-700/50 shadow-sm'>
<div className='flex items-center gap-2 mb-3'>
<div className='p-1.5 bg-gradient-to-br from-cyan-500 to-blue-500 rounded-lg shadow-md shadow-cyan-500/20'>
<Zap size={14} className='text-white' />
</div>
<Text strong className='text-gray-800 dark:text-gray-200'>
{t('Creem 充值')}
</Text>
</div>
<div className='grid grid-cols-2 sm:grid-cols-3 gap-3'>
{creemProducts.map((product, index) => (
<div
key={index}
onClick={() => creemPreTopUp(product)}
className='cursor-pointer rounded-xl p-4 bg-white dark:bg-neutral-900 border border-gray-200 dark:border-neutral-700 transition-all hover:shadow-lg hover:border-cyan-300 dark:hover:border-cyan-700 hover:scale-[1.02] text-center'
>
<Text
strong
className='block text-gray-800 dark:text-gray-200'
>
{product.name}
</Text>
<div className='text-xs text-gray-500 my-2'>
{t('额度')}: {product.quota}
</div>
<Text className='text-lg font-bold bg-clip-text text-transparent bg-gradient-to-r from-cyan-600 to-blue-600'>
{product.currency === 'EUR' ? '€' : '¥'}
{product.price}
</Text>
</div>
))}
</div>
</div>
</div>
)}
{/* 分隔线 */}
<div className='h-px bg-gradient-to-r from-transparent via-gray-200 dark:via-gray-700 to-transparent' />
{/* 兑换码充值 */}
<div className='relative group'>
<div className='absolute -inset-0.5 bg-gradient-to-r from-amber-400/20 to-orange-400/20 rounded-2xl blur-sm opacity-0 group-hover:opacity-100 transition-opacity' />
<div className='relative bg-white/50 dark:bg-neutral-800/40 backdrop-blur-md rounded-xl p-3.5 border border-white/70 dark:border-neutral-700/50 shadow-sm'>
<div className='flex items-center gap-2 mb-3'>
<div className='p-1.5 bg-gradient-to-br from-amber-500 to-orange-500 rounded-lg shadow-md shadow-amber-500/20'>
<Gift size={14} className='text-white' />
</div>
<Text strong className='text-gray-800 dark:text-gray-200'>
{t('兑换码充值')}
</Text>
</div>
<div className='flex gap-3'>
<Input
prefix={<IconGift className='text-amber-500' />}
placeholder={t('请输入兑换码')}
value={redemptionCode}
onChange={(value) => setRedemptionCode(value)}
showClear
className='flex-1 !rounded-xl'
style={{ flex: 1 }}
/>
<Button
theme='solid'
onClick={topUp}
loading={isSubmitting}
className='!bg-gradient-to-r !from-amber-500 !to-orange-500 !rounded-xl !px-6 !shadow-lg !shadow-amber-500/20 hover:!shadow-amber-500/30 transition-all'
>
{t('兑换')}
</Button>
</div>
{topUpLink && (
<div className='mt-2 flex items-center gap-1'>
<Text type='tertiary' size='small'>
{t('在找兑换码?')}
</Text>
<Text
link
onClick={openTopUpLink}
className='cursor-pointer flex items-center gap-1 text-amber-600 hover:text-amber-700'
>
{t('购买兑换码')}
<ExternalLink size={12} />
</Text>
</div>
)}
</div>
</div>
</div>
) : (
<div className='space-y-3.5'>
{/* 提示信息 */}
<Banner
type='info'
description={t(
'管理员未开启在线充值功能,请联系管理员开启或使用兑换码充值。',
)}
className='!rounded-xl'
closeIcon={null}
/>
{/* 分隔线 */}
<div className='h-px bg-gradient-to-r from-transparent via-gray-200 dark:via-gray-700 to-transparent' />
{/* 兑换码充值 */}
<div className='relative group'>
<div className='absolute -inset-0.5 bg-gradient-to-r from-amber-400/20 to-orange-400/20 rounded-2xl blur-sm opacity-0 group-hover:opacity-100 transition-opacity' />
<div className='relative bg-white/50 dark:bg-neutral-800/40 backdrop-blur-md rounded-xl p-3.5 border border-white/70 dark:border-neutral-700/50 shadow-sm'>
<div className='flex items-center gap-2 mb-3'>
<div className='p-1.5 bg-gradient-to-br from-amber-500 to-orange-500 rounded-lg'>
<Gift size={14} className='text-white' />
</div>
<Text strong className='text-gray-800 dark:text-gray-200'>
{t('兑换码充值')}
</Text>
</div>
<div className='flex gap-3'>
<Input
prefix={<IconGift className='text-amber-500' />}
placeholder={t('请输入兑换码')}
value={redemptionCode}
onChange={(value) => setRedemptionCode(value)}
showClear
className='flex-1 !rounded-xl'
style={{ flex: 1 }}
/>
<Button
theme='solid'
onClick={topUp}
loading={isSubmitting}
className='!bg-gradient-to-r !from-amber-500 !to-orange-500 !rounded-xl !px-6 !shadow-lg !shadow-amber-500/20 hover:!shadow-amber-500/30 transition-all'
>
{t('兑换')}
</Button>
</div>
{topUpLink && (
<div className='mt-2 flex items-center gap-1'>
<Text type='tertiary' size='small'>
{t('在找兑换码?')}
</Text>
<Text
link
onClick={openTopUpLink}
className='cursor-pointer flex items-center gap-1 text-amber-600 hover:text-amber-700'
>
{t('购买兑换码')}
<ExternalLink size={12} />
</Text>
</div>
)}
</div>
</div>
</div>
)}
</div>
</Card>
</div>
);
};
export default RechargePanel;