fix: goals.html使用正确的block名称extra_js

This commit is contained in:
hmo
2026-04-23 20:42:04 +08:00
parent 9eec4dbe36
commit dd492c3b88
+13 -1
View File
@@ -70,7 +70,7 @@
</div>
{% endblock %}
{% block scripts %}
{% block extra_js %}
{{ super() }}
<script>
const API_BASE = '/api/goals';
@@ -99,24 +99,36 @@ async function loadGoals() {
// 保存目标
async function saveGoal() {
console.log('saveGoal called');
const id = document.getElementById('goal-id').value;
const name = document.getElementById('goal-name').value;
const content = document.getElementById('goal-content').value;
console.log('Form data:', {id, name, content});
if (!name) { alert('请输入目标名称'); return; }
const method = id ? 'PUT' : 'POST';
const url = id ? `${API_BASE}/${id}` : API_BASE;
console.log('Sending to:', url, 'method:', method);
try {
const res = await fetch(url, {
method,
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({name, content})
});
console.log('Response status:', res.status);
if (res.ok) {
bootstrap.Modal.getInstance(document.getElementById('goalModal')).hide();
loadGoals();
} else {
const err = await res.json();
alert(err.error || '保存失败');
}
} catch (e) {
console.error('Fetch error:', e);
alert('网络错误: ' + e.message);
}
}