From 26e4a14e46ee42baaebb0d1a3202f91946a01398 Mon Sep 17 00:00:00 2001 From: HuangHai <10402852@qq.com> Date: Wed, 2 Jul 2025 14:56:21 +0800 Subject: [PATCH] 'commit' --- dsRag/Start.py | 30 ++++++++++++++++++++++++++++++ dsRag/static/tree.html | 8 ++++---- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/dsRag/Start.py b/dsRag/Start.py index f61e17d5..1e7292b9 100644 --- a/dsRag/Start.py +++ b/dsRag/Start.py @@ -209,5 +209,35 @@ async def get_tree_data(): return {"code": 1, "msg": str(e)} +@app.post("/api/update-prerequisites") +async def update_prerequisites(request: fastapi.Request): + try: + data = await request.json() + node_id = data.get('node_id') + prerequisites = data.get('prerequisites', []) + + if not node_id: + raise ValueError("Missing node_id") + + mysql_pool = await init_mysql_pool() + async with mysql_pool.acquire() as conn: + await conn.ping() + async with conn.cursor() as cur: + await cur.execute( + """ + UPDATE knowledge_points + SET prerequisite = %s + WHERE id = %s + """, + (json.dumps([{"id": p["id"], "title": p["title"]} for p in prerequisites]), node_id) + ) + await conn.commit() + + return {"code": 0, "msg": "更新成功"} + except Exception as e: + logger.error(f"更新先修知识失败: {str(e)}") + return {"code": 1, "msg": str(e)} + + if __name__ == "__main__": uvicorn.run(app, host="0.0.0.0", port=8000) diff --git a/dsRag/static/tree.html b/dsRag/static/tree.html index c8d1f0e3..87aa237b 100644 --- a/dsRag/static/tree.html +++ b/dsRag/static/tree.html @@ -107,12 +107,12 @@ } html += node.title + ''; - - // 修改维护按钮的HTML生成部分 + // 修改后的维护按钮显示逻辑 + const isThirdLevel = node.parent_id && allNodes.find(n => n.id === node.parent_id)?.parent_id; html += '