6160a23117
同步基准:总仓库 a2ca13cb(= 本仓库初始导入 d8f3aee2) 范围:a2ca13cb..bfdfb339 中触及 web/ 的提交(不含 web/.claude/settings.local.json) - 8490ac02 feat(aliyun): integrate Wan 3 and Qwen Image models - 2aff08ec perf(analytics): 运营看板概览改读汇总表,首屏从 19s 降到 0.4s - dc69335e feat(experience): 体验中心图像/视频创作升级(能力 schema、估价、新创作台) - b059c657 fix(org): 下线 /org/create 自助加入企业页与 POST /api/org/join - 4fcf47e6 fix(i18n): 修复中/英/韩/繁体多语言错乱,补齐日/越/泰译文 - e4c301d5 fix: merge enterprise task record date filters - c9369b95 feat: expose enterprise image and video task records - a410fee5 feat(claude): 无断点请求自动注入 cache_control 断点(方案 2) - 521b3376 feat(claude): 缓存命中率优化——上游粘性路由 + 缓存时长强制改写 - 73b615dd feat(pricing): 企业成员不论登录身份均按所属企业等级计价与扣费 - f73f55c3 feat(client): 新增 WeyAi 版本说明管理与公开读取接口 - 8cdf1994 fix(topup): reset amount when switching from PayPal - 93a4ac34 feat(baidu): configure Seedance liveness header by channel - cb1818c5 fix(weyai): 按评审修正内容清理竞态、默认适用端与中文退回(M21) - 04214d83 feat(weyai): WeyAi 内容管理与客户端内容接口(M21 第二部分) - e3c4a57c feat(weyai): 设置页新增 WeyAi 页签与内容专用 COS 桶(M21 第一部分) - b5ee8e70 fix(auth): 会话角色/状态以 DB 为准,修复提升管理员后管理接口报权限不足 - e4618fc2 fix: 修复企业看板日志聚合死循环导致 CPU 打满,并降低看板查询开销 - 584aad52 style(web): 个人中心侧边栏按 prettier 换行 - b8d87064 fix: 小程序教程隐藏充值后保留原步骤编号,企业充值判断直接用 isMiniProgramWebView - eee7f5b2 fix: 小程序里企业首页不落到充值页,隐藏钱包入口与教程充值步骤 - 8b254d49 fix: 小程序里隐藏企业充值入口与页面 - a67661b4 fix(web): 小程序里个人中心默认页跳过充值和发票,避免来回跳转 - cff6c543 feat(web): WeyAi 小程序里打开个人中心时不出现充值和开票 - c6c99eb6 feat(billing): Claude 全部缓存写入统一按 1h 倍率计费 - 0699d1bf fix(web): 小程序 web-view 里注册页同样只显示站内方式 - 04853331 feat(web): WeyAi 小程序 web-view 里登录页只显示站内登录方式
409 lines
12 KiB
React
409 lines
12 KiB
React
/*
|
|
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, {
|
|
useState,
|
|
useEffect,
|
|
useCallback,
|
|
useRef,
|
|
useMemo,
|
|
} from 'react';
|
|
import {
|
|
Modal,
|
|
Table,
|
|
Tag,
|
|
Empty,
|
|
Typography,
|
|
Pagination,
|
|
Toast,
|
|
} from '@douyinfe/semi-ui';
|
|
import { Crown, Clock, CheckCircle, XCircle, Calendar } from 'lucide-react';
|
|
import i18next from 'i18next';
|
|
import { API, renderQuota } from '../../helpers';
|
|
import {
|
|
IllustrationNoResult,
|
|
IllustrationNoResultDark,
|
|
} from '../common/illustrations';
|
|
|
|
const { Text } = Typography;
|
|
|
|
// 会员状态配置
|
|
const STATUS_CONFIG = {
|
|
active: {
|
|
label: '生效中',
|
|
type: 'success',
|
|
icon: CheckCircle,
|
|
color: 'text-emerald-500',
|
|
},
|
|
expired: {
|
|
label: '已过期',
|
|
type: 'default',
|
|
icon: XCircle,
|
|
color: 'text-gray-400',
|
|
},
|
|
pending: {
|
|
label: '待生效',
|
|
type: 'warning',
|
|
icon: Clock,
|
|
color: 'text-amber-500',
|
|
},
|
|
canceled: {
|
|
label: '已取消',
|
|
type: 'default',
|
|
icon: XCircle,
|
|
color: 'text-red-400',
|
|
},
|
|
};
|
|
|
|
// 方案类型映射
|
|
const PLAN_TYPE_MAP = {
|
|
weekly: '周卡',
|
|
monthly: '月卡',
|
|
quarterly: '季卡',
|
|
};
|
|
|
|
// 档位映射
|
|
const TIER_MAP = {
|
|
lite: '轻度版',
|
|
pro: '重度版',
|
|
};
|
|
|
|
const MembershipHistoryModal = ({ visible, onClose, t }) => {
|
|
const [loading, setLoading] = useState(false);
|
|
const [memberships, setMemberships] = useState([]);
|
|
const [total, setTotal] = useState(0);
|
|
const [activeCount, setActiveCount] = useState(0);
|
|
const [pendingCount, setPendingCount] = useState(0);
|
|
const [page, setPage] = useState(1);
|
|
const [pageSize, setPageSize] = useState(10);
|
|
|
|
// 格式化时间戳为日期字符串(使用 useCallback 避免每次渲染都创建新函数)
|
|
const formatDate = useCallback((timestamp) => {
|
|
if (!timestamp) return '-';
|
|
return new Date(timestamp * 1000).toLocaleDateString(i18next.language, {
|
|
year: 'numeric',
|
|
month: '2-digit',
|
|
day: '2-digit',
|
|
});
|
|
}, []);
|
|
|
|
// 格式化时间戳为完整时间字符串
|
|
const formatDateTime = useCallback((timestamp) => {
|
|
if (!timestamp) return '-';
|
|
return new Date(timestamp * 1000).toLocaleString(i18next.language, {
|
|
year: 'numeric',
|
|
month: '2-digit',
|
|
day: '2-digit',
|
|
hour: '2-digit',
|
|
minute: '2-digit',
|
|
});
|
|
}, []);
|
|
|
|
// 计算会员状态
|
|
const getMembershipStatus = (membership) => {
|
|
const now = Math.floor(Date.now() / 1000);
|
|
if (membership.status === 'canceled') return 'canceled';
|
|
if (membership.status === 'expired') return 'expired';
|
|
if (membership.start_date > now && membership.status === 'active')
|
|
return 'pending';
|
|
if (membership.end_date > now && membership.status === 'active')
|
|
return 'active';
|
|
return 'expired';
|
|
};
|
|
|
|
// 加载会员购买历史
|
|
const loadMembershipHistory = async (currentPage, currentPageSize) => {
|
|
setLoading(true);
|
|
try {
|
|
const res = await API.get(
|
|
`/api/user/membership/history?page=${currentPage}&page_size=${currentPageSize}`,
|
|
);
|
|
const { success, data, message } = res.data;
|
|
if (success) {
|
|
setMemberships(data.list || []);
|
|
setTotal(data.total || 0);
|
|
setActiveCount(data.active_count || 0);
|
|
setPendingCount(data.pending_count || 0);
|
|
} else {
|
|
console.error('加载会员历史失败:', message);
|
|
Toast.error({ content: message || t('加载失败'), duration: 3 });
|
|
}
|
|
} catch (error) {
|
|
console.error('Load membership history error:', error);
|
|
Toast.error({
|
|
content: t('加载会员购买记录失败,请稍后重试'),
|
|
duration: 3,
|
|
});
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
};
|
|
|
|
// 追踪上一次 visible 状态,用于检测弹窗刚打开的时机
|
|
const prevVisibleRef = useRef(false);
|
|
|
|
useEffect(() => {
|
|
if (visible && !prevVisibleRef.current) {
|
|
// 弹窗刚打开:重置到第一页
|
|
prevVisibleRef.current = true;
|
|
if (page !== 1) {
|
|
setPage(1); // page 变化会再次触发此 effect,届时加载数据
|
|
return;
|
|
}
|
|
loadMembershipHistory(1, pageSize);
|
|
return;
|
|
}
|
|
if (!visible) {
|
|
prevVisibleRef.current = false;
|
|
return;
|
|
}
|
|
// 弹窗已打开状态下翻页 / 切换每页条数
|
|
loadMembershipHistory(page, pageSize);
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [visible, page, pageSize]);
|
|
|
|
// 渲染状态标签
|
|
const renderStatusTag = (membership) => {
|
|
const status = getMembershipStatus(membership);
|
|
const config = STATUS_CONFIG[status] || STATUS_CONFIG.expired;
|
|
const IconComponent = config.icon;
|
|
|
|
return (
|
|
<div className={`flex items-center gap-1.5 ${config.color}`}>
|
|
<IconComponent size={14} />
|
|
<span className='text-xs font-medium'>{t(config.label)}</span>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
// 表格列定义(使用 useCallback 的格式化函数作为依赖)
|
|
const columns = useMemo(
|
|
() => [
|
|
{
|
|
title: t('方案名称'),
|
|
dataIndex: 'plan_name',
|
|
key: 'plan_name',
|
|
width: 180,
|
|
render: (text, record) => (
|
|
<div className='flex items-center gap-2'>
|
|
<div className='w-8 h-8 rounded-lg bg-gradient-to-br from-brand-from to-brand-to flex items-center justify-center flex-shrink-0'>
|
|
<Crown size={14} className='text-white' />
|
|
</div>
|
|
<div>
|
|
<Text strong className='text-sm block'>
|
|
{text || '-'}
|
|
</Text>
|
|
<Text className='text-xs text-gray-400'>
|
|
{PLAN_TYPE_MAP[record.plan_type]
|
|
? t(PLAN_TYPE_MAP[record.plan_type])
|
|
: record.plan_type}{' '}
|
|
·{' '}
|
|
{TIER_MAP[record.tier] ? t(TIER_MAP[record.tier]) : record.tier}
|
|
</Text>
|
|
</div>
|
|
</div>
|
|
),
|
|
},
|
|
{
|
|
title: t('每日额度'),
|
|
dataIndex: 'daily_quota',
|
|
key: 'daily_quota',
|
|
width: 120,
|
|
render: (quota) => (
|
|
<Text strong className='text-emerald-600 text-sm'>
|
|
{renderQuota(quota)}
|
|
</Text>
|
|
),
|
|
},
|
|
{
|
|
title: t('天数'),
|
|
key: 'duration_days',
|
|
width: 80,
|
|
align: 'center',
|
|
render: (_, record) => {
|
|
// duration_days 不在 UserMembership 模型中,需从 end_date - start_date 计算
|
|
const days =
|
|
record.end_date && record.start_date
|
|
? Math.round((record.end_date - record.start_date) / 86400)
|
|
: '-';
|
|
return (
|
|
<Tag color='blue' size='small'>
|
|
{t('{{days}} 天', { days })}
|
|
</Tag>
|
|
);
|
|
},
|
|
},
|
|
{
|
|
title: t('购买价格'),
|
|
dataIndex: 'price_paid',
|
|
key: 'price_paid',
|
|
width: 100,
|
|
render: (price) => (
|
|
<Text type='danger' className='text-sm'>
|
|
¥{price?.toFixed(2) || '0.00'}
|
|
</Text>
|
|
),
|
|
},
|
|
{
|
|
title: t('生效日期'),
|
|
dataIndex: 'start_date',
|
|
key: 'start_date',
|
|
width: 110,
|
|
render: (date) => (
|
|
<div className='flex items-center gap-1'>
|
|
<Calendar size={12} className='text-gray-400' />
|
|
<Text size='small' type='tertiary'>
|
|
{formatDate(date)}
|
|
</Text>
|
|
</div>
|
|
),
|
|
},
|
|
{
|
|
title: t('到期日期'),
|
|
dataIndex: 'end_date',
|
|
key: 'end_date',
|
|
width: 110,
|
|
render: (date) => (
|
|
<div className='flex items-center gap-1'>
|
|
<Calendar size={12} className='text-gray-400' />
|
|
<Text size='small' type='tertiary'>
|
|
{formatDate(date)}
|
|
</Text>
|
|
</div>
|
|
),
|
|
},
|
|
{
|
|
title: t('状态'),
|
|
key: 'status',
|
|
width: 100,
|
|
render: (_, record) => renderStatusTag(record),
|
|
},
|
|
{
|
|
title: t('购买时间'),
|
|
dataIndex: 'created_at',
|
|
key: 'created_at',
|
|
width: 140,
|
|
render: (time) => (
|
|
<Text size='small' type='tertiary'>
|
|
{formatDateTime(time)}
|
|
</Text>
|
|
),
|
|
},
|
|
],
|
|
[t, formatDate, formatDateTime],
|
|
);
|
|
|
|
return (
|
|
<Modal
|
|
title={
|
|
<div className='flex items-center gap-2'>
|
|
<div className='w-8 h-8 rounded-lg bg-gradient-to-br from-brand-from to-brand-to flex items-center justify-center'>
|
|
<Crown size={16} className='text-white' />
|
|
</div>
|
|
<span>{t('会员购买记录')}</span>
|
|
</div>
|
|
}
|
|
visible={visible}
|
|
onCancel={onClose}
|
|
footer={null}
|
|
width={1100}
|
|
bodyStyle={{ padding: 0, maxHeight: '70vh' }}
|
|
style={{ top: 40 }}
|
|
>
|
|
<div className='flex flex-col h-full'>
|
|
{/* 统计信息 */}
|
|
{total > 0 && (
|
|
<div className='px-6 py-4 bg-gradient-to-r from-brand-from/5 to-brand-to/5 dark:from-brand-from/20 dark:to-brand-to/20 border-b border-gray-200 dark:border-gray-700'>
|
|
<div className='flex items-center gap-6'>
|
|
<div className='flex items-center gap-2'>
|
|
<Text className='text-gray-500 text-sm'>
|
|
{t('总购买次数')}:
|
|
</Text>
|
|
<Text strong className='text-lg text-brand-deep'>
|
|
{total}
|
|
</Text>
|
|
</div>
|
|
<div className='flex items-center gap-2'>
|
|
<Text className='text-gray-500 text-sm'>{t('生效中')}:</Text>
|
|
<Text strong className='text-lg text-emerald-600'>
|
|
{activeCount}
|
|
</Text>
|
|
</div>
|
|
<div className='flex items-center gap-2'>
|
|
<Text className='text-gray-500 text-sm'>{t('待生效')}:</Text>
|
|
<Text strong className='text-lg text-amber-600'>
|
|
{pendingCount}
|
|
</Text>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)}
|
|
|
|
{/* 表格区域 */}
|
|
<div className='flex-1 overflow-auto p-6'>
|
|
<Table
|
|
columns={columns}
|
|
dataSource={memberships}
|
|
loading={loading}
|
|
rowKey='id'
|
|
size='small'
|
|
pagination={false}
|
|
empty={
|
|
<Empty
|
|
image={
|
|
<IllustrationNoResult style={{ width: 100, height: 100 }} />
|
|
}
|
|
darkModeImage={
|
|
<IllustrationNoResultDark
|
|
style={{ width: 100, height: 100 }}
|
|
/>
|
|
}
|
|
description={t('暂无会员购买记录')}
|
|
style={{ padding: 40 }}
|
|
/>
|
|
}
|
|
/>
|
|
</div>
|
|
|
|
{/* 分页器 */}
|
|
{total > 0 && (
|
|
<div className='px-6 py-4 border-t border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-neutral-900'>
|
|
<Pagination
|
|
total={total}
|
|
currentPage={page}
|
|
pageSize={pageSize}
|
|
showSizeChanger
|
|
pageSizeOpts={[10, 20, 50]}
|
|
onPageChange={(p) => setPage(p)}
|
|
onPageSizeChange={(size) => {
|
|
setPageSize(size);
|
|
setPage(1);
|
|
}}
|
|
showTotal
|
|
style={{ justifyContent: 'flex-end' }}
|
|
/>
|
|
</div>
|
|
)}
|
|
</div>
|
|
</Modal>
|
|
);
|
|
};
|
|
|
|
export default MembershipHistoryModal;
|