diff --git a/dsRag/static/tree.html b/dsRag/static/tree.html
index a2336f46..6465ee2e 100644
--- a/dsRag/static/tree.html
+++ b/dsRag/static/tree.html
@@ -121,18 +121,10 @@
}
// 初始化数据
- $.ajax({
- url: "/api/tree-data",
- type: "GET",
- success: function (res) {
- if (res.code === 0) {
- treeData = res.data;
- updateTable();
- }
- }
- });
-
-
+ // Move this declaration outside the AJAX call
+ var allNodes = [];
+
+ // Add flattenTree function definition before the AJAX call
function flattenTree(nodes) {
var result = [];
nodes.forEach(node => {
@@ -143,17 +135,107 @@
});
return result;
}
-
+
+ $.ajax({
+ url: "/api/tree-data",
+ type: "GET",
+ success: function(res) {
+ if (res.code === 0) {
+ treeData = res.data;
+ allNodes = flattenTree(treeData);
+ updateTable();
+ }
+ }
+ });
+
+ // 修改prerequisiteUpdate和relatedUpdate函数
function prerequisiteUpdate(nodeId) {
const node = findNodeById(treeData, nodeId);
- if (node) {
- alert(`先修知识 Node ID: ${node.id}\nNode Title: ${node.title}`);
- } else {
+ if (!node) {
console.error('Node not found:', nodeId);
+ return;
}
+
+ // 创建模态框容器
+ const modal = document.createElement('div');
+ modal.style.position = 'fixed';
+ modal.style.top = '50%';
+ modal.style.left = '50%';
+ modal.style.transform = 'translate(-50%, -50%)';
+ modal.style.width = '500px';
+ modal.style.padding = '20px';
+ modal.style.backgroundColor = 'white';
+ modal.style.border = '1px solid #ccc';
+ modal.style.borderRadius = '5px';
+ modal.style.boxShadow = '0 0 10px rgba(0,0,0,0.2)';
+ modal.style.zIndex = '1000';
+
+ // 创建标题和关闭按钮
+ const header = document.createElement('div');
+ header.style.display = 'flex';
+ header.style.justifyContent = 'space-between';
+ header.style.alignItems = 'center';
+ header.style.marginBottom = '15px';
+
+ const title = document.createElement('h3');
+ title.textContent = '选择先修知识';
+ title.style.margin = '0';
+
+ const closeBtn = document.createElement('button');
+ closeBtn.innerHTML = '×';
+ closeBtn.style.background = 'none';
+ closeBtn.style.border = 'none';
+ closeBtn.style.fontSize = '20px';
+ closeBtn.style.cursor = 'pointer';
+ closeBtn.onclick = function() {
+ document.body.removeChild(modal);
+ };
+
+ header.appendChild(title);
+ header.appendChild(closeBtn);
+
+ // 创建多选下拉框
+ const select = document.createElement('select');
+ select.multiple = true;
+ select.style.width = '100%';
+ select.style.height = '200px';
+ select.style.margin = '10px 0';
+ select.style.padding = '5px';
+
+ // 添加选项
+ allNodes.forEach(n => {
+ if (n.id !== nodeId) {
+ const option = document.createElement('option');
+ option.value = n.id;
+ option.text = n.title;
+ select.appendChild(option);
+ }
+ });
+
+ // 创建确定按钮
+ const button = document.createElement('button');
+ button.textContent = '确定';
+ button.style.padding = '8px 16px';
+ button.style.backgroundColor = '#4CAF50';
+ button.style.color = 'white';
+ button.style.border = 'none';
+ button.style.borderRadius = '4px';
+ button.style.cursor = 'pointer';
+ button.onclick = function() {
+ document.body.removeChild(modal);
+ };
+
+ // 添加到模态框
+ modal.appendChild(header);
+ modal.appendChild(select);
+ modal.appendChild(button);
+
+ // 添加到页面
+ document.body.appendChild(modal);
}
function relatedUpdate(nodeId) {
+ // 同样修改relatedUpdate函数
const node = findNodeById(treeData, nodeId);
if (node) {
alert(`相关知识 Node ID: ${node.id}\nNode Title: ${node.title}`);