feat: 参考原型图 ui优化提交 个人端-用户中心 相关的页面

This commit is contained in:
zhanjunhao
2026-11-04 19:59:06 +08:00
parent f1aa0399aa
commit 78fe73d0db
576 changed files with 18075 additions and 18912 deletions
+211 -397
View File
@@ -18,26 +18,17 @@ For commercial licensing, please contact support@quantumnous.com
*/
import React, { useEffect, useState, useContext } from 'react';
import { Segmented } from 'antd';
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';
Progress,
} from '@/components/ui';
import { ArrowUpRight, Crown, Zap, Check, Clock } from 'lucide-react';
import { useTranslation } from 'react-i18next';
import { UserContext } from '../../context/User';
import { API, showError, showSuccess, renderQuota } from '../../helpers';
@@ -45,45 +36,11 @@ import MembershipHistoryModal from '../../components/membership/MembershipHistor
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: '高频使用首选',
},
weekly: { label: '周卡' },
monthly: { label: '月卡' },
quarterly: { label: '季卡' },
};
const MembershipPanel = () => {
@@ -332,359 +289,216 @@ const MembershipPanel = () => {
return new Date(timestamp * 1000).toLocaleDateString('zh-CN');
};
// 原型展示固定的周卡/月卡/季卡三个时长,没有方案的时长显示“待补充”空态
const periodKeys = [
...Object.keys(planTypeConfig),
...typeKeys.filter((type) => !planTypeConfig[type]),
];
const currentPeriod = periodKeys.includes(activeType)
? activeType
: periodKeys[0];
const periodPlans = plansByType[currentPeriod] || [];
return (
<div className='space-y-4'>
{/* 当前会员状态卡片 */}
<div className='rc-membership'>
{/* 当前会员状态 */}
{!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 (
<div className='rc-member-status'>
<div className='rc-member-status-head'>
<strong>{t('当前会员')}</strong>
<span>
<Tag color='blue' size='small'>
{membershipInfo.plan_name}
</Tag>{' '}
<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'
}
`}
type='button'
className='rc-section-link'
onClick={() => setHistoryModalVisible(true)}
>
<TypeIcon size={16} />
{config.label}
{t('查看记录')}
</button>
);
})}
</span>
</div>
<div className='rc-member-status-grid'>
<div>
<span className='rc-label'>{t('今日剩余额度')}</span>
<strong>{renderQuota(membershipInfo.membership_quota)}</strong>
</div>
<div>
<span className='rc-label'>{t('每日额度')}</span>
<strong>{renderQuota(membershipInfo.daily_quota)}</strong>
</div>
</div>
{membershipInfo.daily_quota > 0 && (
<Progress
percent={Math.round(
(membershipInfo.membership_quota / membershipInfo.daily_quota) *
100,
)}
showInfo
size='small'
aria-label={t('今日用量')}
/>
)}
<div className='rc-member-status-meta'>
<span>
{t('到期日')}: {formatDate(membershipInfo.end_date)}
</span>
<span>
{t('剩余')} {membershipInfo.remaining_days} {t('天')}
</span>
</div>
{/* 已续费提示 */}
{membershipInfo.has_future_membership && (
<Banner
type='success'
closeIcon={null}
description={
t('已续费') +
':' +
membershipInfo.future_plan_name +
',' +
formatDate(membershipInfo.future_start_date) +
' ~ ' +
formatDate(membershipInfo.future_end_date) +
' ' +
t('生效')
}
/>
)}
</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 className='rc-segmented rc-member-type'>
<Segmented
value={currentPeriod}
onChange={setActiveType}
options={periodKeys.map((type) => ({
value: type,
label: t(planTypeConfig[type]?.label || type),
}))}
/>
</div>
{plans.length === 0 && (
<Empty
title={t('暂无可用方案')}
description={t('管理员尚未配置会员方案')}
/>
)}
<section className='rc-section'>
<div className='rc-section-head'>
<div>
<h3>{t('选择适合你的会员')}</h3>
<p className='rc-section-desc'>
{description ||
t(
'会员额度每日重置,优先消耗;用完后切换账户余额,不自动续费。',
)}
</p>
</div>
<button
type='button'
className='rc-section-link'
onClick={() => setHistoryModalVisible(true)}
>
{t('购买记录')}
</button>
</div>
{plans.length === 0 ? (
<div className='rc-plan-empty'>
<Empty
title={t('暂无可用方案')}
description={t('管理员尚未配置会员方案')}
/>
</div>
) : periodPlans.length === 0 ? (
<div className='rc-plan-empty'>
<Clock size={18} />
<strong>
{t(planTypeConfig[currentPeriod]?.label || currentPeriod)}
{t('套餐')}
</strong>
<span>{t('价格与权益待补充')}</span>
</div>
) : (
<div className='rc-plan-grid'>
{periodPlans.map((plan) => {
const isSelected = selectedPlan?.id === plan.id;
const isCurrentPlan = isCurrentPlanCheck(plan);
const canUpgrade = canUpgradeCheck(plan);
const isDowngrade = isDowngradeCheck(plan);
const hasFuture = hasFutureForPlan(plan);
// 按钮文案沿用原有续费/升级/到期生效判断
let btnText = t('立即订阅');
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 (
<button
key={plan.id}
type='button'
onClick={() => handlePlanClick(plan)}
aria-pressed={isSelected}
className={`rc-plan ${isSelected ? 'selected' : ''}`}
>
{(plan.badge || plan.is_recommend) && (
<span className='rc-plan-badge'>
{plan.badge || t('推荐')}
</span>
)}
<span className='rc-plan-name'>{plan.name}</span>
<span className='rc-plan-price'>
<small>¥</small>
<strong>
{Number(plan.price).toLocaleString('en-US')}
</strong>
<span>
/ {plan.duration_days} {t('天')}
</span>
</span>
<span className='rc-plan-quota'>
<span>{t('每日额度')}</span>
<strong>{renderQuota(plan.daily_quota)}</strong>
</span>
{plan.description && (
<span className='rc-plan-desc'>{plan.description}</span>
)}
<ul className='rc-plan-features'>
<li>
<Check size={12} />
{t('每日自动重置额度')}
</li>
<li>
<Check size={12} />
{t('会员额度优先消耗')}
</li>
<li>
<Check size={12} />
{t('额度用完转账户余额')}
</li>
</ul>
<span className='rc-plan-foot'>
<span>
{btnText}
{subText && <small>{subText}</small>}
</span>
{isSelected ? (
<Check size={14} />
) : (
<ArrowUpRight size={14} />
)}
</span>
</button>
);
})}
</div>
)}
</section>
{/* 购买确认弹窗 */}
<Modal
@@ -714,7 +528,7 @@ const MembershipPanel = () => {
>
{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='p-4 rounded-lg'>
<div className='flex justify-between items-center mb-2'>
<Text strong className='text-lg'>
{selectedPlan.name}
@@ -893,7 +707,7 @@ const MembershipPanel = () => {
{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='p-4 rounded-lg'>
<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'>
@@ -927,7 +741,7 @@ const MembershipPanel = () => {
</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='p-4 rounded-lg'>
<div className='flex justify-between items-center mb-2'>
<Text className='text-gray-500'>{t('剩余会员天数')}</Text>
<Text strong>