From 22c32a9f3d08686b08833dd4361a5d56c70605bb Mon Sep 17 00:00:00 2001 From: hubian <908234780@qq.com> Date: Sun, 19 Apr 2026 09:25:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=BC=96=E8=BE=91=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E6=97=B6=E6=98=BE=E7=A4=BA=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=EF=BC=9B=E4=BF=AE=E5=A4=8D=E5=8F=AA=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=A0=87=E7=AD=BE=E6=97=B6=E8=BF=94=E5=9B=9EFalse?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- xian_favor/api.py | 26 +++++++++++++++++--------- xian_favor/db.py | 8 +++++++- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/xian_favor/api.py b/xian_favor/api.py index 497fa42..0d308f9 100644 --- a/xian_favor/api.py +++ b/xian_favor/api.py @@ -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); } } diff --git a/xian_favor/db.py b/xian_favor/db.py index debe2c0..391745d 100644 --- a/xian_favor/db.py +++ b/xian_favor/db.py @@ -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: """删除条目"""