Expose private operational evolution timeline

This commit is contained in:
wuyang
2026-11-03 17:29:10 +08:00
parent 20aea13054
commit 84fc19c965
6 changed files with 67 additions and 4 deletions
+45 -2
View File
@@ -6,6 +6,7 @@ const el = (tag, text, className) => {
return node;
};
let dashboard;
let currentReportId;
const labels = { views: '视频播放', likes: '点赞', followers: '关注人数', downloads: 'APK 下载', visits: '网页访问', videos_published: '已发布视频', comments: '评论', favorites: '收藏', coins: '投币', watch_time: '观看时长', completion_rate: '完播率', revenue: '收益', value: '数值', unit: '单位', source: '来源', status: '状态', note: '备注', observed_at: '观测时间', project: '项目', account: '账号', account_followers: '账号关注人数' };
const basisLabels = { cash: '实际现金', allocated: '套餐分摊', estimate: '预估', settled: '已结算' };
const categoryLabels = { subscription: '套餐', api: 'API', electricity: '电费', hosting: '托管', revenue: '收入', tokens: 'Token 用量' };
@@ -63,6 +64,7 @@ function budgetPanel() {
return section;
}
function renderReport(report) {
currentReportId = report?.id;
const content = $('#report-content'); content.replaceChildren();
const download = $('#download-report');
if (!report) {
@@ -103,7 +105,43 @@ function renderLedger() {
}
table.append(head, body); wrapper.append(table); host.append(wrapper);
}
function showView(view) {
const evolution = view === 'evolution';
$('#report-view').hidden = evolution; $('#evolution-view').hidden = !evolution;
for (const [selector, active] of [['#show-report', !evolution], ['#show-evolution', evolution]]) {
$(selector).classList.toggle('active', active); $(selector).setAttribute('aria-pressed', String(active));
}
}
function renderEvolution(data) {
const host = $('#evolution-content'); host.replaceChildren();
const events = Array.isArray(data?.events) ? data.events : [];
if (!events.length) { host.append(el('p', '还没有演变记录。后续探索与决策会在这里归档。', 'empty')); return; }
const timeline = el('div', undefined, 'timeline');
for (const event of events) {
const item = el('details', undefined, 'evolution-event');
const summary = el('summary');
const heading = el('span', undefined, 'event-heading');
const precision = { datetime: '精确时间', date: '日期', approximate: '约略时间', unknown: '时间待确认' }[event.occurred_at_precision] || event.occurred_at_precision;
const timing = event.occurred_at ? `发生:${dateTime(event.occurred_at)}${precision ? `(${precision})` : ''} · ` : (precision ? `发生时间:${precision} · ` : '');
heading.append(el('strong', valueText(event.change || event.trigger || event.id)), el('span', `${timing}记录:${dateTime(event.recorded_at)} · ${event.retrospective === true ? '早期补录' : event.retrospective === false ? '实时记录' : '记录方式待确认'}`, 'muted'));
summary.append(heading); item.append(summary);
const fields = el('dl', undefined, 'event-fields');
for (const [label, value] of [['起因', event.trigger], ['假设', event.hypothesis], ['改变', event.change], ['证据', event.evidence], ['已知成本', event.cost?.known], ['待确认成本', event.cost?.unknown], ['决策', event.decision], ['下一步', event.next_step], ['关联版本与资料', event.artifact_refs]]) {
const row = el('div'); row.append(el('dt', label), el('dd', valueText(value))); fields.append(row);
}
item.append(fields); timeline.append(item);
}
host.append(timeline);
}
async function openEvolution() {
showView('evolution');
const host = $('#evolution-content'); host.replaceChildren(el('p', '正在读取演变记录…', 'muted'));
history.replaceState(null, '', `/?view=evolution${currentReportId ? `&report=${encodeURIComponent(currentReportId)}` : ''}`);
try { renderEvolution(await api('/api/evolution')); }
catch (error) { host.replaceChildren(el('p', error.message, 'error')); }
}
async function openReport(id) {
showView('report');
$('#global-error').textContent = '';
try { const report = await api(`/api/reports/${encodeURIComponent(id)}`); renderReport(report); history.replaceState(null, '', `/?report=${encodeURIComponent(id)}`); }
catch (error) { $('#global-error').textContent = error.message; }
@@ -120,16 +158,21 @@ async function loadDashboard() {
}
if (!dashboard.reports.length) nav.append(el('p', '还没有历史周报', 'muted'));
renderLedger();
const selected = new URL(location.href).searchParams.get('report');
const params = new URL(location.href).searchParams;
const selected = params.get('report');
const initialView = params.get('view');
if (selected && dashboard.reports.some(r => r.id === selected)) await openReport(selected); else renderReport(dashboard.latest);
if (initialView === 'evolution') await openEvolution();
}
$('#show-evolution').addEventListener('click', openEvolution);
$('#show-report').addEventListener('click', () => { showView('report'); history.replaceState(null, '', currentReportId ? `/?report=${encodeURIComponent(currentReportId)}` : '/'); });
$('#login-form').addEventListener('submit', async event => {
event.preventDefault(); const button = event.currentTarget.querySelector('button'); button.disabled = true; $('#login-error').textContent = '';
try { await api('/api/login', { method: 'POST', body: JSON.stringify({ username: $('#username').value, password: $('#password').value }) }); $('#password').value = ''; await loadDashboard(); }
catch (error) { $('#login-error').textContent = error.message; } finally { button.disabled = false; }
});
$('#logout').addEventListener('click', async () => {
try { await api('/api/logout', { method: 'POST', body: '{}' }); dashboard = null; $('#report-content').replaceChildren(); $('#ledger').replaceChildren(); $('#report-nav').replaceChildren(); showLogin(); }
try { await api('/api/logout', { method: 'POST', body: '{}' }); dashboard = null; $('#report-content').replaceChildren(); $('#evolution-content').replaceChildren(); currentReportId = undefined; showView('report'); $('#ledger').replaceChildren(); $('#report-nav').replaceChildren(); showLogin(); }
catch (error) { $('#global-error').textContent = error.message; }
});
(async () => {