'use client'; import React from 'react'; import { TaskStatistics } from '@/api/video_flow'; interface TaskStatusChartProps { statistics: TaskStatistics[]; } export default function TaskStatusChart({ statistics }: TaskStatusChartProps) { // 聚合所有项目的状态数据 const aggregatedData = React.useMemo(() => { if (statistics.length === 0) { return []; } const totals = statistics.reduce( (acc, stat) => ({ completed: acc.completed + stat.status_stats.completed, in_progress: acc.in_progress + stat.status_stats.in_progress, pending: acc.pending + stat.status_stats.pending, failed: acc.failed + stat.status_stats.failed, blocked: acc.blocked + stat.status_stats.blocked, }), { completed: 0, in_progress: 0, pending: 0, failed: 0, blocked: 0, } ); const total = Object.values(totals).reduce((sum, val) => sum + val, 0); return [ { name: '已完成', value: totals.completed, color: '#10b981', percentage: total > 0 ? (totals.completed / total) * 100 : 0 }, { name: '进行中', value: totals.in_progress, color: '#3b82f6', percentage: total > 0 ? (totals.in_progress / total) * 100 : 0 }, { name: '等待中', value: totals.pending, color: '#f59e0b', percentage: total > 0 ? (totals.pending / total) * 100 : 0 }, { name: '失败', value: totals.failed, color: '#ef4444', percentage: total > 0 ? (totals.failed / total) * 100 : 0 }, { name: '阻塞', value: totals.blocked, color: '#f97316', percentage: total > 0 ? (totals.blocked / total) * 100 : 0 }, ].filter(item => item.value > 0); }, [statistics]); // 简单的饼图实现 const PieChart = ({ data }: { data: typeof aggregatedData }) => { const total = data.reduce((sum, item) => sum + item.value, 0); let cumulativePercentage = 0; return (