From ce2d19466184f8500f9793d8eb687dd387ac334c Mon Sep 17 00:00:00 2001 From: ShukeBta <272197458+ShukeBta@users.noreply.github.com> Date: Wed, 24 Jun 2026 22:13:32 +0800 Subject: [PATCH] refactor: split task runtime tables --- web/src/pages/TaskRuntimeTables.tsx | 85 +++++++++++++++++++++++++++++ web/src/pages/TasksPage.tsx | 83 +--------------------------- 2 files changed, 88 insertions(+), 80 deletions(-) create mode 100644 web/src/pages/TaskRuntimeTables.tsx diff --git a/web/src/pages/TaskRuntimeTables.tsx b/web/src/pages/TaskRuntimeTables.tsx new file mode 100644 index 0000000..31ee618 --- /dev/null +++ b/web/src/pages/TaskRuntimeTables.tsx @@ -0,0 +1,85 @@ +import type { ActiveTranscode } from '../api/tasks' +import type { QBitTorrent } from '../types' + +function fmtBytes(n: number): string { + if (!n || n <= 0) return '0 B' + const u = ['B', 'KB', 'MB', 'GB', 'TB'] + let v = n + let i = 0 + while (v >= 1024 && i < u.length - 1) { + v /= 1024 + i++ + } + return `${v.toFixed(2)} ${u[i]}` +} + +export function TranscodeTaskTable({ transcodes }: { transcodes: ActiveTranscode[] }) { + if (transcodes.length === 0) return

暂无运行中转码。

+ return ( + + + + + + + + + + + {transcodes.map((t) => ( + + + + + + + ))} + +
媒体 ID编码器开始时间就绪
{t.media_id}{t.encoder || 'libx264'}{new Date(t.started_at).toLocaleTimeString()} + {t.playlist_ok ? ( + + ready + + ) : ( + + starting + + )} +
+ ) +} + +export function TorrentTaskTable({ torrents }: { torrents: QBitTorrent[] }) { + if (torrents.length === 0) return

暂无运行中下载。

+ return ( + + + + + + + + + + + {torrents.map((t) => ( + + + + + + + ))} + +
名称状态进度体积
+ {t.name} + {t.state} +
+
+
+
+ {(t.progress * 100).toFixed(1)}% +
+
{fmtBytes(t.size)}
+ ) +} diff --git a/web/src/pages/TasksPage.tsx b/web/src/pages/TasksPage.tsx index ea07172..6476c11 100644 --- a/web/src/pages/TasksPage.tsx +++ b/web/src/pages/TasksPage.tsx @@ -3,18 +3,7 @@ import toast from 'react-hot-toast' import { Activity, Copy } from 'lucide-react' import { tasksAPI, type BackgroundTask, type TasksSnapshot } from '../api/tasks' - -function fmtBytes(n: number): string { - if (!n || n <= 0) return '0 B' - const u = ['B', 'KB', 'MB', 'GB', 'TB'] - let v = n - let i = 0 - while (v >= 1024 && i < u.length - 1) { - v /= 1024 - i++ - } - return `${v.toFixed(2)} ${u[i]}` -} +import { TorrentTaskTable, TranscodeTaskTable } from './TaskRuntimeTables' const metricLabels: Record = { organized: '新增', @@ -208,78 +197,12 @@ export function TasksPage() {

转码任务

- {snap.transcodes.length === 0 &&

暂无运行中转码。

} - {snap.transcodes.length > 0 && ( - - - - - - - - - - - {snap.transcodes.map((t) => ( - - - - - - - ))} - -
媒体 ID编码器开始时间就绪
{t.media_id}{t.encoder || 'libx264'}{new Date(t.started_at).toLocaleTimeString()} - {t.playlist_ok ? ( - - ready - - ) : ( - - starting - - )} -
- )} +

下载任务

- {torrents.length === 0 &&

暂无运行中下载。

} - {torrents.length > 0 && ( - - - - - - - - - - - {torrents.map((t) => ( - - - - - - - ))} - -
名称状态进度体积
- {t.name} - {t.state} -
-
-
-
- {(t.progress * 100).toFixed(1)}% -
-
{fmtBytes(t.size)}
- )} +
)