feat: 目标和问题统一分类体系(综合/乐理相关/演奏能力/其他),添加数据库迁移

This commit is contained in:
hmo
2026-04-23 21:57:00 +08:00
parent 5f1dcc08fb
commit f83769fa20
4 changed files with 49 additions and 6 deletions
+15 -3
View File
@@ -46,6 +46,15 @@
<option value="精通">精通</option>
</select>
</div>
<div class="mb-3">
<label class="form-label">分类</label>
<select class="form-select" id="goal-category">
<option value="综合">综合(涉及多方面)</option>
<option value="乐理相关">乐理相关</option>
<option value="演奏能力">演奏能力</option>
<option value="其他">其他</option>
</select>
</div>
<div class="mb-3">
<label class="form-label">目标内容 (Markdown)</label>
<textarea class="form-control" id="goal-content" rows="8"></textarea>
@@ -111,6 +120,7 @@ async function loadGoals() {
grid.innerHTML = goalsWithChildren.map(g => {
const level = g.level || '入门';
const category = g.category || '综合';
const childNames = g.children && g.children.length > 0
? g.children.map(c => escapeHtml(c.name)).join(', ')
: '';
@@ -120,6 +130,7 @@ async function loadGoals() {
<div class="card-body">
<h6 class="card-title">${escapeHtml(g.name)}</h6>
<div class="mb-1">
<span class="badge bg-primary">${category}</span>
<span class="badge bg-secondary">${level}</span>
</div>
${childNames ? `<div class="small text-muted mb-2">子目标: ${childNames}</div>` : ''}
@@ -140,14 +151,14 @@ async function saveGoal() {
const id = document.getElementById('goal-id').value;
const name = document.getElementById('goal-name').value;
const level = document.getElementById('goal-level').value;
const category = document.getElementById('goal-category').value;
const content = document.getElementById('goal-content').value;
if (!name) { alert('请输入目标名称'); return; }
const method = id ? 'PUT' : 'POST';
const url = id ? `${API_BASE}/${id}` : API_BASE;
const payload = {name, level, content};
console.log('Saving goal:', payload);
const payload = {name, level, category, content};
try {
const res = await fetch(url, {
@@ -174,10 +185,10 @@ 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 || '入门';
document.getElementById('goal-category').value = g.category || '综合';
document.getElementById('goal-content').value = g.content || '';
document.getElementById('goalModalTitle').textContent = '编辑目标';
new bootstrap.Modal(document.getElementById('goalModal')).show();
@@ -298,6 +309,7 @@ document.getElementById('goalModal').addEventListener('hidden.bs.modal', () => {
document.getElementById('goal-id').value = '';
document.getElementById('goal-name').value = '';
document.getElementById('goal-level').value = '入门';
document.getElementById('goal-category').value = '综合';
document.getElementById('goal-content').value = '';
document.getElementById('goalModalTitle').textContent = '新建目标';
});