main
HuangHai 3 weeks ago
parent 1c7f7ba960
commit 26e4a14e46

@ -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)

@ -107,12 +107,12 @@
}
html += node.title + '</td>';
// 修改维护按钮的HTML生成部分
// 修改后的维护按钮显示逻辑
const isThirdLevel = node.parent_id && allNodes.find(n => n.id === node.parent_id)?.parent_id;
html += '<td>' + (node.prerequisite || '') +
(node.isParent && node.parent_id ? '<button onclick="prerequisiteUpdate(\'' + node.id + '\')">维护</button>' : '') + '</td>';
(isThirdLevel ? '<button onclick="prerequisiteUpdate(\'' + node.id + '\')">维护</button>' : '') + '</td>';
html += '<td>' + (node.related || '') +
(node.isParent && node.parent_id ? '<button onclick="relatedUpdate(\'' + node.id + '\')">维护</button>' : '') + '</td>';
(isThirdLevel ? '<button onclick="relatedUpdate(\'' + node.id + '\')">维护</button>' : '') + '</td>';
html += '</tr>';
if (node.open && node.children && node.children.length > 0) {

Loading…
Cancel
Save