main
HuangHai 3 weeks ago
parent bed8cbc4e0
commit 5c4fe533c1

@ -48,7 +48,21 @@
margin-right: 5px; 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> </head>
<body> <body>
<table id="treeTable"> <table id="treeTable">
@ -57,6 +71,7 @@
<th>知识点</th> <th>知识点</th>
<th>先修知识</th> <th>先修知识</th>
<th>相关知识</th> <th>相关知识</th>
<th>维护</th>
</tr> </tr>
</thead> </thead>
<tbody id="treeBody"></tbody> <tbody id="treeBody"></tbody>
@ -112,17 +127,19 @@
// 修改后的维护按钮显示逻辑 // 修改后的维护按钮显示逻辑
const isThirdLevel = node.parent_id && allNodes.find(n => n.id === node.parent_id)?.parent_id; const isThirdLevel = node.parent_id && allNodes.find(n => n.id === node.parent_id)?.parent_id;
html += '<td>' + (node.prerequisite && node.prerequisite.length > 0 ? html += '<td>' + (node.prerequisite && node.prerequisite.length > 0 ?
node.prerequisite.map(p => p.title).join(', ') : '') + node.prerequisite.map(p => p.title).join(', ') : '') + '</td>';
(isThirdLevel ? '<button class="layui-btn layui-btn-sm" onclick="prerequisiteUpdate(\'' + node.id + '\')">维护</button>' : '') + '</td>'; html += '<td>' + (node.related || '') + '</td>';
html += '<td>' + (node.related || '') + html += '<td>' + (isThirdLevel ?
(isThirdLevel ? '<button class="layui-btn layui-btn-sm layui-btn-normal" onclick="relatedUpdate(\'' + node.id + '\')">维护</button>' : '') + '</td>'; '<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>'; html += '</tr>';
if (node.open && node.children && node.children.length > 0) { if (node.open && node.children && node.children.length > 0) {
buildRows(node.children, level + 1); buildRows(node.children, level + 1);
} }
} }
} }
buildRows(treeData); buildRows(treeData);
$("#treeBody").html(html); $("#treeBody").html(html);
} }
@ -158,35 +175,35 @@
// 修改prerequisiteUpdate和relatedUpdate函数 // 修改prerequisiteUpdate和relatedUpdate函数
// 修改prerequisiteUpdate函数使用LayUI // 修改prerequisiteUpdate函数使用LayUI
function prerequisiteUpdate(nodeId) { function prerequisiteUpdate(nodeId) {
layui.use(['layer', 'form'], function(){ layui.use(['layer', 'form'], function () {
var layer = layui.layer; var layer = layui.layer;
var form = layui.form; var form = layui.form;
// 获取当前节点 // 获取当前节点
const currentNode = findNodeById(treeData, nodeId); const currentNode = findNodeById(treeData, nodeId);
// 构建HTML内容 // 构建HTML内容
let html = '<div style="padding: 20px;">'; let html = '<div style="padding: 20px;">';
html += '<form class="layui-form">'; html += '<form class="layui-form">';
allNodes.forEach(node => { allNodes.forEach(node => {
if (node.id !== nodeId && !node.isParent) { if (node.id !== nodeId && !node.isParent) {
const isSelected = currentNode && currentNode.prerequisite && const isSelected = currentNode && currentNode.prerequisite &&
currentNode.prerequisite.some(p => p.id === node.id); currentNode.prerequisite.some(p => p.id === node.id);
// 获取父节点标题 // 获取父节点标题
const parentTitle = findParentTitle(node); const parentTitle = findParentTitle(node);
const displayTitle = parentTitle ? `【${parentTitle}】${node.title}` : node.title; const displayTitle = parentTitle ? `【${parentTitle}】${node.title}` : node.title;
html += '<div class="layui-form-item">'; html += '<div class="layui-form-item">';
html += '<input type="checkbox" name="node" value="' + node.id + '" title="' + displayTitle + '"' + (isSelected ? ' checked' : '') + '>'; html += '<input type="checkbox" name="node" value="' + node.id + '" title="' + displayTitle + '"' + (isSelected ? ' checked' : '') + '>';
html += '</div>'; html += '</div>';
} }
}); });
html += '</form>'; html += '</form>';
html += '</div>'; html += '</div>';
// 弹出层 // 弹出层
layer.open({ layer.open({
type: 1, type: 1,
@ -194,9 +211,9 @@
content: html, content: html,
area: ['500px', '400px'], area: ['500px', '400px'],
btn: ['确定', '取消'], btn: ['确定', '取消'],
yes: function(index, layero){ yes: function (index, layero) {
const selectedNodes = []; const selectedNodes = [];
$('input[name="node"]:checked').each(function(){ $('input[name="node"]:checked').each(function () {
const node = findNodeById(treeData, $(this).val()); const node = findNodeById(treeData, $(this).val());
if (node) { if (node) {
selectedNodes.push({ selectedNodes.push({
@ -205,7 +222,7 @@
}); });
} }
}); });
// 调用后端接口 // 调用后端接口
fetch('/api/update-prerequisites', { fetch('/api/update-prerequisites', {
method: 'POST', method: 'POST',
@ -217,20 +234,20 @@
prerequisites: selectedNodes prerequisites: selectedNodes
}) })
}) })
.then(response => response.json()) .then(response => response.json())
.then(data => { .then(data => {
if (data.code === 0) { if (data.code === 0) {
layer.msg('保存成功', {icon: 1}); layer.msg('保存成功', {icon: 1});
setTimeout(() => location.reload(), 1000); setTimeout(() => location.reload(), 1000);
} else { } else {
layer.msg('保存失败: ' + data.message, {icon: 2}); layer.msg('保存失败: ' + data.message, {icon: 2});
} }
}) })
.catch(error => { .catch(error => {
console.error('Error:', error); console.error('Error:', error);
layer.msg('保存出错', {icon: 2}); layer.msg('保存出错', {icon: 2});
}); });
layer.close(index); layer.close(index);
} }
}); });

Loading…
Cancel
Save