/* index page: 小说列表 dashboard. */ import { escapeHtml, fetchJson } from "../utils.js"; import { statusBadge } from "../components/status-badge.js"; function renderCard(n) { const target = n.target_words || 0; const current = n.current_words || 0; const pct = target > 0 ? Math.min(100, Math.round((current / target) * 100)) : 0; return '' + '
' + '
' + '
' + '
' + escapeHtml(n.title) + '
' + '

' + ' ' + escapeHtml(n.genre || "未分类") + ' ' + statusBadge(n.status) + '

' + '

' + escapeHtml(n.style || "") + '

' + '
' + '
' + pct + '%
' + '
' + '

' + current + ' / ' + target + ' 字

' + ' 打开' + '
' + '
' + '
'; } async function loadNovels() { const container = document.getElementById("novelCards"); try { const novels = await fetchJson("/api/novels"); if (!novels.length) { container.innerHTML = '
还没有小说, 点击右上角"拆书创建新小说"开始。
'; return; } container.innerHTML = novels.map(renderCard).join(""); } catch (err) { container.innerHTML = '
加载失败: ' + escapeHtml(err.message) + "
"; } } loadNovels();