diff --git a/app/templates/student.html b/app/templates/student.html index 6d8f1f3..7ad5558 100644 --- a/app/templates/student.html +++ b/app/templates/student.html @@ -46,7 +46,7 @@
加载失败
'; - } + await loadTimeline(); } -function renderPlanList(plans) { +// 学习历程时间线 +async function loadTimeline() { + const [plansRes, goalsRes] = await Promise.all([ + fetch(`/api/students/${currentStudentId}/plans`), + fetch(`/api/students/${currentStudentId}/goals`) + ]); + const plans = await plansRes.json(); + const goals = await goalsRes.json(); + + // 构建时间线条目 + const timeline = []; + + // 添加目标开始记录 + goals.forEach(g => { + if (g.start_date) { + const startDate = new Date(g.start_date); + const endDate = g.assessment_date ? new Date(g.assessment_date) : null; + const days = endDate ? Math.ceil((endDate - startDate) / (1000*60*60*24)) : null; + timeline.push({ + date: startDate, + type: 'goal_start', + goal: g, + days: days, + endDate: endDate + }); + } + // 添加目标达成记录 + if (g.achievement_date) { + timeline.push({ + date: new Date(g.achievement_date), + type: 'goal_achieved', + goal: g + }); + } + }); + + // 添加方案生成记录 + plans.forEach(p => { + timeline.push({ + date: new Date(p.created_at), + type: 'plan', + plan: p + }); + }); + + // 按时间逆序排序 + timeline.sort((a, b) => b.date - a.date); + + renderTimeline(timeline); +} + +function renderTimeline(timeline) { const container = document.getElementById('planList'); - if (plans.length === 0) { - container.innerHTML = '暂无练习方案
'; + if (timeline.length === 0) { + container.innerHTML = '暂无学习记录
'; return; } - container.innerHTML = plans.map(p => ` -