import React, { useEffect, useState } from 'react'; import { Table, Tag, Empty, Spin, Typography, Row, Col, Pagination } from 'antd'; import { WalletOutlined, PlusCircleOutlined, ThunderboltOutlined } from '@ant-design/icons'; import { getCredits } from '../api'; const CreditRecordsPage: React.FC = () => { const [loading, setLoading] = useState(true); const [records, setRecords] = useState([]); const [credits, setCredits] = useState(0); const [total, setTotal] = useState(0); const [page, setPage] = useState(1); const [pageSize] = useState(10); useEffect(() => { loadData(); }, [page]); const loadData = async () => { setLoading(true); try { const data = await getCredits(page, pageSize); setRecords(data.records || []); setCredits(data.credits || 0); setTotal(data.total || 0); } catch { setRecords([]); } setLoading(false); }; const handlePageChange = (newPage: number) => { setPage(newPage); }; const columns = [ { title: '变动类型', dataIndex: 'type', key: 'type', width: 120, render: (text: string) => { const typeConfig: Record = { recharge: { color: '#10b981', label: '充值', bg: 'rgba(16,185,129,0.1)' }, consume: { color: '#ef4444', label: '消费', bg: 'rgba(239,68,68,0.1)' }, admin: { color: '#f59e0b', label: '管理员调整', bg: 'rgba(245,158,11,0.1)' }, refund: { color: '#8b5cf6', label: '退款', bg: 'rgba(139,92,246,0.1)' }, team_internal: { color: '#0958d9', label: '团队内部', bg: 'rgba(139,92,246,0.1)' }, }; const config = typeConfig[text] || { color: '#64748b', label: text, bg: 'rgba(100,116,139,0.1)' }; return ( {config.label} ); }, }, { title: '描述', dataIndex: 'description', key: 'description', ellipsis: true, }, { title: '变动积分', dataIndex: 'amount', key: 'amount', width: 120, align: 'right' as const, render: (amount: number) => ( 0 ? '#10b981' : '#ef4444', fontSize: 15 }}> {amount > 0 ? '+' : ''}{amount} ), }, { title: '创建时间', key: 'createdAt', width: 180, render: (_, record: any) => { const createdAt = record.created_at || record.createdAt || record.create_time || record.createTime; return createdAt ? new Date(createdAt).toLocaleString('zh-CN') : '-'; }, }, ]; return (
可用积分
{credits.toLocaleString()}
累计获得
{records.filter((r: any) => r.amount > 0).reduce((sum: number, r: any) => sum + r.amount, 0).toLocaleString()}
累计消耗
{records.filter((r: any) => r.amount < 0).reduce((sum: number, r: any) => sum + Math.abs(r.amount), 0).toLocaleString()}
积分明细
{records.length === 0 ? ( 暂无积分变动记录} /> ) : ( <>
)} ); }; export default CreditRecordsPage;