/* PDF 转换管理页:拉取 /api/admin/pdf/jobs、渲染表格(含「是否已删除」列)、硬删。 */ (function () { "use strict"; const { el, toast, fmtBytes, fmtTime, api } = window.ZK; const listEl = document.getElementById("list"); const countEl = document.getElementById("count"); const refreshBtn = document.getElementById("refresh"); refreshBtn.addEventListener("click", load); async function load() { listEl.innerHTML = '
加载中…
'; countEl.textContent = ""; try { const res = await api("/api/admin/pdf/jobs?limit=500&offset=0"); if (!res.ok) throw new Error("HTTP " + res.status); const body = await res.json(); render(body.items || []); countEl.textContent = `共 ${body.total} 个任务`; } catch (e) { listEl.innerHTML = '
加载失败:' + (e.message || e) + "
"; } } function render(items) { if (!items.length) { listEl.innerHTML = '
还没有任务。
'; return; } const table = el("table", { class: "jobs-table admin-table" }); const thead = el("thead", null, el("tr", null, el("th", { class: "col-name" }, "文件名"), el("th", { class: "col-size" }, "大小"), el("th", { class: "col-status" }, "状态"), el("th", { class: "col-del" }, "是否已删除"), el("th", { class: "col-time" }, "创建时间"), el("th", { class: "col-act" }, "操作") ) ); const tbody = el("tbody", null); for (const j of items) tbody.appendChild(renderRow(j)); table.appendChild(thead); table.appendChild(tbody); listEl.innerHTML = ""; listEl.appendChild(table); } function renderRow(j) { const row = el("tr", { class: j.user_deleted ? "row-soft-deleted" : "" }, el("td", { class: "col-name" }, j.source_filename), el("td", { class: "col-size mono" }, fmtBytes(j.source_size)), el("td", { class: "col-status" }, statusCell(j)), el("td", { class: "col-del" }, deletedCell(j)), el("td", { class: "col-time muted" }, fmtTime(j.created_at)), el("td", { class: "col-act" }, j.status === "done" ? el("a", { class: "btn", href: `/api/admin/files/${j.output_file_id}/download`, download: "" }, "下载产物") : el("span", { class: "muted" }, "-"), el("button", { class: "btn danger", onclick: () => remove(j, row) }, "硬删") ) ); return row; } function statusCell(j) { if (j.status === "done") return el("span", { class: "tag ok" }, "完成"); if (j.status === "failed") return el("span", { class: "tag err", title: j.error_message || "" }, "失败"); return el("span", { class: "tag warn" }, j.status === "converting" ? `转换中 ${j.progress}%` : "排队中"); } function deletedCell(j) { if (j.user_deleted) { return el("span", { class: "tag err", title: fmtTime(j.deleted_at) }, "已删除"); } return el("span", { class: "muted" }, "否"); } async function remove(j, row) { if (!confirm(`确定硬删「${j.source_filename}」?\n将真正删除原始文件与产物 PDF(磁盘 + 记录),不可恢复。`)) return; try { const res = await api(`/api/admin/pdf/jobs/${j.id}`, { method: "DELETE" }); if (res.status === 404) { toast("任务已不存在"); } else if (!res.ok) throw new Error("HTTP " + res.status); row.classList.add("row-removed"); setTimeout(() => row.remove(), 250); toast("已硬删"); const m = (countEl.textContent || "").match(/(\d+)/); if (m) countEl.textContent = `共 ${Math.max(0, Number(m[1]) - 1)} 个任务`; } catch (e) { toast("删除失败:" + (e.message || e), "err"); } } load(); })();