From caa795c2d4b9785cbeca3b548b534d32bcda5e24 Mon Sep 17 00:00:00 2001 From: Hera Zhao Date: Fri, 10 Apr 2026 19:38:57 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=B7=B2=E6=B7=BB=E5=8A=A0=E9=85=8D?= =?UTF-8?q?=E6=96=B9=E9=80=9A=E7=9F=A5=E8=81=94=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 点击"已添加"后: 1. 标记所有同标题通知为已读(其他编辑者不用重复处理) 2. 通知其他管理员/高级编辑"已有人添加,无需重复处理" 3. 通知原始搜索用户"你搜索的配方已添加" - 新增 /api/notifications/{id}/added 端点 Co-Authored-By: Claude Opus 4.6 (1M context) --- backend/main.py | 44 ++++++++++++++++++++++++++++ frontend/src/components/UserMenu.vue | 8 ++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/backend/main.py b/backend/main.py index 8f43ffe..1b50276 100644 --- a/backend/main.py +++ b/backend/main.py @@ -1601,6 +1601,50 @@ def mark_notification_read(nid: int, body: dict = None, user=Depends(get_current return {"ok": True} +@app.post("/api/notifications/{nid}/added") +def mark_notification_added(nid: int, user=Depends(get_current_user)): + """Mark a 'search missing' notification as handled: notify others and the original requester.""" + conn = get_db() + notif = conn.execute("SELECT title, body FROM notifications WHERE id = ?", (nid,)).fetchone() + if not notif: + conn.close() + raise HTTPException(404, "通知不存在") + # Mark this one as read + conn.execute("UPDATE notifications SET is_read = 1 WHERE id = ?", (nid,)) + who = user.get("display_name") or user.get("username") + title = notif["title"] or "" + # Extract query from title "🔍 用户需求:XXX" + query = title.replace("🔍 用户需求:", "").strip() if "用户需求" in title else title + # Mark all same-title notifications as read + conn.execute("UPDATE notifications SET is_read = 1 WHERE title = ? AND is_read = 0", (title,)) + # Notify other editors that it's been handled + for role in ("admin", "senior_editor"): + conn.execute( + "INSERT INTO notifications (target_role, title, body) VALUES (?, ?, ?)", + (role, "✅ 配方已添加", + f"{who} 已为「{query}」添加了配方,无需重复处理。") + ) + # Notify the original requester (search the body for who searched) + body_text = notif["body"] or "" + # body format: "XXX 搜索了「YYY」..." + if "搜索了" in body_text: + requester_name = body_text.split(" 搜索了")[0].strip() + # Find the user + requester = conn.execute( + "SELECT id, role FROM users WHERE display_name = ? OR username = ?", + (requester_name, requester_name) + ).fetchone() + if requester: + conn.execute( + "INSERT INTO notifications (target_role, title, body, target_user_id) VALUES (?, ?, ?, ?)", + (requester["role"], "🎉 你搜索的配方已添加", + f"你之前搜索的「{query}」已有编辑添加了配方,快去查看吧!", requester["id"]) + ) + conn.commit() + conn.close() + return {"ok": True} + + @app.post("/api/notifications/{nid}/unread") def mark_notification_unread(nid: int, user=Depends(get_current_user)): conn = get_db() diff --git a/frontend/src/components/UserMenu.vue b/frontend/src/components/UserMenu.vue index 2a98152..f97ae3f 100644 --- a/frontend/src/components/UserMenu.vue +++ b/frontend/src/components/UserMenu.vue @@ -141,7 +141,13 @@ function isReviewable(n) { } async function markAdded(n) { - await markOneRead(n) + try { + await api(`/api/notifications/${n.id}/added`, { method: 'POST' }) + n.is_read = 1 + ui.showToast('已标记,已通知相关人员') + } catch { + await markOneRead(n) + } } function goReview(n) {