Initial import of weiyuan frontend
This commit is contained in:
@@ -0,0 +1,989 @@
|
||||
/*
|
||||
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, useContext } from 'react';
|
||||
import {
|
||||
Typography,
|
||||
Button,
|
||||
Tag,
|
||||
Modal,
|
||||
Spin,
|
||||
Empty,
|
||||
Banner,
|
||||
} from '@douyinfe/semi-ui';
|
||||
import {
|
||||
Crown,
|
||||
Sparkles,
|
||||
Zap,
|
||||
Calendar,
|
||||
Check,
|
||||
Clock,
|
||||
Shield,
|
||||
Star,
|
||||
FileText,
|
||||
} from 'lucide-react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { UserContext } from '../../context/User';
|
||||
import { API, showError, showSuccess, renderQuota } from '../../helpers';
|
||||
import MembershipHistoryModal from '../../components/membership/MembershipHistoryModal';
|
||||
|
||||
const { Text } = Typography;
|
||||
|
||||
// 方案类型图标和颜色映射
|
||||
const planTypeConfig = {
|
||||
weekly: {
|
||||
label: '周卡',
|
||||
color: 'var(--brand-gradient-from)',
|
||||
gradient: 'from-brand-from to-brand',
|
||||
icon: Clock,
|
||||
btnGradient:
|
||||
'linear-gradient(135deg, var(--brand-gradient-from), var(--brand-primary))',
|
||||
},
|
||||
monthly: {
|
||||
label: '月卡',
|
||||
color: 'var(--brand-gradient-to)',
|
||||
gradient: 'from-brand-from to-brand-to',
|
||||
icon: Calendar,
|
||||
btnGradient:
|
||||
'linear-gradient(135deg, var(--brand-gradient-to), var(--brand-primary-hover))',
|
||||
},
|
||||
quarterly: {
|
||||
label: '季卡',
|
||||
color: 'var(--brand-primary-hover)',
|
||||
gradient: 'from-brand-deep to-brand',
|
||||
icon: Crown,
|
||||
btnGradient:
|
||||
'linear-gradient(135deg, var(--brand-primary-hover), var(--brand-primary))',
|
||||
},
|
||||
};
|
||||
|
||||
const tierConfig = {
|
||||
lite: {
|
||||
label: '轻度版',
|
||||
color: 'var(--brand-primary)',
|
||||
desc: '适合偶尔使用',
|
||||
},
|
||||
pro: {
|
||||
label: '重度版',
|
||||
color: 'var(--brand-primary-hover)',
|
||||
desc: '高频使用首选',
|
||||
},
|
||||
};
|
||||
|
||||
const MembershipPanel = () => {
|
||||
const { t } = useTranslation();
|
||||
const [, userDispatch] = useContext(UserContext);
|
||||
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [membershipEnabled, setMembershipEnabled] = useState(false);
|
||||
const [plans, setPlans] = useState([]);
|
||||
const [, setTitle] = useState('会员订阅');
|
||||
const [description, setDescription] = useState('');
|
||||
|
||||
// 当前会员信息
|
||||
const [membershipInfo, setMembershipInfo] = useState(null);
|
||||
const [infoLoading, setInfoLoading] = useState(true);
|
||||
|
||||
// 购买相关
|
||||
const [selectedPlan, setSelectedPlan] = useState(null);
|
||||
const [purchaseModalVisible, setPurchaseModalVisible] = useState(false);
|
||||
const [purchasing, setPurchasing] = useState(false);
|
||||
|
||||
// 升级相关
|
||||
const [upgradeModalVisible, setUpgradeModalVisible] = useState(false);
|
||||
const [upgradeInfo, setUpgradeInfo] = useState(null);
|
||||
const [upgradeLoading, setUpgradeLoading] = useState(false);
|
||||
const [upgrading, setUpgrading] = useState(false);
|
||||
|
||||
// 选中的方案类型 tab
|
||||
const [activeType, setActiveType] = useState('monthly');
|
||||
|
||||
// 会员购买历史弹窗
|
||||
const [historyModalVisible, setHistoryModalVisible] = useState(false);
|
||||
|
||||
// 获取方案列表
|
||||
const fetchPlans = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const res = await API.get('/api/user/membership/plans');
|
||||
const { success, data } = res.data;
|
||||
if (success) {
|
||||
setMembershipEnabled(data.membership_enabled);
|
||||
setPlans(data.plans || []);
|
||||
setTitle(data.title || '会员订阅');
|
||||
setDescription(data.description || '');
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('获取会员方案失败:', err);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// 获取当前会员信息
|
||||
const fetchMembershipInfo = async () => {
|
||||
setInfoLoading(true);
|
||||
try {
|
||||
const res = await API.get('/api/user/membership/info');
|
||||
const { success, data } = res.data;
|
||||
if (success) {
|
||||
setMembershipInfo(data);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('获取会员信息失败:', err);
|
||||
} finally {
|
||||
setInfoLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
// 购买会员
|
||||
const handlePurchase = async () => {
|
||||
if (!selectedPlan) return;
|
||||
setPurchasing(true);
|
||||
try {
|
||||
const res = await API.post('/api/user/membership/purchase', {
|
||||
plan_id: selectedPlan.id,
|
||||
payment_method: 'balance',
|
||||
});
|
||||
const { success, message } = res.data;
|
||||
if (success) {
|
||||
showSuccess(t('购买成功!'));
|
||||
setPurchaseModalVisible(false);
|
||||
setSelectedPlan(null);
|
||||
fetchMembershipInfo();
|
||||
// 刷新用户信息
|
||||
try {
|
||||
const userRes = await API.get('/api/user/self');
|
||||
if (userRes.data.success) {
|
||||
userDispatch({ type: 'login', payload: userRes.data.data });
|
||||
}
|
||||
} catch (e) {}
|
||||
} else {
|
||||
showError(message);
|
||||
}
|
||||
} catch (err) {
|
||||
showError(t('购买失败'));
|
||||
} finally {
|
||||
setPurchasing(false);
|
||||
}
|
||||
};
|
||||
|
||||
// 检查是否为升级场景并获取差价
|
||||
const checkUpgrade = async (plan) => {
|
||||
if (!membershipInfo?.has_membership) return false;
|
||||
if (plan.daily_quota <= membershipInfo.daily_quota) return false;
|
||||
if (plan.plan_type !== membershipInfo.plan_type) return false; // 只能同类型内升级
|
||||
|
||||
setUpgradeLoading(true);
|
||||
try {
|
||||
const res = await API.get(
|
||||
`/api/user/membership/upgrade/cost?plan_id=${plan.id}`,
|
||||
);
|
||||
const { success, data } = res.data;
|
||||
if (success && data.can_upgrade) {
|
||||
setUpgradeInfo(data);
|
||||
return true;
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('查询升级信息失败:', err);
|
||||
} finally {
|
||||
setUpgradeLoading(false);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
// 判断是否为当前正在使用的同款方案(匹配 tier + plan_type,可续费但不可升级)
|
||||
const isCurrentPlanCheck = (plan) => {
|
||||
return (
|
||||
membershipInfo?.has_membership &&
|
||||
membershipInfo?.daily_quota === plan.daily_quota &&
|
||||
membershipInfo?.tier === plan.tier &&
|
||||
membershipInfo?.plan_type === plan.plan_type
|
||||
);
|
||||
};
|
||||
|
||||
// 判断是否可以升级(同一时长类型内,更高档位)
|
||||
const canUpgradeCheck = (plan) => {
|
||||
return (
|
||||
membershipInfo?.has_membership &&
|
||||
plan.daily_quota > (membershipInfo?.daily_quota || 0) &&
|
||||
plan.plan_type === membershipInfo?.plan_type
|
||||
);
|
||||
};
|
||||
|
||||
// 判断是否为降级(同一时长类型内,更低档位)
|
||||
const isDowngradeCheck = (plan) => {
|
||||
return (
|
||||
membershipInfo?.has_membership &&
|
||||
plan.plan_type === membershipInfo?.plan_type &&
|
||||
plan.daily_quota < (membershipInfo?.daily_quota || 0)
|
||||
);
|
||||
};
|
||||
|
||||
// 判断该方案是否已有未来待生效的续费
|
||||
const hasFutureForPlan = (plan) => {
|
||||
return (
|
||||
membershipInfo?.has_future_membership &&
|
||||
membershipInfo?.future_plan_type === plan.plan_type &&
|
||||
membershipInfo?.future_tier === plan.tier
|
||||
);
|
||||
};
|
||||
|
||||
// 点击方案卡片
|
||||
const handlePlanClick = async (plan) => {
|
||||
setSelectedPlan(plan);
|
||||
// 判断是否为升级场景(同一时长类型内,且每日额度更高)
|
||||
if (canUpgradeCheck(plan)) {
|
||||
const isUpgrade = await checkUpgrade(plan);
|
||||
if (isUpgrade) {
|
||||
setUpgradeModalVisible(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// 普通购买 / 续期(包括同款方案续费)
|
||||
setPurchaseModalVisible(true);
|
||||
};
|
||||
|
||||
// 执行升级
|
||||
const handleUpgrade = async () => {
|
||||
if (!selectedPlan) return;
|
||||
setUpgrading(true);
|
||||
try {
|
||||
const res = await API.post('/api/user/membership/upgrade', {
|
||||
plan_id: selectedPlan.id,
|
||||
});
|
||||
const { success, message } = res.data;
|
||||
if (success) {
|
||||
showSuccess(message || '升级成功!');
|
||||
setUpgradeModalVisible(false);
|
||||
setSelectedPlan(null);
|
||||
setUpgradeInfo(null);
|
||||
fetchMembershipInfo();
|
||||
// 刷新用户信息
|
||||
try {
|
||||
const userRes = await API.get('/api/user/self');
|
||||
if (userRes.data.success) {
|
||||
userDispatch({ type: 'login', payload: userRes.data.data });
|
||||
}
|
||||
} catch (e) {}
|
||||
} else {
|
||||
showError(message);
|
||||
}
|
||||
} catch (err) {
|
||||
showError(t('升级失败'));
|
||||
} finally {
|
||||
setUpgrading(false);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
fetchPlans();
|
||||
fetchMembershipInfo();
|
||||
}, []);
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div className='flex items-center justify-center py-20'>
|
||||
<Spin size='large' />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!membershipEnabled) {
|
||||
return (
|
||||
<div className='py-12'>
|
||||
<Empty
|
||||
title={t('会员功能未开启')}
|
||||
description={t('管理员尚未启用会员订阅功能')}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// 按类型分组方案
|
||||
const plansByType = {};
|
||||
plans.forEach((plan) => {
|
||||
if (!plansByType[plan.plan_type]) {
|
||||
plansByType[plan.plan_type] = [];
|
||||
}
|
||||
plansByType[plan.plan_type].push(plan);
|
||||
});
|
||||
|
||||
const typeKeys = Object.keys(plansByType);
|
||||
|
||||
// 格式化日期
|
||||
const formatDate = (timestamp) => {
|
||||
return new Date(timestamp * 1000).toLocaleDateString('zh-CN');
|
||||
};
|
||||
|
||||
return (
|
||||
<div className='space-y-4'>
|
||||
{/* 当前会员状态卡片 */}
|
||||
{!infoLoading && membershipInfo?.has_membership && (
|
||||
<div
|
||||
className='relative overflow-hidden rounded-2xl p-5 text-white shadow-2xl'
|
||||
style={{
|
||||
background:
|
||||
'linear-gradient(135deg, color-mix(in srgb, var(--brand-primary-hover) 35%, #0b1020) 0%, color-mix(in srgb, var(--brand-primary-hover) 55%, #161029) 30%, color-mix(in srgb, var(--brand-gradient-to) 70%, #211038) 60%, var(--brand-primary-hover) 100%)',
|
||||
}}
|
||||
>
|
||||
{/* 背景装饰 */}
|
||||
<div className='absolute top-0 right-0 w-64 h-64 bg-brand/15 rounded-full blur-3xl' />
|
||||
<div className='absolute -bottom-16 -left-16 w-48 h-48 bg-brand-from/10 rounded-full blur-3xl' />
|
||||
<div className='absolute top-1/2 right-1/4 w-24 h-24 bg-brand-from/10 rounded-full blur-2xl' />
|
||||
|
||||
<div className='relative'>
|
||||
<div className='flex items-center justify-between mb-3.5'>
|
||||
<div className='flex items-center gap-2.5'>
|
||||
<div className='w-8 h-8 rounded-lg bg-gradient-to-br from-yellow-400 to-amber-500 flex items-center justify-center shadow-lg shadow-amber-500/30'>
|
||||
<Crown size={18} className='text-white' />
|
||||
</div>
|
||||
<span className='text-white font-semibold text-base tracking-wide'>
|
||||
{t('当前会员')}
|
||||
</span>
|
||||
</div>
|
||||
<div className='flex items-center gap-2'>
|
||||
<span className='inline-flex items-center px-2.5 py-1 rounded-md text-xs font-medium bg-white/15 text-white backdrop-blur-sm border border-white/20'>
|
||||
{membershipInfo.plan_name}
|
||||
</span>
|
||||
<button
|
||||
onClick={() => setHistoryModalVisible(true)}
|
||||
className='inline-flex items-center gap-1.5 px-2.5 py-1 rounded-md text-xs font-medium bg-white/10 text-white/90 backdrop-blur-sm border border-white/15 hover:bg-white/20 transition-all duration-200'
|
||||
>
|
||||
<FileText size={12} />
|
||||
{t('查看记录')}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className='grid grid-cols-2 gap-3 mb-3.5'>
|
||||
<div className='p-3 rounded-xl bg-white/10 backdrop-blur-sm border border-white/10'>
|
||||
<span className='text-white/70 text-xs block mb-1'>
|
||||
{t('今日剩余额度')}
|
||||
</span>
|
||||
<span
|
||||
className='text-white font-bold text-xl block'
|
||||
style={{ textShadow: '0 1px 2px rgba(0,0,0,0.2)' }}
|
||||
>
|
||||
{renderQuota(membershipInfo.membership_quota)}
|
||||
</span>
|
||||
</div>
|
||||
<div className='p-3 rounded-xl bg-white/10 backdrop-blur-sm border border-white/10'>
|
||||
<span className='text-white/70 text-xs block mb-1'>
|
||||
{t('每日额度')}
|
||||
</span>
|
||||
<span
|
||||
className='text-white font-bold text-xl block'
|
||||
style={{ textShadow: '0 1px 2px rgba(0,0,0,0.2)' }}
|
||||
>
|
||||
{renderQuota(membershipInfo.daily_quota)}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 额度使用进度 */}
|
||||
{membershipInfo.daily_quota > 0 && (
|
||||
<div className='mb-3'>
|
||||
<div className='flex justify-between text-xs text-white/60 mb-1.5'>
|
||||
<span>{t('今日用量')}</span>
|
||||
<span>
|
||||
{Math.round(
|
||||
(membershipInfo.membership_quota /
|
||||
membershipInfo.daily_quota) *
|
||||
100,
|
||||
)}
|
||||
%
|
||||
</span>
|
||||
</div>
|
||||
<div className='w-full h-2 bg-white/10 rounded-full overflow-hidden'>
|
||||
<div
|
||||
className='h-full rounded-full transition-all duration-500'
|
||||
style={{
|
||||
width: `${Math.round((membershipInfo.membership_quota / membershipInfo.daily_quota) * 100)}%`,
|
||||
background:
|
||||
'linear-gradient(90deg, var(--brand-gradient-from), var(--brand-gradient-via), var(--brand-gradient-to))',
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className='flex items-center justify-between text-white/70 text-xs'>
|
||||
<span className='flex items-center gap-1.5'>
|
||||
<Calendar size={12} />
|
||||
{t('到期日')}: {formatDate(membershipInfo.end_date)}
|
||||
</span>
|
||||
<span className='flex items-center gap-1.5 px-2 py-0.5 rounded-full bg-white/10'>
|
||||
<Clock size={12} />
|
||||
{t('剩余')} {membershipInfo.remaining_days} {t('天')}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* 已续费提示 */}
|
||||
{membershipInfo.has_future_membership && (
|
||||
<div className='mt-3 pt-2.5 border-t border-white/15'>
|
||||
<div className='flex items-center gap-2 px-3 py-2 rounded-lg bg-emerald-500/15 border border-emerald-400/20'>
|
||||
<Check size={14} className='text-emerald-300 flex-shrink-0' />
|
||||
<span className='text-white text-xs'>
|
||||
{t('已续费')}:{membershipInfo.future_plan_name},
|
||||
{formatDate(membershipInfo.future_start_date)} ~{' '}
|
||||
{formatDate(membershipInfo.future_end_date)} {t('生效')}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 描述提示 */}
|
||||
{description && (
|
||||
<Banner type='info' description={description} closeIcon={null} />
|
||||
)}
|
||||
|
||||
{/* 查看购买历史按钮 - 当没有会员时也显示 */}
|
||||
{!membershipInfo?.has_membership && (
|
||||
<div className='flex justify-end -mt-1'>
|
||||
<Button
|
||||
theme='borderless'
|
||||
icon={<FileText size={16} />}
|
||||
onClick={() => setHistoryModalVisible(true)}
|
||||
className='text-gray-600 dark:text-gray-400 hover:text-brand-deep dark:hover:text-brand-from'
|
||||
>
|
||||
{t('查看购买记录')}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 方案类型切换 */}
|
||||
{typeKeys.length > 1 && (
|
||||
<div className='flex items-center gap-1.5 p-1.5 bg-gray-100/80 dark:bg-neutral-800/80 rounded-2xl backdrop-blur-sm border border-gray-200/50 dark:border-neutral-700/50'>
|
||||
{typeKeys.map((type) => {
|
||||
const config = planTypeConfig[type] || {
|
||||
label: type,
|
||||
gradient: 'from-gray-500 to-gray-600',
|
||||
};
|
||||
const TypeIcon = config.icon || Clock;
|
||||
const isActive = activeType === type;
|
||||
return (
|
||||
<button
|
||||
key={type}
|
||||
onClick={() => setActiveType(type)}
|
||||
className={`
|
||||
flex-1 flex items-center justify-center gap-2 py-2.5 px-4 rounded-xl text-sm font-semibold transition-all duration-300
|
||||
${
|
||||
isActive
|
||||
? `bg-gradient-to-r ${config.gradient} text-white shadow-lg transform scale-[1.02]`
|
||||
: 'text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300 hover:bg-white/60 dark:hover:bg-neutral-700/60'
|
||||
}
|
||||
`}
|
||||
>
|
||||
<TypeIcon size={16} />
|
||||
{config.label}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 方案卡片列表 */}
|
||||
<div className='grid grid-cols-1 sm:grid-cols-2 gap-4'>
|
||||
{(plansByType[activeType] || []).map((plan) => {
|
||||
const typeConf = planTypeConfig[plan.plan_type] || {};
|
||||
const tierConf = tierConfig[plan.tier] || {};
|
||||
const isSelected = selectedPlan?.id === plan.id;
|
||||
const isRecommend = plan.badge || plan.is_recommend;
|
||||
|
||||
return (
|
||||
<div
|
||||
key={plan.id}
|
||||
onClick={() => handlePlanClick(plan)}
|
||||
className={`
|
||||
group relative cursor-pointer rounded-2xl transition-all duration-300 overflow-hidden
|
||||
${
|
||||
isSelected
|
||||
? 'ring-2 ring-brand shadow-xl shadow-brand/20 scale-[1.02]'
|
||||
: 'hover:shadow-xl hover:shadow-gray-200/50 dark:hover:shadow-neutral-900/50 hover:-translate-y-1'
|
||||
}
|
||||
${
|
||||
isRecommend
|
||||
? 'bg-gradient-to-br from-white to-brand-to/50 dark:from-neutral-900 dark:to-brand-to/30 border-2 border-brand/20 dark:border-brand-deep/50'
|
||||
: 'bg-white dark:bg-neutral-900 border border-gray-200/80 dark:border-neutral-700/80'
|
||||
}
|
||||
`}
|
||||
>
|
||||
{/* 推荐角标 */}
|
||||
{plan.badge && (
|
||||
<div
|
||||
className='absolute top-0 right-0 px-3 py-1.5 rounded-bl-2xl text-xs font-bold text-white shadow-lg flex items-center gap-1'
|
||||
style={{
|
||||
background: plan.badge_color
|
||||
? `linear-gradient(135deg, ${plan.badge_color}, ${plan.badge_color}dd)`
|
||||
: 'linear-gradient(135deg, var(--brand-primary), var(--brand-gradient-to))',
|
||||
}}
|
||||
>
|
||||
<Star size={10} className='fill-current' />
|
||||
{plan.badge}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className='p-4'>
|
||||
{/* 方案头部 */}
|
||||
<div className='flex items-center gap-3 mb-3'>
|
||||
<div
|
||||
className={`w-10 h-10 rounded-xl bg-gradient-to-br ${typeConf.gradient || 'from-gray-500 to-gray-600'} flex items-center justify-center shadow-lg`}
|
||||
>
|
||||
<Zap size={18} className='text-white' />
|
||||
</div>
|
||||
<div>
|
||||
<Text strong className='text-base block leading-tight'>
|
||||
{plan.name}
|
||||
</Text>
|
||||
<Text className='text-xs text-gray-400 mt-0.5 block'>
|
||||
{plan.duration_days}
|
||||
{t('天')} · {tierConf.label}
|
||||
</Text>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 价格 */}
|
||||
<div className='mb-3'>
|
||||
<span className='text-sm font-medium text-gray-400 mr-0.5'>
|
||||
¥
|
||||
</span>
|
||||
<span
|
||||
className='text-4xl font-extrabold tracking-tight'
|
||||
style={{ color: typeConf.color || 'var(--brand-primary)' }}
|
||||
>
|
||||
{plan.price}
|
||||
</span>
|
||||
<span className='text-sm text-gray-400 ml-1 font-medium'>
|
||||
/{typeConf.label}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* 每日额度 - 高亮区域 */}
|
||||
<div className='flex items-center gap-2 mb-3 py-2 px-3 rounded-xl bg-gradient-to-r from-emerald-50 to-teal-50 dark:from-emerald-900/20 dark:to-teal-900/20 border border-emerald-100 dark:border-emerald-800/30'>
|
||||
<Sparkles
|
||||
size={15}
|
||||
className='text-emerald-500 flex-shrink-0'
|
||||
/>
|
||||
<span className='text-sm text-gray-600 dark:text-gray-300'>
|
||||
{t('每日到账')}{' '}
|
||||
<strong className='text-emerald-600 dark:text-emerald-400'>
|
||||
{renderQuota(plan.daily_quota)}
|
||||
</strong>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* 描述 */}
|
||||
{plan.description && (
|
||||
<Text className='text-xs text-gray-400 block mb-2'>
|
||||
{plan.description}
|
||||
</Text>
|
||||
)}
|
||||
|
||||
{/* 功能点 */}
|
||||
<div className='space-y-1.5 mb-3.5'>
|
||||
<div className='flex items-center gap-2.5 text-xs text-gray-500 dark:text-gray-400'>
|
||||
<div className='w-4 h-4 rounded-full bg-green-100 dark:bg-green-900/30 flex items-center justify-center flex-shrink-0'>
|
||||
<Check
|
||||
size={10}
|
||||
className='text-green-600 dark:text-green-400'
|
||||
/>
|
||||
</div>
|
||||
<span>{t('每日自动重置额度')}</span>
|
||||
</div>
|
||||
<div className='flex items-center gap-2.5 text-xs text-gray-500 dark:text-gray-400'>
|
||||
<div className='w-4 h-4 rounded-full bg-green-100 dark:bg-green-900/30 flex items-center justify-center flex-shrink-0'>
|
||||
<Check
|
||||
size={10}
|
||||
className='text-green-600 dark:text-green-400'
|
||||
/>
|
||||
</div>
|
||||
<span>{t('会员额度优先消耗')}</span>
|
||||
</div>
|
||||
<div className='flex items-center gap-2.5 text-xs text-gray-500 dark:text-gray-400'>
|
||||
<div className='w-4 h-4 rounded-full bg-blue-100 dark:bg-blue-900/30 flex items-center justify-center flex-shrink-0'>
|
||||
<Shield
|
||||
size={10}
|
||||
className='text-blue-600 dark:text-blue-400'
|
||||
/>
|
||||
</div>
|
||||
<span>{t('用完自动切换账户余额')}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 立即订阅/升级/续费按钮 */}
|
||||
{(() => {
|
||||
const isCurrentPlan = isCurrentPlanCheck(plan);
|
||||
const canUpgrade = canUpgradeCheck(plan);
|
||||
const isDowngrade = isDowngradeCheck(plan);
|
||||
const hasFuture = hasFutureForPlan(plan);
|
||||
// 按钮文案和样式 - 跟随卡片类型色调
|
||||
let btnText = t('立即订阅');
|
||||
let btnBg =
|
||||
typeConf.btnGradient ||
|
||||
'linear-gradient(135deg, var(--brand-primary), var(--brand-primary-hover))';
|
||||
let subText = '';
|
||||
if (isCurrentPlan) {
|
||||
btnText = hasFuture ? t('再次续费') : t('续费');
|
||||
} else if (canUpgrade) {
|
||||
btnText = t('立即升级');
|
||||
subText = t('立即生效,补差价');
|
||||
} else if (isDowngrade) {
|
||||
subText = t('到期后生效');
|
||||
} else if (membershipInfo?.has_membership) {
|
||||
subText = t('到期后生效');
|
||||
}
|
||||
return (
|
||||
<div>
|
||||
<button
|
||||
className='w-full py-2.5 rounded-xl text-white text-sm font-semibold shadow-lg hover:shadow-xl transition-all duration-300 hover:opacity-90 active:scale-[0.98]'
|
||||
style={{
|
||||
background: btnBg,
|
||||
}}
|
||||
>
|
||||
{btnText}
|
||||
</button>
|
||||
{subText && (
|
||||
<span className='text-xs text-gray-400 text-center block mt-1.5'>
|
||||
{subText}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})()}
|
||||
</div>
|
||||
|
||||
{/* 悬停光效 */}
|
||||
<div className='absolute inset-0 rounded-2xl bg-gradient-to-br from-brand-from/0 to-brand-to/0 group-hover:from-brand-from/[0.03] group-hover:to-brand-to/[0.06] transition-all duration-500 pointer-events-none' />
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
{plans.length === 0 && (
|
||||
<Empty
|
||||
title={t('暂无可用方案')}
|
||||
description={t('管理员尚未配置会员方案')}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* 购买确认弹窗 */}
|
||||
<Modal
|
||||
title={
|
||||
<div className='flex items-center gap-2'>
|
||||
<Crown size={20} className='text-amber-500' />
|
||||
{selectedPlan && isCurrentPlanCheck(selectedPlan)
|
||||
? t('确认续费会员')
|
||||
: t('确认购买会员')}
|
||||
</div>
|
||||
}
|
||||
visible={purchaseModalVisible}
|
||||
onOk={handlePurchase}
|
||||
onCancel={() => {
|
||||
setPurchaseModalVisible(false);
|
||||
setSelectedPlan(null);
|
||||
}}
|
||||
confirmLoading={purchasing}
|
||||
okText={
|
||||
selectedPlan && isCurrentPlanCheck(selectedPlan)
|
||||
? t('确认续费')
|
||||
: t('确认购买')
|
||||
}
|
||||
cancelText={t('取消')}
|
||||
centered
|
||||
maskClosable={false}
|
||||
>
|
||||
{selectedPlan && (
|
||||
<div className='space-y-4 py-2'>
|
||||
<div className='p-4 rounded-xl bg-gradient-to-r from-gray-50 to-gray-100 dark:from-neutral-800 dark:to-neutral-900'>
|
||||
<div className='flex justify-between items-center mb-2'>
|
||||
<Text strong className='text-lg'>
|
||||
{selectedPlan.name}
|
||||
</Text>
|
||||
<Tag color='blue' size='small'>
|
||||
{selectedPlan.duration_days}
|
||||
{t('天')}
|
||||
</Tag>
|
||||
</div>
|
||||
<div className='flex justify-between items-center mb-2'>
|
||||
<Text className='text-gray-500'>{t('每日到账额度')}</Text>
|
||||
<Text strong className='text-emerald-600'>
|
||||
{renderQuota(selectedPlan.daily_quota)}
|
||||
</Text>
|
||||
</div>
|
||||
<div className='flex justify-between items-center'>
|
||||
<Text className='text-gray-500'>{t('总计到账')}</Text>
|
||||
<Text strong className='text-blue-600'>
|
||||
{renderQuota(
|
||||
selectedPlan.daily_quota * selectedPlan.duration_days,
|
||||
)}
|
||||
</Text>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className='flex justify-between items-center pt-2 border-t border-gray-200 dark:border-neutral-700'>
|
||||
<Text className='text-gray-500'>{t('支付方式')}</Text>
|
||||
<Text strong>{t('账户余额抵扣')}</Text>
|
||||
</div>
|
||||
|
||||
<div className='flex justify-between items-center'>
|
||||
<Text className='text-gray-500'>{t('需支付')}</Text>
|
||||
<Text strong className='text-2xl text-red-500'>
|
||||
¥{selectedPlan.price}
|
||||
</Text>
|
||||
</div>
|
||||
|
||||
{/* 场景化提示 */}
|
||||
{(() => {
|
||||
if (!membershipInfo?.has_membership) {
|
||||
// 新用户,无会员
|
||||
return (
|
||||
<Banner
|
||||
type='info'
|
||||
description={t(
|
||||
'购买后会员立即生效,每日额度将于每天自动重置到账。',
|
||||
)}
|
||||
closeIcon={null}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
const isRenewal = isCurrentPlanCheck(selectedPlan);
|
||||
const isDowngrade = isDowngradeCheck(selectedPlan);
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* 续费同款方案 */}
|
||||
{isRenewal && (
|
||||
<Banner
|
||||
type='success'
|
||||
description={
|
||||
t('续费提示') +
|
||||
':' +
|
||||
t('您将续费当前「') +
|
||||
membershipInfo.plan_name +
|
||||
t('」,新的 ') +
|
||||
selectedPlan.duration_days +
|
||||
t(' 天会员将在当前会员到期后(') +
|
||||
formatDate(membershipInfo.end_date) +
|
||||
t(')自动生效,届时每日额度保持不变。')
|
||||
}
|
||||
closeIcon={null}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* 购买不同类型的方案(非升级、非同款) */}
|
||||
{!isRenewal && !isDowngrade && (
|
||||
<Banner
|
||||
type='info'
|
||||
description={
|
||||
t('您当前有「') +
|
||||
membershipInfo.plan_name +
|
||||
t('」会员(到期日:') +
|
||||
formatDate(membershipInfo.end_date) +
|
||||
t(')。新购买的「') +
|
||||
selectedPlan.name +
|
||||
t('」将在当前会员到期后开始生效。')
|
||||
}
|
||||
closeIcon={null}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* 降级方案提示 */}
|
||||
{isDowngrade && (
|
||||
<Banner
|
||||
type='warning'
|
||||
description={
|
||||
t('注意:此方案的每日额度(') +
|
||||
renderQuota(selectedPlan.daily_quota) +
|
||||
t(')低于您当前方案(') +
|
||||
renderQuota(membershipInfo.daily_quota) +
|
||||
t(
|
||||
')。新会员将在当前会员到期后生效,届时每日额度将降低。如需立即提升额度,建议使用「升级」功能。',
|
||||
)
|
||||
}
|
||||
closeIcon={null}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* 同类型升级提示(用户通过购买而非升级入口来的) */}
|
||||
{!isRenewal &&
|
||||
!isDowngrade &&
|
||||
canUpgradeCheck(selectedPlan) && (
|
||||
<Banner
|
||||
type='info'
|
||||
description={t(
|
||||
'提示:此方案额度高于您当前方案,您也可以选择「升级」,升级后立即生效且只需补差价。',
|
||||
)}
|
||||
closeIcon={null}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* 已有未来待生效的续费 */}
|
||||
{membershipInfo.has_future_membership && (
|
||||
<Banner
|
||||
type='warning'
|
||||
description={
|
||||
t('您已有一个待生效的续费会员「') +
|
||||
membershipInfo.future_plan_name +
|
||||
t('」(') +
|
||||
formatDate(membershipInfo.future_start_date) +
|
||||
t(
|
||||
' 生效)。再次购买将在其到期后生效,请确认是否需要继续。',
|
||||
)
|
||||
}
|
||||
closeIcon={null}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
})()}
|
||||
|
||||
<Banner
|
||||
type='warning'
|
||||
description={t(
|
||||
'购买后将从您的账户余额中扣除对应额度,会员每日额度不累加,当日未使用次日重置。',
|
||||
)}
|
||||
closeIcon={null}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</Modal>
|
||||
|
||||
{/* 升级确认弹窗 */}
|
||||
<Modal
|
||||
title={
|
||||
<div className='flex items-center gap-2'>
|
||||
<Zap size={20} className='text-orange-500' />
|
||||
{t('确认升级会员')}
|
||||
</div>
|
||||
}
|
||||
visible={upgradeModalVisible}
|
||||
onOk={handleUpgrade}
|
||||
onCancel={() => {
|
||||
setUpgradeModalVisible(false);
|
||||
setSelectedPlan(null);
|
||||
setUpgradeInfo(null);
|
||||
}}
|
||||
confirmLoading={upgrading}
|
||||
okText={t('确认升级')}
|
||||
cancelText={t('取消')}
|
||||
centered
|
||||
maskClosable={false}
|
||||
>
|
||||
{selectedPlan && upgradeInfo && (
|
||||
<div className='space-y-4 py-2'>
|
||||
{/* 升级对比 */}
|
||||
<div className='p-4 rounded-xl bg-gradient-to-r from-orange-50 to-amber-50 dark:from-orange-900/20 dark:to-amber-900/20'>
|
||||
<div className='flex items-center justify-between mb-3'>
|
||||
<div className='text-center flex-1'>
|
||||
<Text className='text-xs text-gray-400 block mb-1'>
|
||||
{t('当前方案')}
|
||||
</Text>
|
||||
<Text strong className='text-sm block'>
|
||||
{upgradeInfo.current_plan}
|
||||
</Text>
|
||||
<Text className='text-xs text-gray-500 block mt-1'>
|
||||
{t('每日')} {renderQuota(upgradeInfo.current_daily)}
|
||||
</Text>
|
||||
</div>
|
||||
<div className='mx-3 flex flex-col items-center'>
|
||||
<Zap size={20} className='text-orange-500' />
|
||||
<Text className='text-xs text-orange-500 mt-1'>
|
||||
{t('升级')}
|
||||
</Text>
|
||||
</div>
|
||||
<div className='text-center flex-1'>
|
||||
<Text className='text-xs text-gray-400 block mb-1'>
|
||||
{t('升级方案')}
|
||||
</Text>
|
||||
<Text strong className='text-sm block text-orange-600'>
|
||||
{upgradeInfo.new_plan}
|
||||
</Text>
|
||||
<Text className='text-xs text-orange-500 block mt-1'>
|
||||
{t('每日')} {renderQuota(upgradeInfo.new_daily)}
|
||||
</Text>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 差价明细 */}
|
||||
<div className='p-4 rounded-xl bg-gradient-to-r from-gray-50 to-gray-100 dark:from-neutral-800 dark:to-neutral-900'>
|
||||
<div className='flex justify-between items-center mb-2'>
|
||||
<Text className='text-gray-500'>{t('剩余会员天数')}</Text>
|
||||
<Text strong>
|
||||
{upgradeInfo.remaining_days} {t('天')}
|
||||
</Text>
|
||||
</div>
|
||||
<div className='flex justify-between items-center mb-2'>
|
||||
<Text className='text-gray-500'>{t('升级差价')}</Text>
|
||||
<Text strong className='text-orange-600'>
|
||||
¥{upgradeInfo.upgrade_cost}
|
||||
</Text>
|
||||
</div>
|
||||
<div className='flex justify-between items-center'>
|
||||
<Text className='text-gray-500'>{t('需补缴额度')}</Text>
|
||||
<Text strong className='text-blue-600'>
|
||||
{renderQuota(upgradeInfo.quota_needed)}
|
||||
</Text>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className='flex justify-between items-center pt-2 border-t border-gray-200 dark:border-neutral-700'>
|
||||
<Text className='text-gray-500'>{t('支付方式')}</Text>
|
||||
<Text strong>{t('账户余额抵扣')}</Text>
|
||||
</div>
|
||||
|
||||
<div className='flex justify-between items-center'>
|
||||
<Text className='text-gray-500'>{t('需支付')}</Text>
|
||||
<Text strong className='text-2xl text-red-500'>
|
||||
¥{upgradeInfo.upgrade_cost}
|
||||
</Text>
|
||||
</div>
|
||||
|
||||
<Banner
|
||||
type='info'
|
||||
description={t(
|
||||
'升级后立即生效,今日额度将重置为新方案额度。到期日期不变。',
|
||||
)}
|
||||
closeIcon={null}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{upgradeLoading && (
|
||||
<div className='flex items-center justify-center py-8'>
|
||||
<Spin size='large' />
|
||||
</div>
|
||||
)}
|
||||
</Modal>
|
||||
|
||||
{/* 会员购买历史弹窗 */}
|
||||
<MembershipHistoryModal
|
||||
visible={historyModalVisible}
|
||||
onClose={() => setHistoryModalVisible(false)}
|
||||
t={t}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default MembershipPanel;
|
||||
Reference in New Issue
Block a user