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
+358
View File
@@ -0,0 +1,358 @@
/*
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, useMemo } from 'react';
import {
Card,
Typography,
Input,
Table,
Empty,
Button,
Modal,
Toast,
Pagination,
} from '@douyinfe/semi-ui';
import { IconSearch } from '@douyinfe/semi-icons';
import {
IllustrationNoResult,
IllustrationNoResultDark,
} from '../../components/common/illustrations';
import {
Receipt,
Sparkles,
Clock,
CheckCircle,
AlertCircle,
XCircle,
} from 'lucide-react';
import { API, timestamp2string } from '../../helpers';
import { isAdmin } from '../../helpers/utils';
const { Text, Title } = Typography;
// 状态映射
const STATUS_CONFIG = {
success: {
type: 'success',
key: '成功',
icon: CheckCircle,
color: 'text-emerald-500',
},
pending: {
type: 'warning',
key: '待支付',
icon: Clock,
color: 'text-amber-500',
},
expired: {
type: 'danger',
key: '已过期',
icon: XCircle,
color: 'text-red-500',
},
};
const HistoryPanel = ({ t, refreshTrigger }) => {
const [loading, setLoading] = useState(false);
const [topups, setTopups] = useState([]);
const [total, setTotal] = useState(0);
const [page, setPage] = useState(1);
const [pageSize, setPageSize] = useState(10);
const [keyword, setKeyword] = useState('');
const userIsAdmin = useMemo(() => isAdmin(), []);
// 加载充值记录
const loadTopups = async (currentPage, currentPageSize) => {
setLoading(true);
try {
const base = userIsAdmin ? '/api/user/topup' : '/api/user/topup/self';
const qs =
`p=${currentPage}&page_size=${currentPageSize}` +
(keyword ? `&keyword=${encodeURIComponent(keyword)}` : '');
const endpoint = `${base}?${qs}`;
const res = await API.get(endpoint);
const { success, message, data } = res.data;
if (success) {
setTopups(data.items || []);
setTotal(data.total || 0);
} else {
Toast.error({ content: message || t('加载失败') });
}
} catch (error) {
console.error('Load topups error:', error);
Toast.error({ content: t('加载账单失败') });
} finally {
setLoading(false);
}
};
useEffect(() => {
loadTopups(page, pageSize);
}, [page, pageSize, keyword, refreshTrigger]);
// 管理员补单
const handleAdminComplete = async (tradeNo) => {
try {
const res = await API.post('/api/user/topup/complete', {
trade_no: tradeNo,
});
const { success, message } = res.data;
if (success) {
Toast.success({ content: t('补单成功') });
await loadTopups(page, pageSize);
} else {
Toast.error({ content: message || t('补单失败') });
}
} catch (e) {
Toast.error({ content: t('补单失败') });
}
};
const confirmAdminComplete = (tradeNo) => {
Modal.confirm({
title: t('确认补单'),
content: t('是否将该订单标记为成功并为用户入账?'),
onOk: () => handleAdminComplete(tradeNo),
});
};
// 渲染状态徽章
const renderStatusBadge = (status) => {
const config = STATUS_CONFIG[status] || {
type: 'primary',
key: status,
icon: AlertCircle,
color: 'text-gray-500',
};
const IconComponent = config.icon;
return (
<span className={`flex items-center gap-1.5 ${config.color}`}>
<IconComponent size={14} />
<span className='text-xs font-medium'>{t(config.key)}</span>
</span>
);
};
// 表格列定义
const columns = useMemo(() => {
const baseColumns = [
{
title: t('订单号'),
dataIndex: 'trade_no',
key: 'trade_no',
width: 240,
render: (text) => (
<Text
copyable={{ content: text }}
size='small'
className='font-mono'
ellipsis={{ showTooltip: true }}
style={{ maxWidth: 200 }}
>
{text || '-'}
</Text>
),
},
{
title: t('支付'),
dataIndex: 'money',
key: 'money',
width: 80,
render: (money) => (
<Text type='danger' size='small'>
¥{money?.toFixed(2)}
</Text>
),
},
{
title: t('状态'),
dataIndex: 'status',
key: 'status',
width: 80,
render: renderStatusBadge,
},
{
title: t('时间'),
dataIndex: 'create_time',
key: 'create_time',
width: 100,
render: (time) => (
<Text size='small' type='tertiary'>
{timestamp2string(time).slice(5, 16)}
</Text>
),
},
];
// 管理员显示操作列
if (userIsAdmin) {
baseColumns.push({
title: t('操作'),
key: 'action',
width: 60,
render: (_, record) => {
if (record.status !== 'pending') return null;
return (
<Button
size='small'
theme='outline'
onClick={() => confirmAdminComplete(record.trade_no)}
>
{t('补单')}
</Button>
);
},
});
}
return baseColumns;
}, [t, userIsAdmin]);
return (
<div className='relative'>
{/* 外层发光效果 - 与 RechargePanel 对齐 */}
<div className='absolute -inset-0.5 bg-gradient-to-br from-emerald-400/20 via-teal-400/20 to-cyan-400/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 overflow-hidden'
style={{
display: 'flex',
flexDirection: 'column',
maxHeight: 'calc(100vh - 160px)',
}}
bodyStyle={{
flex: 1,
display: 'flex',
flexDirection: 'column',
minHeight: 0,
overflow: 'hidden',
}}
>
{/* 顶部装饰线 */}
<div className='absolute top-0 left-0 right-0 h-1 bg-gradient-to-r from-emerald-500 via-teal-500 to-cyan-500' />
{/* 背景装饰 */}
<div className='absolute top-0 right-0 w-64 h-64 bg-gradient-to-br from-emerald-400/10 to-teal-400/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-cyan-400/10 to-blue-400/10 rounded-full blur-3xl -ml-24 -mb-24 pointer-events-none' />
{/* 这层必须是 flex 列并参与父级伸缩:Card 的 bodyStyle 已经是
flex-column + minHeight:0 + overflow:hidden,但中间隔着这个普通块级 div,
下面表格区的 flex-1/min-h-0 与分页的 flex-shrink-0 就都不是 flex 项了——
每页选 20/50 条时表格会顶破 maxHeight 被裁掉,分页控件跟着滚出可视区。 */}
<div className='relative flex-1 min-h-0 flex flex-col'>
{/* 头部 */}
<div className='flex items-center justify-between mb-3 flex-shrink-0'>
<div className='flex items-center gap-3'>
<div className='relative'>
<div className='absolute -inset-1 bg-gradient-to-br from-emerald-500/40 to-teal-500/40 rounded-xl blur-md' />
<div className='relative w-10 h-10 rounded-xl bg-gradient-to-br from-emerald-500 to-teal-600 flex items-center justify-center shadow-lg shadow-emerald-500/30'>
<Receipt 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-emerald-600 to-teal-600 dark:from-emerald-400 dark:to-teal-400'
>
{t('充值记录')}
</Title>
<Text type='tertiary' size='small'>
{t('查看历史充值订单')}
</Text>
</div>
</div>
</div>
{/* 搜索框 */}
<div className='mb-3 flex-shrink-0'>
<div className='relative group'>
<div className='absolute -inset-0.5 bg-gradient-to-r from-emerald-400/20 to-teal-400/20 rounded-xl blur-sm opacity-0 group-hover:opacity-100 transition-opacity' />
<Input
prefix={<IconSearch className='text-emerald-500' />}
placeholder={t('搜索订单号')}
value={keyword}
onChange={(value) => {
setKeyword(value);
setPage(1);
}}
showClear
className='!rounded-xl relative'
/>
</div>
</div>
{/* 表格区域 - 可滚动 */}
<div className='flex-1 overflow-auto min-h-0 image-list-scroll rounded-xl bg-white/40 dark:bg-neutral-800/30 backdrop-blur-sm border border-white/60 dark:border-neutral-700/40'>
<Table
columns={columns}
dataSource={topups}
loading={loading}
rowKey='id'
size='small'
pagination={false}
className='history-table'
empty={
<Empty
image={
<IllustrationNoResult style={{ width: 100, height: 100 }} />
}
darkModeImage={
<IllustrationNoResultDark
style={{ width: 100, height: 100 }}
/>
}
description={t('暂无充值记录')}
style={{ padding: 20 }}
/>
}
/>
</div>
{/* 分页器 - 固定在底部 */}
{total > 0 && (
<div className='flex-shrink-0 pt-3 border-t border-gray-100 dark:border-gray-700 mt-3'>
<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>
</Card>
</div>
);
};
export default HistoryPanel;