rename chapter/lesson

This commit is contained in:
Cai
2025-09-19 09:06:37 +00:00
parent 6575ee80bc
commit 24f191d5a5
9 changed files with 709 additions and 430 deletions

View File

@@ -3,12 +3,12 @@ let material_id = null;
function lessonTemplate(material_id,chapter_name,lesson_name) {
return `
<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}')">
<span class="lesson-text" onclick="editLesson(this)">${lesson_name}
<button class="icon-btn edit-btn" onclick="editLesson(this)">
<i class="fas fa-pencil-alt"></i>
</button>
</span>
<div class="delete-btn-container" onclick="deleteLesson('${material_id}','${chapter_name}','${lesson_name}')">
<div class="delete-btn-container" onclick="deleteLesson(this)">
<button class="icon-btn delete-btn">
<i class="fas fa-trash-alt"></i>
</button>
@@ -216,7 +216,20 @@ function checkAndAddLesson(input, chapterTitle, addButton) {
})
}
function deleteLesson(material_id,chapter_name,lesson_name) {
function deleteLesson(elemOrEvent) {
const el = elemOrEvent?.target ? elemOrEvent.target : elemOrEvent;
const li = el?.closest?.('li.lesson-item');
if (!li) {
console.warn('未找到父级 lesson-item');
return;
}
const { materialId, chapterName, lessonName } = li.dataset;
const material_id = materialId;
const chapter_name = chapterName;
const lesson_name = lessonName;
if (!window.confirm(`确认删除课时「${lesson_name}」吗?`)){
return;
}
const lessonItems = document.querySelectorAll('.lesson-item');
lessonItems.forEach(item => {
if (item.dataset.lessonName === lesson_name && item.dataset.chapterName === chapter_name && item.dataset.materialId === material_id) {
@@ -242,7 +255,21 @@ function deleteLesson(material_id,chapter_name,lesson_name) {
}
function editLesson(material_id,chapter_name,lesson_name) {
function editLesson(elemOrEvent) {
const el = elemOrEvent?.target ? elemOrEvent.target : elemOrEvent;
const li = el?.closest?.('li.lesson-item');
if (!li) {
console.warn('未找到父级 lesson-item');
return;
}
const { materialId, chapterName, lessonName } = li.dataset;
const material_id = materialId;
const chapter_name = chapterName;
const lesson_name = lessonName;
const renameMode = document.getElementById('toggle-rename').getAttribute('aria-pressed') === 'true';
if (renameMode) {
return;
}
// 编辑课时的逻辑
alert("编辑课时: " + lesson_name);
window.location.href = `/api/materials/${material_id}/chapters/${chapter_name}/lessons/${lesson_name}`;