|
|
|
@ -48,7 +48,21 @@
|
|
|
|
|
margin-right: 5px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
</style>
|
|
|
|
|
#treeTable th:nth-child(4), #treeTable td:nth-child(4) {
|
|
|
|
|
width: 220px;
|
|
|
|
|
min-width: 220px;
|
|
|
|
|
max-width: 220px;
|
|
|
|
|
text-align: center;
|
|
|
|
|
border-right: 1px solid #ddd; /* 确保右侧边框闭合 */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#treeTable td:nth-child(4) {
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
gap: 5px;
|
|
|
|
|
min-height: 36px; /* 确保空单元格也有高度 */
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
</head>
|
|
|
|
|
<body>
|
|
|
|
|
<table id="treeTable">
|
|
|
|
@ -57,6 +71,7 @@
|
|
|
|
|
<th>知识点</th>
|
|
|
|
|
<th>先修知识</th>
|
|
|
|
|
<th>相关知识</th>
|
|
|
|
|
<th>维护</th>
|
|
|
|
|
</tr>
|
|
|
|
|
</thead>
|
|
|
|
|
<tbody id="treeBody"></tbody>
|
|
|
|
@ -112,17 +127,19 @@
|
|
|
|
|
|
|
|
|
|
// 修改后的维护按钮显示逻辑
|
|
|
|
|
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(', ') : '') +
|
|
|
|
|
(isThirdLevel ? '<button class="layui-btn layui-btn-sm" onclick="prerequisiteUpdate(\'' + node.id + '\')">维护</button>' : '') + '</td>';
|
|
|
|
|
html += '<td>' + (node.related || '') +
|
|
|
|
|
(isThirdLevel ? '<button class="layui-btn layui-btn-sm layui-btn-normal" onclick="relatedUpdate(\'' + node.id + '\')">维护</button>' : '') + '</td>';
|
|
|
|
|
html += '<td>' + (node.prerequisite && node.prerequisite.length > 0 ?
|
|
|
|
|
node.prerequisite.map(p => p.title).join(', ') : '') + '</td>';
|
|
|
|
|
html += '<td>' + (node.related || '') + '</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>';
|
|
|
|
|
html += '</tr>';
|
|
|
|
|
if (node.open && node.children && node.children.length > 0) {
|
|
|
|
|
buildRows(node.children, level + 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buildRows(treeData);
|
|
|
|
|
$("#treeBody").html(html);
|
|
|
|
|
}
|
|
|
|
@ -158,35 +175,35 @@
|
|
|
|
|
// 修改prerequisiteUpdate和relatedUpdate函数
|
|
|
|
|
// 修改prerequisiteUpdate函数使用LayUI
|
|
|
|
|
function prerequisiteUpdate(nodeId) {
|
|
|
|
|
layui.use(['layer', 'form'], function(){
|
|
|
|
|
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.prerequisite &&
|
|
|
|
|
const isSelected = currentNode && currentNode.prerequisite &&
|
|
|
|
|
currentNode.prerequisite.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,
|
|
|
|
@ -194,9 +211,9 @@
|
|
|
|
|
content: html,
|
|
|
|
|
area: ['500px', '400px'],
|
|
|
|
|
btn: ['确定', '取消'],
|
|
|
|
|
yes: function(index, layero){
|
|
|
|
|
yes: function (index, layero) {
|
|
|
|
|
const selectedNodes = [];
|
|
|
|
|
$('input[name="node"]:checked').each(function(){
|
|
|
|
|
$('input[name="node"]:checked').each(function () {
|
|
|
|
|
const node = findNodeById(treeData, $(this).val());
|
|
|
|
|
if (node) {
|
|
|
|
|
selectedNodes.push({
|
|
|
|
@ -205,7 +222,7 @@
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 调用后端接口
|
|
|
|
|
fetch('/api/update-prerequisites', {
|
|
|
|
|
method: 'POST',
|
|
|
|
@ -217,20 +234,20 @@
|
|
|
|
|
prerequisites: selectedNodes
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
.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});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
.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);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|