diff --git a/app/templates/goals.html b/app/templates/goals.html index 4edc79f..9713a31 100644 --- a/app/templates/goals.html +++ b/app/templates/goals.html @@ -102,22 +102,27 @@ async function loadGoals() { const goals = await res.json(); const grid = document.getElementById('goals-grid'); - // 获取每个目标的子目标数量 + // 获取每个目标的子目标信息 const goalsWithChildren = await Promise.all(goals.map(async g => { const childrenRes = await fetch(`${API_BASE}/${g.id}/children`); const children = await childrenRes.json(); - return {...g, childCount: children.length}; + return {...g, children: children}; })); - grid.innerHTML = goalsWithChildren.map(g => ` + grid.innerHTML = goalsWithChildren.map(g => { + const level = g.level || '入门'; + const childNames = g.children && g.children.length > 0 + ? g.children.map(c => escapeHtml(c.name)).join(', ') + : ''; + return `
${escapeHtml(g.name)}
- ${g.level} - ${g.childCount > 0 ? `${g.childCount}个子目标` : ''} + ${level}
+ ${childNames ? `
子目标: ${childNames}
` : ''}

${escapeHtml(g.content || '').substring(0, 80)}${g.content && g.content.length > 80 ? '...' : ''}

- `).join(''); + `}).join(''); } // 保存目标 @@ -141,20 +146,24 @@ async function saveGoal() { const method = id ? 'PUT' : 'POST'; const url = id ? `${API_BASE}/${id}` : API_BASE; + const payload = {name, level, content}; + console.log('Saving goal:', payload); try { const res = await fetch(url, { method, headers: {'Content-Type': 'application/json'}, - body: JSON.stringify({name, level, content}) + body: JSON.stringify(payload) }); + const result = await res.json(); + console.log('Save result:', result); + if (res.ok) { bootstrap.Modal.getInstance(document.getElementById('goalModal')).hide(); loadGoals(); } else { - const err = await res.json(); - alert(err.error || '保存失败'); + alert(result.error || '保存失败'); } } catch (e) { alert('网络错误: ' + e.message); @@ -165,6 +174,7 @@ function editGoal(id) { fetch(`${API_BASE}/${id}`) .then(r => r.json()) .then(g => { + console.log('Editing goal:', g); document.getElementById('goal-id').value = g.id; document.getElementById('goal-name').value = g.name; document.getElementById('goal-level').value = g.level || '入门';