'use client';
import React from 'react';
import { useDownload } from '@/contexts/DownloadContext';
import { M3U8DownloadTask } from '@/lib/m3u8-downloader';
export function DownloadPanel() {
const { tasks, showDownloadPanel, setShowDownloadPanel, startTask, pauseTask, cancelTask, retryFailedSegments, getProgress } = useDownload();
if (!showDownloadPanel) {
return null;
}
const getStatusText = (status: M3U8DownloadTask['status']) => {
switch (status) {
case 'ready':
return '等待中';
case 'downloading':
return '下载中';
case 'pause':
return '已暂停';
case 'done':
return '已完成';
case 'error':
return '错误';
default:
return '未知';
}
};
const getStatusColor = (status: M3U8DownloadTask['status']) => {
switch (status) {
case 'ready':
return 'text-gray-500';
case 'downloading':
return 'text-blue-500';
case 'pause':
return 'text-yellow-500';
case 'done':
return 'text-green-500';
case 'error':
return 'text-red-500';
default:
return 'text-gray-500';
}
};
return (
{/* 标题栏 */}
下载任务列表
{/* 任务列表 */}
{tasks.length === 0 ? (
) : (
tasks.map((task) => {
const progress = getProgress(task.id);
return (
{/* 任务信息 */}
{getStatusText(task.status)}
{task.type}
{/* 进度条 */}
{task.finishNum} / {task.rangeDownload.targetSegment} 片段
{progress.toFixed(1)}%
{/* 错误信息 */}
{task.errorNum > 0 && (
{task.errorNum} 个片段下载失败
)}
{/* 操作按钮 */}
{task.status === 'downloading' && (
)}
{(task.status === 'pause' || task.status === 'ready' || task.status === 'error') && (
)}
);
})
)}
{/* 底部统计 */}
{tasks.length > 0 && (
总任务数: {tasks.length}
下载中: {tasks.filter(t => t.status === 'downloading').length}
已完成: {tasks.filter(t => t.status === 'done').length}
已暂停: {tasks.filter(t => t.status === 'pause').length}
)}
);
}