Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 22c32a9f3d |
@@ -1781,15 +1781,23 @@ async function saveEdit() {
|
||||
is_starred: document.getElementById('editStarred').checked ? 1 : 0
|
||||
};
|
||||
|
||||
const res = await fetch(`${API_BASE}/items/${id}`, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data)
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
bootstrap.Modal.getInstance(document.getElementById('editModal')).hide();
|
||||
refreshData();
|
||||
try {
|
||||
const res = await fetch(`${API_BASE}/items/${id}`, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data)
|
||||
});
|
||||
|
||||
const result = await res.json();
|
||||
|
||||
if (res.ok && result.success) {
|
||||
bootstrap.Modal.getInstance(document.getElementById('editModal')).hide();
|
||||
refreshData();
|
||||
} else {
|
||||
alert('保存失败: ' + (result.error || '未知错误'));
|
||||
}
|
||||
} catch (e) {
|
||||
alert('保存失败: ' + e.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -263,6 +263,7 @@ class Database:
|
||||
allowed_fields = ['type', 'title', 'content', 'url', 'source', 'status', 'priority', 'due_date', 'note', 'is_starred']
|
||||
update_fields = {k: v for k, v in kwargs.items() if k in allowed_fields}
|
||||
|
||||
# 只有 tags 变化也算有效更新
|
||||
if not update_fields and 'tags' not in kwargs:
|
||||
return False
|
||||
|
||||
@@ -271,6 +272,11 @@ class Database:
|
||||
with self.get_conn() as conn:
|
||||
cursor = conn.cursor()
|
||||
|
||||
# 检查条目是否存在
|
||||
cursor.execute("SELECT id FROM items WHERE id = ?", (item_id,))
|
||||
if not cursor.fetchone():
|
||||
return False
|
||||
|
||||
if update_fields:
|
||||
set_clause = ", ".join(f"{k} = ?" for k in update_fields.keys())
|
||||
set_clause += ", updated_at = ?"
|
||||
@@ -285,7 +291,7 @@ class Database:
|
||||
self._add_tags_to_item(conn, item_id, kwargs['tags'])
|
||||
|
||||
conn.commit()
|
||||
return cursor.rowcount > 0
|
||||
return True
|
||||
|
||||
def delete_item(self, item_id: int) -> bool:
|
||||
"""删除条目"""
|
||||
|
||||
Reference in New Issue
Block a user