分页优化
This commit is contained in:
+66
-11
@@ -425,21 +425,42 @@ function startApplyPoll() {
|
||||
}
|
||||
|
||||
// ==========================================================
|
||||
// Step 5: 历史与统计
|
||||
// Step 5: 历史与统计(筛选 + 分页)
|
||||
// ==========================================================
|
||||
const histState = { range: 'today', start: '', end: '', type: '', page: 1, pageSize: 20 };
|
||||
|
||||
function fmtDate(d) {
|
||||
return d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0')
|
||||
+ '-' + String(d.getDate()).padStart(2, '0');
|
||||
}
|
||||
function histRangeDates() {
|
||||
const now = new Date(), today = fmtDate(now);
|
||||
if (histState.range === 'today') return [today, today];
|
||||
if (histState.range === 'week') {
|
||||
const d = new Date(now); d.setDate(d.getDate() - ((d.getDay() + 6) % 7)); // 周一
|
||||
return [fmtDate(d), today];
|
||||
}
|
||||
if (histState.range === 'month') {
|
||||
return [fmtDate(new Date(now.getFullYear(), now.getMonth(), 1)), today];
|
||||
}
|
||||
return [histState.start, histState.end]; // 自定义
|
||||
}
|
||||
|
||||
async function loadHistory() {
|
||||
try {
|
||||
const [stats, history] = await Promise.all([
|
||||
api('/api/stats'),
|
||||
api('/api/history?limit=50'),
|
||||
]);
|
||||
const [start, end] = histRangeDates();
|
||||
if (histState.range === 'custom' && (!start || !end)) return;
|
||||
const params = new URLSearchParams({ page: histState.page, page_size: histState.pageSize });
|
||||
if (start) params.set('start', start);
|
||||
if (end) params.set('end', end);
|
||||
if (histState.type) params.set('apply_type', histState.type);
|
||||
const d = await api('/api/history-page?' + params);
|
||||
$('statsGrid').innerHTML = `
|
||||
<div class="stat-card"><div class="num">${stats.total_applied || 0}</div><div class="label">累计投递</div></div>
|
||||
<div class="stat-card"><div class="num">${stats.total_chat || 0}</div><div class="label">立即沟通</div></div>
|
||||
<div class="stat-card"><div class="num">${stats.total_deliver || 0}</div><div class="label">投递简历</div></div>
|
||||
<div class="stat-card"><div class="num">${stats.today_applied || 0}</div><div class="label">今日投递</div></div>
|
||||
<div class="stat-card"><div class="num">${d.applied || 0}</div><div class="label">已投递(筛选范围)</div></div>
|
||||
<div class="stat-card"><div class="num">${d.skipped || 0}</div><div class="label">已跳过(筛选范围)</div></div>
|
||||
<div class="stat-card"><div class="num">${d.total || 0}</div><div class="label">处理总数(筛选范围)</div></div>
|
||||
`;
|
||||
$('historyBody').innerHTML = history.map(h => `
|
||||
$('historyBody').innerHTML = (d.items || []).map(h => `
|
||||
<tr>
|
||||
<td title="${escapeHtml(recordDetail(h))}">${escapeHtml(h.job_title || '-')}</td>
|
||||
<td>${escapeHtml(h.company || '-')}</td>
|
||||
@@ -448,7 +469,10 @@ async function loadHistory() {
|
||||
<td>${h.ai_score >= 0 ? h.ai_score : '-'}</td>
|
||||
<td>${formatTime(h.applied_at)}</td>
|
||||
</tr>
|
||||
`).join('') || '<tr><td colspan="6" style="text-align:center;color:#999">暂无记录</td></tr>';
|
||||
`).join('') || '<tr><td colspan="6" style="text-align:center;color:#999">该筛选条件下暂无记录</td></tr>';
|
||||
$('histPageInfo').textContent = `共 ${d.total} 条 · 第 ${d.page} / ${Math.max(d.pages, 1)} 页`;
|
||||
$('btnHistPrev').disabled = d.page <= 1;
|
||||
$('btnHistNext').disabled = d.page >= d.pages;
|
||||
} catch (e) { console.error(e); }
|
||||
}
|
||||
|
||||
@@ -478,6 +502,37 @@ function escapeHtml(s) {
|
||||
}[c]));
|
||||
}
|
||||
|
||||
// ---------- 记录筛选/分页事件 ----------
|
||||
document.querySelectorAll('[data-hrange]').forEach(el => el.addEventListener('click', () => {
|
||||
document.querySelectorAll('[data-hrange]').forEach(c => c.classList.toggle('active', c === el));
|
||||
histState.range = el.dataset.hrange;
|
||||
$('histCustomRange').classList.toggle('hidden', histState.range !== 'custom');
|
||||
if (histState.range !== 'custom') { histState.page = 1; loadHistory(); }
|
||||
}));
|
||||
$('btnHistQuery').onclick = () => {
|
||||
histState.start = $('histDateStart').value;
|
||||
histState.end = $('histDateEnd').value;
|
||||
if (!histState.start || !histState.end) { toast('请选择起止日期'); return; }
|
||||
if (histState.start > histState.end) { toast('起始日期不能晚于结束日期'); return; }
|
||||
histState.page = 1; loadHistory();
|
||||
};
|
||||
document.querySelectorAll('[data-htype]').forEach(el => el.addEventListener('click', () => {
|
||||
document.querySelectorAll('[data-htype]').forEach(c => c.classList.toggle('active', c === el));
|
||||
histState.type = el.dataset.htype;
|
||||
histState.page = 1; loadHistory();
|
||||
}));
|
||||
$('histPageSize').onchange = e => {
|
||||
histState.pageSize = parseInt(e.target.value, 10);
|
||||
histState.page = 1; loadHistory();
|
||||
};
|
||||
$('btnHistPrev').onclick = () => { if (histState.page > 1) { histState.page--; loadHistory(); } };
|
||||
$('btnHistNext').onclick = () => { histState.page++; loadHistory(); };
|
||||
|
||||
// ---------- 启动 ----------
|
||||
{ // 自定义日期默认填入今天
|
||||
const today = fmtDate(new Date());
|
||||
$('histDateStart').value = today;
|
||||
$('histDateEnd').value = today;
|
||||
}
|
||||
refreshStatus();
|
||||
setInterval(refreshStatus, 8000);
|
||||
|
||||
@@ -314,6 +314,24 @@ body {
|
||||
.tag.deliver { background: #dbeafe; color: var(--primary); }
|
||||
.tag.skipped { background: #f3f4f6; color: var(--text-light); }
|
||||
|
||||
/* ===== 记录筛选栏与分页 ===== */
|
||||
.filters-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-bottom: 12px; font-size: 13px; }
|
||||
.filters-bar .grp { display: flex; align-items: center; gap: 6px; }
|
||||
.filters-bar .grp > label { color: var(--text-light); }
|
||||
.chip {
|
||||
padding: 4px 12px; border: 1px solid var(--border); border-radius: 14px;
|
||||
cursor: pointer; color: var(--text-light); background: #fff; font-size: 12px;
|
||||
}
|
||||
.chip:hover { border-color: var(--primary); color: var(--primary); }
|
||||
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
|
||||
.filters-bar input[type=date] { padding: 3px 6px; border: 1px solid var(--border); border-radius: 6px; font-size: 12px; }
|
||||
.filters-bar select { padding: 3px 6px; border: 1px solid var(--border); border-radius: 6px; font-size: 12px; }
|
||||
.btn-query { padding: 4px 14px; background: var(--primary); border: none; color: #fff; border-radius: 6px; cursor: pointer; font-size: 12px; }
|
||||
.pager-bar { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 12px; font-size: 13px; color: var(--text-light); }
|
||||
.pager-bar button { padding: 4px 12px; border: 1px solid var(--border); background: #fff; border-radius: 6px; cursor: pointer; font-size: 12px; }
|
||||
.pager-bar button:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
|
||||
.pager-bar button:disabled { color: #ccc; cursor: not-allowed; }
|
||||
|
||||
/* ===== Toast ===== */
|
||||
.toast {
|
||||
position: fixed;
|
||||
|
||||
Reference in New Issue
Block a user