fix: 增加任务详情自动刷新
This commit is contained in:
@@ -71,6 +71,26 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
updateScaleHint();
|
||||
});
|
||||
|
||||
function pollTaskDetailStatus(taskId) {
|
||||
if (!taskId) return;
|
||||
const intervalMs = 3000;
|
||||
const poll = async () => {
|
||||
try {
|
||||
const resp = await fetch(`/api/tasks/${taskId}`, { cache: "no-store" });
|
||||
if (!resp.ok) return;
|
||||
const task = await resp.json();
|
||||
if (task.status !== "running") {
|
||||
window.location.reload();
|
||||
return;
|
||||
}
|
||||
} catch (_error) {
|
||||
return;
|
||||
}
|
||||
window.setTimeout(poll, intervalMs);
|
||||
};
|
||||
window.setTimeout(poll, intervalMs);
|
||||
}
|
||||
|
||||
async function downloadExport(url, defaultFilename, event) {
|
||||
if (event) event.preventDefault();
|
||||
const resp = await fetch(url);
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
{% block content %}
|
||||
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||
<h1 class="h3 mb-0">任务 #{{ task.id }}</h1>
|
||||
<button class="btn btn-outline-secondary btn-sm" onclick="window.location.href='/'">手动刷新</button>
|
||||
<button class="btn btn-outline-secondary btn-sm" onclick="window.location.reload()">手动刷新</button>
|
||||
</div>
|
||||
<section class="card mb-4"><div class="card-body">
|
||||
<section class="card mb-4" {% if task.status == "running" %}data-task-id="{{ task.id }}" data-auto-poll="true"{% endif %}><div class="card-body">
|
||||
{% set label, cls = status_badge_config(task.status) %}
|
||||
<p>平台:{{ task.platform | platform_label }} <span class="badge {{ cls }}">{{ label }}</span></p>
|
||||
<p>成功 {{ task.successful_items_count }} / 共 {{ task.total_items_count }} 条内容</p>
|
||||
@@ -19,6 +19,7 @@
|
||||
</div></section>
|
||||
{% if task.status == "running" and not hotspots %}
|
||||
<div class="text-center text-muted py-5"><div class="spinner-border text-warning mb-3"></div><p>正在抓取热点数据,请稍候...</p></div>
|
||||
<script>pollTaskDetailStatus("{{ task.id }}");</script>
|
||||
{% endif %}
|
||||
<div class="accordion" id="hotspot-list">
|
||||
{% for hotspot in hotspots %}
|
||||
|
||||
Reference in New Issue
Block a user