|
|
|
@ -50,7 +50,6 @@
|
|
|
|
|
|
|
|
|
|
#treeTable th:nth-child(2), #treeTable td:nth-child(2),
|
|
|
|
|
#treeTable th:nth-child(3), #treeTable td:nth-child(3),
|
|
|
|
|
|
|
|
|
|
#treeTable th:nth-child(4), #treeTable td:nth-child(4) {
|
|
|
|
|
width: 220px;
|
|
|
|
|
min-width: 220px;
|
|
|
|
@ -132,7 +131,8 @@
|
|
|
|
|
const isThirdLevel = node.parent_id && allNodes.find(n => n.id === node.parent_id)?.parent_id;
|
|
|
|
|
html += '<td>' + (node.prerequisite && node.prerequisite.length > 0 ?
|
|
|
|
|
node.prerequisite.map(p => p.title).join(', ') : '') + '</td>';
|
|
|
|
|
html += '<td>' + (node.related || '') + '</td>';
|
|
|
|
|
html += '<td>' + (node.related && node.related.length > 0 ?
|
|
|
|
|
node.related.map(r => r.title).join(', ') : '') + '</td>';
|
|
|
|
|
html += '<td>' + (isThirdLevel ?
|
|
|
|
|
'<button class="layui-btn layui-btn-sm" onclick="prerequisiteUpdate(\'' + node.id + '\')">先修知识</button> ' +
|
|
|
|
|
'<button class="layui-btn layui-btn-sm layui-btn-normal" onclick="relatedUpdate(\'' + node.id + '\')">相关知识</button>' : '') + '</td>';
|
|
|
|
@ -227,14 +227,97 @@
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 调用后端接口
|
|
|
|
|
fetch('/api/update-prerequisites', {
|
|
|
|
|
fetch('/api/update-knowledge', {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
node_id: nodeId,
|
|
|
|
|
knowledge: selectedNodes, // 修改参数名
|
|
|
|
|
update_type: 'prerequisite'
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
.then(response => response.json())
|
|
|
|
|
.then(data => {
|
|
|
|
|
if (data.code === 0) {
|
|
|
|
|
layer.msg('保存成功', {icon: 1});
|
|
|
|
|
setTimeout(() => location.reload(), 1000);
|
|
|
|
|
} else {
|
|
|
|
|
layer.msg('保存失败: ' + data.message, {icon: 2});
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch(error => {
|
|
|
|
|
console.error('Error:', error);
|
|
|
|
|
layer.msg('保存出错', {icon: 2});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
layer.close(index);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
form.render();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function relatedUpdate(nodeId) {
|
|
|
|
|
layui.use(['layer', 'form'], function () {
|
|
|
|
|
var layer = layui.layer;
|
|
|
|
|
var form = layui.form;
|
|
|
|
|
|
|
|
|
|
// 获取当前节点
|
|
|
|
|
const currentNode = findNodeById(treeData, nodeId);
|
|
|
|
|
|
|
|
|
|
// 构建HTML内容
|
|
|
|
|
let html = '<div style="padding: 20px;">';
|
|
|
|
|
html += '<form class="layui-form">';
|
|
|
|
|
|
|
|
|
|
allNodes.forEach(node => {
|
|
|
|
|
if (node.id !== nodeId && !node.isParent) {
|
|
|
|
|
const isSelected = currentNode && currentNode.related &&
|
|
|
|
|
currentNode.related.some(p => p.id === node.id);
|
|
|
|
|
|
|
|
|
|
// 获取父节点标题
|
|
|
|
|
const parentTitle = findParentTitle(node);
|
|
|
|
|
const displayTitle = parentTitle ? `【${parentTitle}】${node.title}` : node.title;
|
|
|
|
|
|
|
|
|
|
html += '<div class="layui-form-item">';
|
|
|
|
|
html += '<input type="checkbox" name="node" value="' + node.id + '" title="' + displayTitle + '"' + (isSelected ? ' checked' : '') + '>';
|
|
|
|
|
html += '</div>';
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
html += '</form>';
|
|
|
|
|
html += '</div>';
|
|
|
|
|
|
|
|
|
|
// 弹出层
|
|
|
|
|
layer.open({
|
|
|
|
|
type: 1,
|
|
|
|
|
title: '选择相关知识',
|
|
|
|
|
content: html,
|
|
|
|
|
area: ['500px', '400px'],
|
|
|
|
|
btn: ['确定', '取消'],
|
|
|
|
|
yes: function (index, layero) {
|
|
|
|
|
const selectedNodes = [];
|
|
|
|
|
$('input[name="node"]:checked').each(function () {
|
|
|
|
|
const node = findNodeById(treeData, $(this).val());
|
|
|
|
|
if (node) {
|
|
|
|
|
selectedNodes.push({
|
|
|
|
|
id: node.id,
|
|
|
|
|
title: node.title
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 调用后端接口
|
|
|
|
|
fetch('/api/update-knowledge', {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
node_id: nodeId,
|
|
|
|
|
prerequisites: selectedNodes
|
|
|
|
|
knowledge: selectedNodes, // 修改参数名
|
|
|
|
|
update_type: 'related'
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
.then(response => response.json())
|
|
|
|
|