From 11b1cefec119e82c515badaf12035def36ec1c78 Mon Sep 17 00:00:00 2001
From: HuangHai <10402852@qq.com>
Date: Wed, 2 Jul 2025 15:12:02 +0800
Subject: [PATCH] 'commit'
---
dsRag/Start.py | 11 ++++++++++-
dsRag/static/tree.html | 43 ++++++++++++++++++++++++++++++++----------
2 files changed, 43 insertions(+), 11 deletions(-)
diff --git a/dsRag/Start.py b/dsRag/Start.py
index 1e7292b9..f06e90a9 100644
--- a/dsRag/Start.py
+++ b/dsRag/Start.py
@@ -182,12 +182,21 @@ async def get_tree_data():
# 构建节点映射
nodes = {}
for row in rows:
+ prerequisite_data = json.loads(row[4]) if row[4] else []
+ # 转换先修知识格式
+ if isinstance(prerequisite_data, list) and len(prerequisite_data) > 0 and isinstance(prerequisite_data[0], dict):
+ # 已经是新格式
+ prerequisites = prerequisite_data
+ else:
+ # 转换为新格式
+ prerequisites = [{"id": str(id), "title": title} for id, title in (prerequisite_data or [])] if prerequisite_data else None
+
nodes[row[0]] = {
"id": row[0],
"title": row[1],
"parent_id": row[2] if row[2] is not None else 0,
"isParent": not row[3],
- "prerequisite": json.loads(row[4]) if row[4] and len(json.loads(row[4])) > 0 else None,
+ "prerequisite": prerequisites if prerequisites and len(prerequisites) > 0 else None,
"related": json.loads(row[5]) if row[5] and len(json.loads(row[5])) > 0 else None,
"open": True
}
diff --git a/dsRag/static/tree.html b/dsRag/static/tree.html
index 87aa237b..bc5ddc2c 100644
--- a/dsRag/static/tree.html
+++ b/dsRag/static/tree.html
@@ -109,7 +109,8 @@
// 修改后的维护按钮显示逻辑
const isThirdLevel = node.parent_id && allNodes.find(n => n.id === node.parent_id)?.parent_id;
- html += '
' + (node.prerequisite || '') +
+ html += ' | ' + (node.prerequisite && node.prerequisite.length > 0 ?
+ node.prerequisite.map(p => p.title).join(', ') : '') +
(isThirdLevel ? '' : '') + ' | ';
html += '' + (node.related || '') +
(isThirdLevel ? '' : '') + ' | ';
@@ -213,7 +214,7 @@
// 为每个节点创建checkbox
allNodes.forEach(node => {
- // 只处理二级节点
+ console.log('Node title:', typeof node.title, node.title); // 添加调试
if (node.id !== currentNodeId && !node.isParent) {
const div = document.createElement('div');
const checkbox = document.createElement('input');
@@ -223,7 +224,7 @@
const label = document.createElement('label');
label.htmlFor = `node_${node.id}`;
- label.textContent = `【${findParentTitle(node)}】${node.title}`;
+ label.textContent = node.title; // 修改这里,直接显示节点title
div.appendChild(checkbox);
div.appendChild(label);
@@ -248,9 +249,8 @@
console.error('找不到当前节点:', currentNodeId);
return;
}
-
- console.log(`当前操作的二级节点ID: ${currentNodeId}, 名称: ${currentNode.title}`);
-
+
+
const selectedNodes = [];
const checkboxes = container.querySelectorAll('input[type="checkbox"]:checked');
checkboxes.forEach(checkbox => {
@@ -258,12 +258,11 @@
if (node) {
selectedNodes.push({
id: node.id,
- title: node.title,
- parentTitle: node.isParent ? '' : findParentTitle(node)
+ title: node.title
});
}
});
-
+ console.log(`当前操作的三级节点ID: ${currentNodeId}, 名称: ${currentNode.title}`);
console.log('选中的先修知识:');
selectedNodes.forEach(node => {
if (node.parentTitle) {
@@ -272,7 +271,31 @@
console.log(`ID: ${node.id}, 名称: ${node.title}`);
}
});
-
+ // 调用后端接口
+ fetch('/api/update-prerequisites', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify({
+ node_id: currentNodeId,
+ prerequisites: selectedNodes
+ })
+ })
+ .then(response => response.json())
+ .then(data => {
+ if (data.code === 0) {
+ alert('保存成功');
+ location.reload(); // 刷新页面
+ } else {
+ alert('保存失败: ' + data.message);
+ }
+ })
+ .catch(error => {
+ console.error('Error:', error);
+ alert('保存出错');
+ });
+
modal.remove();
};