import { useCallback, useEffect, useState } from 'react' import { useSearchParams } from 'react-router-dom' import { Download, ListChecks, Sparkles, Upload } from 'lucide-react' import clsx from 'clsx' import { scraperAPI } from '../api/scraper' import { strmAPI } from '../api/strm' import { ScraperQueuePage } from './ScraperQueuePage' import { StrmQueuePanel } from './StrmQueuePage' type QueueType = 'all' | 'scrape' | 'download' | 'upload' const QUEUE_TABS: { type: QueueType; label: string; icon: typeof ListChecks }[] = [ { type: 'all', label: '全部', icon: ListChecks }, { type: 'scrape', label: '刮削队列', icon: Sparkles }, { type: 'download', label: '下载队列', icon: Download }, { type: 'upload', label: '上传队列', icon: Upload }, ] function normalizeType(raw: string | null): QueueType { if (raw === 'scrape' || raw === 'download' || raw === 'upload' || raw === 'all') { return raw } return 'all' } /** * 任务队列:整合刮削 / 下载 / 上传 三类队列的统一入口,按类型 Tab 区分。 * 单个类型视图直接复用原队列组件;「全部」纵向堆叠三个队列。 */ export function TaskQueuePage() { const [searchParams, setSearchParams] = useSearchParams() const type = normalizeType(searchParams.get('type')) const [scrapeCounts, setScrapeCounts] = useState | null>(null) const [downloadCounts, setDownloadCounts] = useState | null>(null) // StrmQueueCounts const [uploadCounts, setUploadCounts] = useState | null>(null) const loadOverview = useCallback(async () => { try { const scrape = await scraperAPI.queue(undefined, 1, 1) setScrapeCounts(scrape.counts as unknown as Record) } catch { setScrapeCounts(null) } try { const dl = await strmAPI.downloads(undefined, 1, 1) setDownloadCounts(dl.counts as unknown as Record) } catch { setDownloadCounts(null) } try { const ul = await strmAPI.uploads(undefined, 1, 1) setUploadCounts(ul.counts as unknown as Record) } catch { setUploadCounts(null) } }, []) useEffect(() => { loadOverview() }, [loadOverview]) const countBadge = (counts: Record | null) => { if (!counts) return null const total = Object.values(counts).reduce((a, b) => a + (b || 0), 0) return {total} } const switchType = (next: QueueType) => { setSearchParams(next === 'all' ? {} : { type: next }, { replace: true }) } return (

任务队列

刮削 / 下载 / 上传三类任务统一管理,按类型切换查看

{/* 类型 Tab */}
{QUEUE_TABS.map((tab) => { const active = type === tab.type const Icon = tab.icon const badge = tab.type === 'scrape' ? countBadge(scrapeCounts) : tab.type === 'download' ? countBadge(downloadCounts) : tab.type === 'upload' ? countBadge(uploadCounts) : null return ( ) })}
{/* 内容 */} {type === 'scrape' && } {type === 'download' && } {type === 'upload' && } {type === 'all' && (

刮削队列

下载队列

上传队列

)}
) }