修复刷新页面后停止按钮消失:从后端任务派生 activeBatchIds 驱动停止按钮显示与停止目标
This commit is contained in:
@@ -447,6 +447,17 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind })
|
||||
return set;
|
||||
}, [visibleTasks]);
|
||||
|
||||
// 从后端任务派生正在运行的批次 ID(刷新页面后仍可恢复,用于显示停止按钮)
|
||||
const activeBatchIds = useMemo(() => {
|
||||
const set = new Set<string>();
|
||||
for (const task of visibleTasks) {
|
||||
if (['pending', 'running', 'planned'].includes(task.status) && task.batch_id) {
|
||||
set.add(task.batch_id);
|
||||
}
|
||||
}
|
||||
return set;
|
||||
}, [visibleTasks]);
|
||||
|
||||
const selectedHasRunning = selectedIds.some((id) => runningAccountIds.has(id));
|
||||
|
||||
// 有活跃任务或 WS 连接时 3 秒刷 tasks;空闲 15 秒轻量刷新
|
||||
@@ -595,9 +606,10 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind })
|
||||
};
|
||||
|
||||
const stopBatch = async () => {
|
||||
if (runningBatchIds.size === 0) return;
|
||||
const ids = Array.from(new Set([...runningBatchIds, ...activeBatchIds]));
|
||||
if (ids.length === 0) return;
|
||||
try {
|
||||
await Promise.all(Array.from(runningBatchIds).map((id) => douyuApi.stopBatch(id)));
|
||||
await Promise.all(ids.map((id) => douyuApi.stopBatch(id)));
|
||||
message.success('已停止');
|
||||
} catch (error) {
|
||||
message.error(getErrorMessage(error));
|
||||
@@ -1122,7 +1134,7 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind })
|
||||
<Space>
|
||||
<Button icon={<ReloadOutlined />} onClick={loadData} loading={loading}>刷新</Button>
|
||||
{canConfig && <Button icon={<SettingOutlined />} onClick={() => setConfigOpen(true)}>配置</Button>}
|
||||
{runningBatchIds.size > 0 && <Button danger icon={<StopOutlined />} onClick={stopBatch}>停止</Button>}
|
||||
{(activeBatchIds.size > 0 || runningBatchIds.size > 0) && <Button danger icon={<StopOutlined />} onClick={stopBatch}>停止</Button>}
|
||||
</Space>
|
||||
</Space>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user