"use client"; import { useState, useEffect, useCallback } from "react"; import { motion } from "motion/react"; import { Card, CardContent, CardHeader, CardTitle, } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Badge } from "@/components/ui/badge"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table"; import { Download, FileText, Receipt, BarChart3, Loader2, Search, } from "lucide-react"; import { api } from "@/lib/api/client"; interface ExportRecord { id: number; task_id: number; type: string; format: string; status: string; file_name: string; created_at: string; } const typeLabels: Record = { cost_analysis: "成本分析", voucher: "会计凭证", exception: "异常清单", reconciliation: "对账结果", }; const formatLabels: Record = { csv: "CSV", excel: "Excel", pdf: "PDF", }; const statusConfig: Record = { COMPLETED: { label: "已完成", color: "bg-emerald-100 text-emerald-700 dark:bg-emerald-900/40 dark:text-emerald-300" }, PROCESSING: { label: "处理中", color: "bg-blue-100 text-blue-700 dark:bg-blue-900/40 dark:text-blue-300" }, FAILED: { label: "失败", color: "bg-red-100 text-red-700 dark:bg-red-900/40 dark:text-red-300" }, }; export default function ExportsPage() { const [records, setRecords] = useState([]); const [loading, setLoading] = useState(true); const [taskId, setTaskId] = useState(""); const loadRecords = useCallback(async () => { setLoading(true); try { const params: Record = {}; if (taskId) params.task_id = taskId; const res = await api.get<{ items: ExportRecord[] }>("/api/exports/list", { params }); setRecords(res.data.items || []); } catch (error) { console.error("加载导出记录失败:", error); setRecords([]); } finally { setLoading(false); } }, [taskId]); useEffect(() => { loadRecords(); }, [loadRecords]); function handleExport(type: string) { if (!taskId) return; const token = localStorage.getItem("auth_token"); const companyId = localStorage.getItem("company_id"); const url = `${process.env.NEXT_PUBLIC_API_URL}/api/exports/task/${taskId}?type=${type}`; fetch(url, { headers: { Authorization: `Bearer ${token}`, "X-Company-ID": companyId || "", }, }) .then((res) => res.blob()) .then((blob) => { const a = document.createElement("a"); a.href = URL.createObjectURL(blob); a.download = `export_${taskId}_${type}.xlsx`; a.click(); URL.revokeObjectURL(a.href); }); } const quickExports = [ { title: "成本分析导出", desc: "导出人工成本分析 Excel", icon: BarChart3, type: "cost_analysis", color: "text-violet-500", bgColor: "bg-violet-500/10", }, { title: "凭证导出 (金蝶CSV)", desc: "导出金蝶 K3 格式凭证", icon: Receipt, type: "voucher_csv", color: "text-emerald-500", bgColor: "bg-emerald-500/10", }, { title: "凭证导出 (Excel)", desc: "导出 Excel 格式凭证", icon: FileText, type: "voucher_excel", color: "text-blue-500", bgColor: "bg-blue-500/10", }, ]; return (

导出中心

集中管理和导出各类财务数据

setTaskId(e.target.value)} className="h-9" />

快捷导出

{quickExports.map((action) => { const Icon = action.icon; return ( handleExport(action.type)}>

{action.title}

{action.desc}

); })}
导出记录 任务ID 类型 格式 状态 文件名 时间 {loading ? ( ) : records.length === 0 ? (

暂无导出记录

) : ( records.map((record) => ( #{record.task_id} {typeLabels[record.type] || record.type} {formatLabels[record.format] || record.format} {statusConfig[record.status]?.label || record.status} {record.file_name} {new Date(record.created_at).toLocaleString("zh-CN")} )) )}
); }