教师教材编辑页面

This commit is contained in:
CakeCN
2025-08-31 00:30:53 +08:00
parent 06e2e69b44
commit b18c981367
10 changed files with 573 additions and 38 deletions

View File

@@ -1,16 +1,18 @@
let material_id = null;
function lessonTemplate(lesson_name) {
function lessonTemplate(material_id,chapter_name,lesson_name) {
return `
<li class="lesson-item">
<span class="lesson-text" onclick="editLesson('${lesson_name}')">${lesson_name}
<button class="icon-btn edit-btn" onclick="editLesson('${lesson_name}')">
<li class="lesson-item" data-material-id="${material_id}" data-chapter-name="${chapter_name}" data-lesson-name="${lesson_name}">
<span class="lesson-text" onclick="editLesson('${material_id}','${chapter_name}','${lesson_name}')">${lesson_name}
<button class="icon-btn edit-btn" onclick="editLesson('${material_id}','${chapter_name}','${lesson_name}')">
<i class="fas fa-pencil-alt"></i>
</button>
</span>
<button class="icon-btn delete-btn" onclick="deleteLesson('${lesson_name}')">
<div class="delete-btn-container" onclick="deleteLesson('${material_id}','${chapter_name}','${lesson_name}')">
<button class="icon-btn delete-btn">
<i class="fas fa-trash-alt"></i>
</button>
</div>
</li>
`;
}
@@ -140,7 +142,7 @@ function renderChapters(courseId) {
const lessonList = document.createElement('ul');
chapter.lessons.forEach(lesson => {
const lessonItem = document.createElement('li');
lessonItem.innerHTML = lessonTemplate(lesson.lesson_name);
lessonItem.innerHTML = lessonTemplate(material_id,chapter.chapter_name,lesson.lesson_name);
lessonList.appendChild(lessonItem);
});
chapterItem.appendChild(lessonList);
@@ -195,7 +197,7 @@ function checkAndAddLesson(input, chapterTitle, addButton) {
const lessonsList = chapterItem.querySelector('ul');
const lessonItem = document.createElement('span');
lessonItem.innerHTML = lessonTemplate(lessonName);
lessonItem.innerHTML = lessonTemplate(material_id, chapterTitle, lessonName);
lessonsList.appendChild(lessonItem); // 将新课时添加到章节下
input.remove(); // 删除输入框
@@ -208,19 +210,37 @@ function checkAndAddLesson(input, chapterTitle, addButton) {
body: JSON.stringify({chapter_name: chapterTitle, lesson_name: lessonName})
})
}
function deleteLesson(lesson) {
function deleteLesson(material_id,chapter_name,lesson_name) {
const lessonItems = document.querySelectorAll('.lesson-item');
lessonItems.forEach(item => {
if (item.querySelector('.lesson-text').textContent === lesson) {
item.remove(); // 删除对应的课时项
if (item.dataset.lessonName === lesson_name && item.dataset.chapterName === chapter_name && item.dataset.materialId === material_id) {
fetch(`/materials/deletelesson/${material_id}`, {
method: 'DELETE',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({chapter_name: chapter_name, lesson_name: lesson_name})
})
.then(response => response.json())
.then(data => {
alert(data.message);
item.remove(); // 删除对应的课时项
renderChapters(material_id);
return;
})
.catch(error => {
console.error('Error deleting lesson:', error);
});
}
});
}
function editLesson(lesson) {
function editLesson(material_id,chapter_name,lesson_name) {
// 编辑课时的逻辑
alert("编辑课时: " + lesson);
alert("编辑课时: " + lesson_name);
window.location.href = `/api/materials/${material_id}/chapters/${chapter_name}/lessons/${lesson_name}`;
}
function closeCourseDetails() {