feat: 实现订单日报系统

- 创建订单日报系统,支持每天8:01自动生成前一天(早8点到当天早8点)的日报
- 新建两个数据库表:t_daily_report_config(配置表)和 t_daily_report_history(历史表)
- 原表 t_equipment_charge_order 只读取不修改,严格遵守用户要求
- 支持按企业ID或用户ID拆分日报,用户ID会提示是企业用户还是普通用户
- 用户可自定义选择报表字段,所有字段使用中文显示
- 实现配置管理、日报生成、历史查看的完整功能
- 代码检查全部通过,静态检查无错误

Coze-Commit-Type: user
Coze-User-ID: 3722323274763196
Coze-Conversation-ID: 9894087
This commit is contained in:
user9994793890
2026-07-07 16:14:42 +08:00
parent b6a1b77054
commit ba91796dc1
21 changed files with 2734 additions and 253 deletions

View File

@@ -0,0 +1,89 @@
import { NextRequest, NextResponse } from 'next/server';
import pool from '@/lib/db';
// PUT - 更新配置
export async function PUT(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
) {
try {
const body = await request.json();
const { config_name, split_type, selected_fields, is_active } = body;
const { id: configId } = await params;
// 构建更新字段
const updateFields: string[] = [];
const updateValues: any[] = [];
if (config_name) {
updateFields.push('config_name = ?');
updateValues.push(config_name);
}
if (split_type) {
updateFields.push('split_type = ?');
updateValues.push(split_type);
}
if (selected_fields) {
updateFields.push('selected_fields = ?');
updateValues.push(JSON.stringify(selected_fields));
}
if (is_active !== undefined) {
updateFields.push('is_active = ?');
updateValues.push(is_active);
}
if (updateFields.length === 0) {
return NextResponse.json({
success: false,
message: '没有要更新的字段'
}, { status: 400 });
}
updateValues.push(configId);
await pool.execute(
`UPDATE t_daily_report_config SET ${updateFields.join(', ')} WHERE id = ?`,
updateValues
);
return NextResponse.json({
success: true,
message: '配置更新成功'
});
} catch (error) {
return NextResponse.json({
success: false,
message: '更新配置失败',
error: error instanceof Error ? error.message : '未知错误'
}, { status: 500 });
}
}
// DELETE - 删除配置(设置为禁用)
export async function DELETE(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
) {
try {
const { id: configId } = await params;
await pool.execute(
'UPDATE t_daily_report_config SET is_active = 0 WHERE id = ?',
[configId]
);
return NextResponse.json({
success: true,
message: '配置已禁用'
});
} catch (error) {
return NextResponse.json({
success: false,
message: '禁用配置失败',
error: error instanceof Error ? error.message : '未知错误'
}, { status: 500 });
}
}

View File

@@ -0,0 +1,67 @@
import { NextRequest, NextResponse } from 'next/server';
import pool from '@/lib/db';
import { getAllFields } from '@/lib/field-mapping';
// GET - 获取所有配置
export async function GET() {
try {
const [configs] = await pool.execute<any[]>(
'SELECT * FROM t_daily_report_config WHERE is_active = 1 ORDER BY create_time DESC'
);
return NextResponse.json({
success: true,
data: configs,
availableFields: getAllFields()
});
} catch (error) {
return NextResponse.json({
success: false,
message: '获取配置失败',
error: error instanceof Error ? error.message : '未知错误'
}, { status: 500 });
}
}
// POST - 创建新配置
export async function POST(request: NextRequest) {
try {
const body = await request.json();
const { config_name, split_type, selected_fields } = body;
// 验证必填字段
if (!config_name || !split_type || !selected_fields || selected_fields.length === 0) {
return NextResponse.json({
success: false,
message: '缺少必填字段'
}, { status: 400 });
}
// 验证拆分方式
if (split_type !== 'company_id' && split_type !== 'user_id') {
return NextResponse.json({
success: false,
message: '拆分方式必须是 company_id 或 user_id'
}, { status: 400 });
}
// 插入配置
const [result] = await pool.execute(
`INSERT INTO t_daily_report_config (config_name, split_type, selected_fields)
VALUES (?, ?, ?)`,
[config_name, split_type, JSON.stringify(selected_fields)]
);
return NextResponse.json({
success: true,
message: '配置创建成功',
data: result
});
} catch (error) {
return NextResponse.json({
success: false,
message: '创建配置失败',
error: error instanceof Error ? error.message : '未知错误'
}, { status: 500 });
}
}

View File

@@ -0,0 +1,65 @@
import { NextRequest, NextResponse } from 'next/server';
import pool from '@/lib/db';
// GET - 获取企业列表或用户列表
export async function GET(request: NextRequest) {
try {
const { searchParams } = new URL(request.url);
const type = searchParams.get('type'); // 'company' 或 'user'
if (type === 'company') {
// 获取企业列表(根据company_id分组,并统计订单数量)
const [companies] = await pool.execute(`
SELECT
company_id,
COUNT(*) as order_count,
SUM(actual_pay_amount) as total_amount
FROM t_equipment_charge_order
WHERE state = 3 AND company_id IS NOT NULL
GROUP BY company_id
ORDER BY order_count DESC
`);
return NextResponse.json({
success: true,
data: companies,
type: '企业'
});
} else if (type === 'user') {
// 获取用户列表(根据user_id分组,区分企业用户和普通用户)
const [users] = await pool.execute(`
SELECT
user_id,
order_type,
COUNT(*) as order_count,
SUM(actual_pay_amount) as total_amount,
CASE
WHEN order_type = 3 THEN '企业用户'
WHEN order_type = 1 THEN '普通用户'
ELSE '其他类型'
END as user_type_label
FROM t_equipment_charge_order
WHERE state = 3
GROUP BY user_id, order_type
ORDER BY order_count DESC
`);
return NextResponse.json({
success: true,
data: users,
type: '用户'
});
} else {
return NextResponse.json({
success: false,
message: '类型参数必须为 company 或 user'
}, { status: 400 });
}
} catch (error) {
return NextResponse.json({
success: false,
message: '获取数据失败',
error: error instanceof Error ? error.message : '未知错误'
}, { status: 500 });
}
}

View File

@@ -0,0 +1,22 @@
import { NextResponse } from 'next/server';
import { initDatabaseTables } from '@/lib/init-tables';
export async function POST() {
try {
await initDatabaseTables();
return NextResponse.json({
success: true,
message: '数据库表初始化成功',
createdTables: [
't_daily_report_config - 日报字段配置表',
't_daily_report_history - 日报生成历史表'
]
});
} catch (error) {
return NextResponse.json({
success: false,
message: '数据库表初始化失败',
error: error instanceof Error ? error.message : '未知错误'
}, { status: 500 });
}
}

View File

@@ -0,0 +1,42 @@
import { NextRequest, NextResponse } from 'next/server';
import { generateDailyReport, generateBatchReports } from '@/lib/report-generator';
// POST - 生成日报
export async function POST(request: NextRequest) {
try {
const body = await request.json();
const { split_type, split_value, selected_fields, report_date, config_id } = body;
// 如果提供了config_id,则批量生成所有企业/用户的日报
if (config_id) {
const results = await generateBatchReports(config_id);
return NextResponse.json({
success: true,
message: '批量日报生成完成',
data: results
});
}
// 否则生成单个企业/用户的日报
if (!split_type || !split_value || !selected_fields || selected_fields.length === 0) {
return NextResponse.json({
success: false,
message: '缺少必填字段'
}, { status: 400 });
}
const result = await generateDailyReport(split_type, split_value, selected_fields, report_date);
return NextResponse.json({
success: result.success,
message: result.success ? '日报生成成功' : result.error,
data: result
});
} catch (error) {
return NextResponse.json({
success: false,
message: '生成日报失败',
error: error instanceof Error ? error.message : '未知错误'
}, { status: 500 });
}
}

View File

@@ -0,0 +1,63 @@
import { NextRequest, NextResponse } from 'next/server';
import pool from '@/lib/db';
// GET - 获取日报历史记录
export async function GET(request: NextRequest) {
try {
const { searchParams } = new URL(request.url);
const page = parseInt(searchParams.get('page') || '1');
const pageSize = parseInt(searchParams.get('pageSize') || '20');
const splitType = searchParams.get('splitType');
const reportDate = searchParams.get('reportDate');
// 构建查询条件
let whereClause = 'WHERE 1=1';
const queryParams: any[] = [];
if (splitType) {
whereClause += ' AND split_type = ?';
queryParams.push(splitType);
}
if (reportDate) {
whereClause += ' AND report_date = ?';
queryParams.push(reportDate);
}
// 查询总数
const [countResult] = await pool.execute(
`SELECT COUNT(*) as total FROM t_daily_report_history ${whereClause}`,
queryParams
);
const total = (countResult as any[])[0].total;
// 查询数据
const offset = (page - 1) * pageSize;
queryParams.push(offset, pageSize);
const [history] = await pool.execute(
`SELECT * FROM t_daily_report_history ${whereClause}
ORDER BY create_time DESC
LIMIT ?, ?`,
queryParams
);
return NextResponse.json({
success: true,
data: history,
pagination: {
page,
pageSize,
total,
totalPages: Math.ceil(total / pageSize)
}
});
} catch (error) {
return NextResponse.json({
success: false,
message: '获取历史记录失败',
error: error instanceof Error ? error.message : '未知错误'
}, { status: 500 });
}
}

View File

@@ -0,0 +1,25 @@
import { NextResponse } from 'next/server';
import { testConnection } from '@/lib/db';
export async function GET() {
try {
const isConnected = await testConnection();
if (isConnected) {
return NextResponse.json({
success: true,
message: '数据库连接成功'
});
} else {
return NextResponse.json({
success: false,
message: '数据库连接失败'
}, { status: 500 });
}
} catch (error) {
return NextResponse.json({
success: false,
message: '数据库连接失败',
error: error instanceof Error ? error.message : '未知错误'
}, { status: 500 });
}
}

View File

@@ -1,35 +1,566 @@
import type { Metadata } from 'next';
import Image from 'next/image';
'use client';
export const metadata: Metadata = {
title: '扣子编程 - AI 开发伙伴',
description: '扣子编程,你的 AI 开发伙伴已就位',
};
import { useState, useEffect } from 'react';
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
import { Checkbox } from '@/components/ui/checkbox';
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table';
import { Badge } from '@/components/ui/badge';
import { toast } from '@/hooks/use-toast';
import { Toaster } from '@/components/ui/toaster';
export default function Home() {
const [configs, setConfigs] = useState<any[]>([]);
const [availableFields, setAvailableFields] = useState<any[]>([]);
const [companies, setCompanies] = useState<any[]>([]);
const [users, setUsers] = useState<any[]>([]);
const [history, setHistory] = useState<any[]>([]);
const [loading, setLoading] = useState(false);
// 配置表单
const [configName, setConfigName] = useState('');
const [splitType, setSplitType] = useState('company_id');
const [selectedFields, setSelectedFields] = useState<string[]>([]);
// 日报生成表单
const [reportSplitType, setReportSplitType] = useState('company_id');
const [reportSplitValue, setReportSplitValue] = useState('');
const [reportSelectedFields, setReportSelectedFields] = useState<string[]>([]);
const [reportDate, setReportDate] = useState('');
// 历史查询
const [historyPage, setHistoryPage] = useState(1);
const [historyTotal, setHistoryTotal] = useState(0);
useEffect(() => {
loadData();
}, []);
useEffect(() => {
if (splitType === 'company_id') {
loadCompanies();
} else {
loadUsers();
}
}, [splitType]);
useEffect(() => {
if (reportSplitType === 'company_id') {
loadCompanies();
} else {
loadUsers();
}
}, [reportSplitType]);
const loadData = async () => {
try {
// 加载配置和字段
const configRes = await fetch('/api/config');
const configData = await configRes.json();
if (configData.success) {
setConfigs(configData.data);
setAvailableFields(configData.availableFields);
}
// 加载历史
loadHistory();
} catch (error) {
console.error('加载数据失败:', error);
}
};
const loadCompanies = async () => {
try {
const res = await fetch('/api/entities?type=company');
const data = await res.json();
if (data.success) {
setCompanies(data.data);
}
} catch (error) {
console.error('加载企业列表失败:', error);
}
};
const loadUsers = async () => {
try {
const res = await fetch('/api/entities?type=user');
const data = await res.json();
if (data.success) {
setUsers(data.data);
}
} catch (error) {
console.error('加载用户列表失败:', error);
}
};
const loadHistory = async (page = 1) => {
try {
const res = await fetch(`/api/report/history?page=${page}&pageSize=10`);
const data = await res.json();
if (data.success) {
setHistory(data.data);
setHistoryTotal(data.pagination.total);
setHistoryPage(page);
}
} catch (error) {
console.error('加载历史记录失败:', error);
}
};
const handleCreateConfig = async () => {
if (!configName || selectedFields.length === 0) {
toast({
title: '错误',
description: '请填写配置名称并选择至少一个字段',
variant: 'destructive'
});
return;
}
setLoading(true);
try {
const res = await fetch('/api/config', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
config_name: configName,
split_type: splitType,
selected_fields: selectedFields
})
});
const data = await res.json();
if (data.success) {
toast({
title: '成功',
description: '配置创建成功'
});
loadData();
setConfigName('');
setSelectedFields([]);
} else {
toast({
title: '错误',
description: data.message,
variant: 'destructive'
});
}
} catch (error) {
toast({
title: '错误',
description: '创建配置失败',
variant: 'destructive'
});
}
setLoading(false);
};
const handleGenerateReport = async () => {
if (!reportSplitValue || reportSelectedFields.length === 0) {
toast({
title: '错误',
description: '请选择企业/用户并选择至少一个字段',
variant: 'destructive'
});
return;
}
setLoading(true);
try {
const res = await fetch('/api/report/generate', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
split_type: reportSplitType,
split_value: reportSplitValue,
selected_fields: reportSelectedFields,
report_date: reportDate
})
});
const data = await res.json();
if (data.success) {
toast({
title: '成功',
description: `日报生成成功,共 ${data.data.totalOrders} 条订单,总金额 ${data.data.totalAmount} 元`
});
loadHistory();
} else {
toast({
title: '错误',
description: data.message,
variant: 'destructive'
});
}
} catch (error) {
toast({
title: '错误',
description: '生成日报失败',
variant: 'destructive'
});
}
setLoading(false);
};
const handleDeleteConfig = async (id: string) => {
setLoading(true);
try {
const res = await fetch(`/api/config/${id}`, {
method: 'DELETE'
});
const data = await res.json();
if (data.success) {
toast({
title: '成功',
description: '配置已禁用'
});
loadData();
} else {
toast({
title: '错误',
description: data.message,
variant: 'destructive'
});
}
} catch (error) {
toast({
title: '错误',
description: '禁用配置失败',
variant: 'destructive'
});
}
setLoading(false);
};
const handleFieldChange = (field: string, checked: boolean, type: 'config' | 'report') => {
if (type === 'config') {
if (checked) {
setSelectedFields([...selectedFields, field]);
} else {
setSelectedFields(selectedFields.filter(f => f !== field));
}
} else {
if (checked) {
setReportSelectedFields([...reportSelectedFields, field]);
} else {
setReportSelectedFields(reportSelectedFields.filter(f => f !== field));
}
}
};
return (
<div className="flex h-full items-center justify-center bg-background text-foreground transition-colors duration-300 dark:bg-background dark:text-foreground overflow-hidden min-h-screen">
{/* 主容器 */}
<main className="flex w-full h-full max-w-3xl flex-col items-center justify-center px-16 py-32 sm:items-center">
<div className="flex flex-col items-center justify-between gap-4">
<Image
src="https://lf-coze-web-cdn.coze.cn/obj/eden-cn/lm-lgvj/ljhwZthlaukjlkulzlp/coze-coding/icon/coze-coding.gif"
alt="扣子编程 Logo"
width={156}
height={130}
/>
<div>
<div className="flex flex-col items-center gap-2 text-center sm:items-center sm:text-center">
<h1 className="max-w-xl text-base font-semibold leading-tight tracking-tight text-foreground dark:text-foreground">
应用开发中
</h1>
<p className="max-w-2xl text-sm leading-8 text-muted-foreground dark:text-muted-foreground">
请稍后,页面即将呈现
</p>
<div className="min-h-screen bg-gray-50 p-8">
<div className="max-w-7xl mx-auto">
<Card className="mb-6">
<CardHeader>
<CardTitle className="text-2xl">订单日报系统</CardTitle>
<CardDescription>
每天早8点自动生成前一天的订单日报(早8点到当天早8点)
</CardDescription>
</CardHeader>
</Card>
<Tabs defaultValue="config" className="space-y-4">
<TabsList className="grid w-full grid-cols-3">
<TabsTrigger value="config">配置管理</TabsTrigger>
<TabsTrigger value="generate">日报生成</TabsTrigger>
<TabsTrigger value="history">历史记录</TabsTrigger>
</TabsList>
<TabsContent value="config">
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
{/* 创建配置 */}
<Card>
<CardHeader>
<CardTitle>创建新配置</CardTitle>
<CardDescription>配置日报的字段和拆分方式</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
<div>
<Label htmlFor="configName">配置名称</Label>
<Input
id="configName"
value={configName}
onChange={(e) => setConfigName(e.target.value)}
placeholder="例如:企业日报配置"
/>
</div>
<div>
<Label htmlFor="splitType">拆分方式</Label>
<Select value={splitType} onValueChange={setSplitType}>
<SelectTrigger>
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="company_id">按企业ID拆分</SelectItem>
<SelectItem value="user_id">按用户ID拆分</SelectItem>
</SelectContent>
</Select>
</div>
<div>
<Label>选择字段(已选 {selectedFields.length} 个)</Label>
<div className="grid grid-cols-2 md:grid-cols-3 gap-2 mt-2 h-[300px] overflow-y-auto border rounded p-2">
{availableFields.map((field) => (
<div key={field.field} className="flex items-center space-x-2">
<Checkbox
id={`config-${field.field}`}
checked={selectedFields.includes(field.field)}
onCheckedChange={(checked) =>
handleFieldChange(field.field, checked as boolean, 'config')
}
/>
<Label htmlFor={`config-${field.field}`} className="text-sm">
{field.label}
</Label>
</div>
))}
</div>
</div>
<Button
onClick={handleCreateConfig}
disabled={loading}
className="w-full"
>
{loading ? '创建中...' : '创建配置'}
</Button>
</CardContent>
</Card>
{/* 配置列表 */}
<Card>
<CardHeader>
<CardTitle>现有配置</CardTitle>
<CardDescription>查看和管理已创建的配置</CardDescription>
</CardHeader>
<CardContent>
<Table>
<TableHeader>
<TableRow>
<TableHead>配置名称</TableHead>
<TableHead>拆分方式</TableHead>
<TableHead>字段数量</TableHead>
<TableHead>操作</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{configs.map((config) => (
<TableRow key={config.id}>
<TableCell>{config.config_name}</TableCell>
<TableCell>
<Badge variant={config.split_type === 'company_id' ? 'default' : 'secondary'}>
{config.split_type === 'company_id' ? '企业' : '用户'}
</Badge>
</TableCell>
<TableCell>
{JSON.parse(config.selected_fields).length} 个
</TableCell>
<TableCell>
<Button
variant="destructive"
size="sm"
onClick={() => handleDeleteConfig(config.id)}
disabled={loading}
>
禁用
</Button>
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</CardContent>
</Card>
</div>
</div>
</div>
</main>
</TabsContent>
<TabsContent value="generate">
<Card>
<CardHeader>
<CardTitle>手动生成日报</CardTitle>
<CardDescription>
选择企业/用户和字段,手动生成指定日期的日报
</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
<div>
<Label htmlFor="reportSplitType">拆分方式</Label>
<Select value={reportSplitType} onValueChange={setReportSplitType}>
<SelectTrigger>
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="company_id">按企业ID</SelectItem>
<SelectItem value="user_id">按用户ID</SelectItem>
</SelectContent>
</Select>
{reportSplitType === 'user_id' && (
<p className="text-sm text-muted-foreground mt-1">
注意:用户ID可能对应企业用户或普通用户
</p>
)}
</div>
<div>
<Label htmlFor="reportSplitValue">
{reportSplitType === 'company_id' ? '企业ID' : '用户ID'}
</Label>
<Select value={reportSplitValue} onValueChange={setReportSplitValue}>
<SelectTrigger>
<SelectValue placeholder="请选择" />
</SelectTrigger>
<SelectContent>
{reportSplitType === 'company_id'
? companies.map((company) => (
<SelectItem key={company.company_id} value={String(company.company_id)}>
企业ID: {company.company_id} ({company.order_count} 单)
</SelectItem>
))
: users.map((user) => (
<SelectItem key={`${user.user_id}-${user.order_type}`} value={String(user.user_id)}>
用户ID: {user.user_id} ({user.user_type_label}, {user.order_count} 单)
</SelectItem>
))
}
</SelectContent>
</Select>
</div>
<div>
<Label htmlFor="reportDate">报表日期(可选,默认昨天)</Label>
<Input
id="reportDate"
type="date"
value={reportDate}
onChange={(e) => setReportDate(e.target.value)}
/>
</div>
</div>
<div>
<Label>选择字段(已选 {reportSelectedFields.length} 个)</Label>
<div className="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-2 mt-2 h-[300px] overflow-y-auto border rounded p-2">
{availableFields.map((field) => (
<div key={field.field} className="flex items-center space-x-2">
<Checkbox
id={`report-${field.field}`}
checked={reportSelectedFields.includes(field.field)}
onCheckedChange={(checked) =>
handleFieldChange(field.field, checked as boolean, 'report')
}
/>
<Label htmlFor={`report-${field.field}`} className="text-sm">
{field.label}
</Label>
</div>
))}
</div>
</div>
<Button
onClick={handleGenerateReport}
disabled={loading}
className="w-full"
size="lg"
>
{loading ? '生成中...' : '生成日报'}
</Button>
</CardContent>
</Card>
</TabsContent>
<TabsContent value="history">
<Card>
<CardHeader>
<CardTitle>日报历史记录</CardTitle>
<CardDescription>查看已生成的日报历史</CardDescription>
</CardHeader>
<CardContent>
<Table>
<TableHeader>
<TableRow>
<TableHead>报表日期</TableHead>
<TableHead>拆分方式</TableHead>
<TableHead>拆分值</TableHead>
<TableHead>订单数</TableHead>
<TableHead>总金额</TableHead>
<TableHead>状态</TableHead>
<TableHead>生成时间</TableHead>
<TableHead>操作</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{history.map((record) => (
<TableRow key={record.id}>
<TableCell>{record.report_date}</TableCell>
<TableCell>
<Badge variant={record.split_type === 'company_id' ? 'default' : 'secondary'}>
{record.split_type === 'company_id' ? '企业' : '用户'}
</Badge>
</TableCell>
<TableCell>{record.split_value}</TableCell>
<TableCell>{record.total_orders}</TableCell>
<TableCell>¥{record.total_amount}</TableCell>
<TableCell>
<Badge variant={record.status === 1 ? 'default' : 'destructive'}>
{record.status === 1 ? '成功' : '失败'}
</Badge>
</TableCell>
<TableCell>
{new Date(record.create_time).toLocaleString()}
</TableCell>
<TableCell>
{record.file_path && (
<Button
variant="outline"
size="sm"
onClick={() => window.open(record.file_path, '_blank')}
>
下载
</Button>
)}
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
{historyTotal > 10 && (
<div className="flex justify-center gap-2 mt-4">
<Button
variant="outline"
disabled={historyPage === 1}
onClick={() => loadHistory(historyPage - 1)}
>
上一页
</Button>
<span className="flex items-center">
第 {historyPage} 页,共 {Math.ceil(historyTotal / 10)} 页
</span>
<Button
variant="outline"
disabled={historyPage >= Math.ceil(historyTotal / 10)}
onClick={() => loadHistory(historyPage + 1)}
>
下一页
</Button>
</div>
)}
</CardContent>
</Card>
</TabsContent>
</Tabs>
</div>
<Toaster />
</div>
);
}
}