feat: 重构移动端布局并新增专用单词本页面

This commit is contained in:
guoqingshan
2026-08-02 11:00:39 +08:00
parent 870f8a5da3
commit b337ee23c2
8 changed files with 867 additions and 48 deletions
+51
View File
@@ -72,6 +72,57 @@ def add_vocabulary(user):
conn.close()
@vocab_bp.put("/api/vocabulary/<int:item_id>")
@login_required
def update_vocabulary(user, item_id):
data = request.get_json(silent=True) or {}
word = (data.get("word") or "").strip()
if not word:
return jsonify({"error": "单词不能为空"}), 400
conn = get_db()
try:
row = conn.execute(
"SELECT id FROM vocabulary WHERE id = ? AND user_id = ?",
(item_id, user["id"]),
).fetchone()
if row is None:
return jsonify({"error": "收藏不存在或无权访问"}), 404
duplicate = conn.execute(
"""
SELECT id FROM vocabulary
WHERE user_id = ? AND word = ? AND id <> ?
""",
(user["id"], word, item_id),
).fetchone()
if duplicate:
return jsonify({"error": "该单词已在单词本中"}), 409
conn.execute(
"""
UPDATE vocabulary
SET word = ?, english = ?, chinese = ?, category = ?
WHERE id = ?
""",
(
word,
(data.get("english") or "").strip(),
(data.get("chinese") or "").strip(),
(data.get("category") or "").strip(),
item_id,
),
)
conn.commit()
updated = conn.execute(
"""
SELECT id, word, english, chinese, category, created_at
FROM vocabulary WHERE id = ?
""",
(item_id,),
).fetchone()
return jsonify(row_to_dict(updated))
finally:
conn.close()
@vocab_bp.delete("/api/vocabulary/<int:item_id>")
@login_required
def delete_vocabulary(user, item_id):