|
|
@@ -7,6 +7,108 @@ layui.config({
|
|
|
laytpl = layui.laytpl,
|
|
|
table = layui.table,
|
|
|
treeTable = layui.treeTable;
|
|
|
+ //用户列表
|
|
|
+ var tableIns = table.render({
|
|
|
+ elem: '#list',
|
|
|
+ url: '/silos/cms/books/contents/queryPage',
|
|
|
+ method: 'POST',
|
|
|
+ dataType: 'json',
|
|
|
+ contentType: 'application/json;charset=utf-8',
|
|
|
+ headers: {token: ''},
|
|
|
+ cellMinWidth: 95,
|
|
|
+ page: true,
|
|
|
+ height: "full-125",
|
|
|
+ limits: [10, 15, 20, 25],
|
|
|
+ limit: 15,
|
|
|
+ id: "listTable",
|
|
|
+ request: {
|
|
|
+ pageName: "pageNo",//重新定义当前页码参数名称
|
|
|
+ limitName: "pageRows"//重新定义每页大小参数名称
|
|
|
+ },
|
|
|
+ response: {
|
|
|
+ statusName: 'code', //数据状态的字段名称,默认:code
|
|
|
+ statusCode: 200, //成功的状态码,默认:0
|
|
|
+ msgName: 'msg', //状态信息的字段名称,默认:msg
|
|
|
+ countName: 'totalRows', //数据总数的字段名称,默认:count
|
|
|
+ dataName: 'data' //数据列表的字段名称,默认:data
|
|
|
+ },
|
|
|
+ where: {
|
|
|
+ //请求的参数写在where
|
|
|
+ },
|
|
|
+ parseData: function (res) {
|
|
|
+ return {
|
|
|
+ "code": res.code,
|
|
|
+ "msg": res.msg, //解析提示文本
|
|
|
+ "totalRows": res.data.totalRows, //解析数据长度
|
|
|
+ "data": res.data.dataList, //解析数据列表
|
|
|
+ };
|
|
|
+ },
|
|
|
+ cols: [[
|
|
|
+ {type: "checkbox", fixed: "left", width: 50},
|
|
|
+ {field: 'bookInfoId', title: '关联图书', minWidth: 100, align: "center"},
|
|
|
+ {field: 'chapterLevel', title: '章节层级', minWidth: 100, align: "center"},
|
|
|
+ {field: 'chapterNumber', title: '章节编号', minWidth: 100, align: "center"},
|
|
|
+ {field: 'chapterTitle', title: '章节标题', minWidth: 100, align: "center"},
|
|
|
+ {field: 'contentType', title: '内容类型', minWidth: 100, align: "center"},
|
|
|
+ {field: 'wordCount', title: '字数统计', align: 'center'},
|
|
|
+
|
|
|
+ {field: 'isPublic', title: '是否公开', minWidth: 100, align: "center"},
|
|
|
+ /*{field: 'userAvatar', title: '用户头像', minWidth:100, align:"center",templet:function(d){
|
|
|
+ return "<img src='"+d.userAvatar+"' style='width: 30px;height: 30px'>";
|
|
|
+ }},*/
|
|
|
+ {field: 'version', title: '内容版本', minWidth: 100, align: "center"},
|
|
|
+ {field: 'parentId', title: '父级章节', minWidth: 100, align: "center"},
|
|
|
+ {field: 'coverImage', title: '封面图片路径', minWidth: 100, align: "center"},
|
|
|
+ {
|
|
|
+ field: 'createTime', title: '创建时间', minWidth: 100, align: "center", templet: function (d) {
|
|
|
+ return showTime(d.createTime);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ field: 'updateTime', title: '修改时间', minWidth: 100, align: "center", templet: function (d) {
|
|
|
+ return showTime(d.updateTime);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {title: '操作', minWidth: 200, templet: '#listBar', fixed: "right", align: "center", toolBar: '#listBar'}
|
|
|
+ ]]
|
|
|
+ });
|
|
|
+ //时间转换函数
|
|
|
+ function showTime(tempDate) {
|
|
|
+ var d = new Date(tempDate);
|
|
|
+ var year = d.getFullYear();
|
|
|
+ var month = d.getMonth();
|
|
|
+ month++;
|
|
|
+ var day = d.getDate();
|
|
|
+ var hours = d.getHours();
|
|
|
+
|
|
|
+ var minutes = d.getMinutes();
|
|
|
+ var seconds = d.getSeconds();
|
|
|
+ month = month < 10 ? "0" + month : month;
|
|
|
+ day = day < 10 ? "0" + day : day;
|
|
|
+ hours = hours < 10 ? "0" + hours : hours;
|
|
|
+ minutes = minutes < 10 ? "0" + minutes : minutes;
|
|
|
+ seconds = seconds < 10 ? "0" + seconds : seconds;
|
|
|
+
|
|
|
+
|
|
|
+ var time = year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;
|
|
|
+ return time;
|
|
|
+ }
|
|
|
+ $(".search_btn").click(function () {
|
|
|
+ const searchInput = $("#searchInput").val();
|
|
|
+ table.reload("listTable", {
|
|
|
+ page: {
|
|
|
+ curr: 1 //重新从第 1 页开始
|
|
|
+ },
|
|
|
+ where: {
|
|
|
+ contentsName: searchInput,
|
|
|
+ contentType: $("#contentType").val(),
|
|
|
+ isPublic: $("#isPublic").val(),
|
|
|
+ version: $("#version").val(),
|
|
|
+ createBeginTime: $("#createTime").val(),
|
|
|
+ bookInfoId: $("#bookInfoId").val(),
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
$(".add_btn").click(function () {
|
|
|
edit();
|
|
|
})
|
|
|
@@ -53,535 +155,4 @@ layui.config({
|
|
|
layui.layer.full(window.sessionStorage.getItem("index"));
|
|
|
})
|
|
|
}
|
|
|
-})
|
|
|
-// 示例章节数据
|
|
|
-const chapters = [
|
|
|
- {
|
|
|
- id: 1,
|
|
|
- number: "1",
|
|
|
- title: "HTML基础",
|
|
|
- description: "学习HTML标签和文档结构",
|
|
|
- parentId: null,
|
|
|
- contentType: "mixed",
|
|
|
- wordCount: 5200,
|
|
|
- isPublic: true,
|
|
|
- version: "v1.2",
|
|
|
- subChapters: [
|
|
|
- {
|
|
|
- id: 101,
|
|
|
- number: "1.1",
|
|
|
- title: "HTML文档结构",
|
|
|
- description: "HTML文档的基本结构",
|
|
|
- parentId: 1,
|
|
|
- contentType: "text",
|
|
|
- wordCount: 1200,
|
|
|
- isPublic: true,
|
|
|
- version: "v1.0"
|
|
|
- },
|
|
|
- {
|
|
|
- id: 102,
|
|
|
- number: "1.2",
|
|
|
- title: "常用HTML标签",
|
|
|
- description: "常用HTML标签的使用方法",
|
|
|
- parentId: 1,
|
|
|
- contentType: "mixed",
|
|
|
- wordCount: 2500,
|
|
|
- isPublic: true,
|
|
|
- version: "v1.1"
|
|
|
- },
|
|
|
- {
|
|
|
- id: 103,
|
|
|
- number: "1.3",
|
|
|
- title: "表单元素",
|
|
|
- description: "HTML表单元素的使用",
|
|
|
- parentId: 1,
|
|
|
- contentType: "code",
|
|
|
- wordCount: 1500,
|
|
|
- isPublic: false,
|
|
|
- version: "v1.0"
|
|
|
- }
|
|
|
- ]
|
|
|
- },
|
|
|
- {
|
|
|
- id: 2,
|
|
|
- number: "2",
|
|
|
- title: "CSS样式",
|
|
|
- description: "掌握CSS选择器和样式规则",
|
|
|
- parentId: null,
|
|
|
- contentType: "mixed",
|
|
|
- wordCount: 6800,
|
|
|
- isPublic: true,
|
|
|
- version: "v1.3",
|
|
|
- subChapters: [
|
|
|
- {
|
|
|
- id: 201,
|
|
|
- number: "2.1",
|
|
|
- title: "CSS选择器",
|
|
|
- description: "CSS选择器的使用方法",
|
|
|
- parentId: 2,
|
|
|
- contentType: "text",
|
|
|
- wordCount: 1800,
|
|
|
- isPublic: true,
|
|
|
- version: "v1.0"
|
|
|
- },
|
|
|
- {
|
|
|
- id: 202,
|
|
|
- number: "2.2",
|
|
|
- title: "盒模型",
|
|
|
- description: "CSS盒模型的理解和应用",
|
|
|
- parentId: 2,
|
|
|
- contentType: "mixed",
|
|
|
- wordCount: 2200,
|
|
|
- isPublic: true,
|
|
|
- version: "v1.1"
|
|
|
- },
|
|
|
- {
|
|
|
- id: 203,
|
|
|
- number: "2.3",
|
|
|
- title: "Flexbox布局",
|
|
|
- description: "Flexbox布局的详细讲解",
|
|
|
- parentId: 2,
|
|
|
- contentType: "code",
|
|
|
- wordCount: 2800,
|
|
|
- isPublic: true,
|
|
|
- version: "v1.2"
|
|
|
- }
|
|
|
- ]
|
|
|
- },
|
|
|
- {
|
|
|
- id: 3,
|
|
|
- number: "3",
|
|
|
- title: "JavaScript编程",
|
|
|
- description: "学习JavaScript基础语法和DOM操作",
|
|
|
- parentId: null,
|
|
|
- contentType: "code",
|
|
|
- wordCount: 7500,
|
|
|
- isPublic: true,
|
|
|
- version: "v1.0",
|
|
|
- subChapters: []
|
|
|
- },
|
|
|
- {
|
|
|
- id: 4,
|
|
|
- number: "4",
|
|
|
- title: "响应式设计",
|
|
|
- description: "创建适应不同设备的网页",
|
|
|
- parentId: null,
|
|
|
- contentType: "mixed",
|
|
|
- wordCount: 4200,
|
|
|
- isPublic: false,
|
|
|
- version: "v0.8",
|
|
|
- subChapters: [
|
|
|
- {
|
|
|
- id: 401,
|
|
|
- number: "4.1",
|
|
|
- title: "媒体查询",
|
|
|
- description: "CSS媒体查询的使用",
|
|
|
- parentId: 4,
|
|
|
- contentType: "code",
|
|
|
- wordCount: 1500,
|
|
|
- isPublic: true,
|
|
|
- version: "v1.0"
|
|
|
- },
|
|
|
- {
|
|
|
- id: 402,
|
|
|
- number: "4.2",
|
|
|
- title: "移动优先设计",
|
|
|
- description: "移动优先的设计理念",
|
|
|
- parentId: 4,
|
|
|
- contentType: "text",
|
|
|
- wordCount: 2700,
|
|
|
- isPublic: false,
|
|
|
- version: "v0.5"
|
|
|
- }
|
|
|
- ]
|
|
|
- }
|
|
|
-];
|
|
|
-
|
|
|
-let selectedChapterId = null;
|
|
|
-let editingChapterId = null;
|
|
|
-
|
|
|
-// 内容类型映射
|
|
|
-const contentTypeMap = {
|
|
|
- "text": { text: "纯文本", class: "type-text" },
|
|
|
- "code": { text: "代码示例", class: "type-code" },
|
|
|
- "mixed": { text: "混合内容", class: "type-mixed" }
|
|
|
-};
|
|
|
-
|
|
|
-// 生成章节列表
|
|
|
-function renderChapters() {
|
|
|
- const chaptersList = document.getElementById('chaptersList');
|
|
|
-
|
|
|
- if (chapters.length === 0) {
|
|
|
- chaptersList.innerHTML = `
|
|
|
- <div class="empty-state">
|
|
|
- <i class="fas fa-book-open"></i>
|
|
|
- <h3>暂无章节</h3>
|
|
|
- <p>点击"添加章节"按钮开始创建章节</p>
|
|
|
- </div>
|
|
|
- `;
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- let chaptersHTML = '';
|
|
|
-
|
|
|
- chapters.forEach(chapter => {
|
|
|
- const isActive = selectedChapterId === chapter.id;
|
|
|
-
|
|
|
- chaptersHTML += `
|
|
|
- <div class="chapter-item ${isActive ? 'active' : ''}" data-id="${chapter.id}">
|
|
|
- <div class="chapter-drag">
|
|
|
- <i class="fas fa-grip-vertical"></i>
|
|
|
- </div>
|
|
|
- <div class="chapter-number">${chapter.number}</div>
|
|
|
- <div class="chapter-content">
|
|
|
- <div class="chapter-title">${chapter.title}</div>
|
|
|
- <div class="chapter-meta">
|
|
|
- <span class="content-type-badge ${contentTypeMap[chapter.contentType].class}">
|
|
|
- ${contentTypeMap[chapter.contentType].text}
|
|
|
- </span>
|
|
|
- <span class="word-count">
|
|
|
- <i class="fas fa-file-word"></i> ${chapter.wordCount}字
|
|
|
- </span>
|
|
|
- <span class="status-badge ${chapter.isPublic ? 'status-public' : 'status-private'}">
|
|
|
- ${chapter.isPublic ? '公开' : '不公开'}
|
|
|
- </span>
|
|
|
- <span class="version-badge">${chapter.version}</span>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- <div class="chapter-actions">
|
|
|
- <button class="action-btn edit-btn" data-id="${chapter.id}">
|
|
|
- <i class="fas fa-edit"></i>
|
|
|
- </button>
|
|
|
- <button class="action-btn delete-btn" data-id="${chapter.id}">
|
|
|
- <i class="fas fa-trash"></i>
|
|
|
- </button>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- `;
|
|
|
-
|
|
|
- // 添加子章节
|
|
|
- if (chapter.subChapters && chapter.subChapters.length > 0) {
|
|
|
- chaptersHTML += `<div class="sub-chapters">`;
|
|
|
-
|
|
|
- chapter.subChapters.forEach(subChapter => {
|
|
|
- const isSubActive = selectedChapterId === subChapter.id;
|
|
|
-
|
|
|
- chaptersHTML += `
|
|
|
- <div class="sub-chapter-item ${isSubActive ? 'active' : ''}" data-id="${subChapter.id}">
|
|
|
- <div class="chapter-drag">
|
|
|
- <i class="fas fa-grip-vertical"></i>
|
|
|
- </div>
|
|
|
- <div class="sub-chapter-number">${subChapter.number}</div>
|
|
|
- <div class="sub-chapter-content">
|
|
|
- <div class="sub-chapter-title">${subChapter.title}</div>
|
|
|
- <div class="sub-chapter-meta">
|
|
|
- <span class="content-type-badge ${contentTypeMap[subChapter.contentType].class}">
|
|
|
- ${contentTypeMap[subChapter.contentType].text}
|
|
|
- </span>
|
|
|
- <span class="word-count">
|
|
|
- <i class="fas fa-file-word"></i> ${subChapter.wordCount}字
|
|
|
- </span>
|
|
|
- <span class="status-badge ${subChapter.isPublic ? 'status-public' : 'status-private'}">
|
|
|
- ${subChapter.isPublic ? '公开' : '不公开'}
|
|
|
- </span>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- <div class="chapter-actions">
|
|
|
- <button class="action-btn edit-btn" data-id="${subChapter.id}">
|
|
|
- <i class="fas fa-edit"></i>
|
|
|
- </button>
|
|
|
- <button class="action-btn delete-btn" data-id="${subChapter.id}">
|
|
|
- <i class="fas fa-trash"></i>
|
|
|
- </button>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- `;
|
|
|
- });
|
|
|
-
|
|
|
- chaptersHTML += `</div>`;
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- chaptersList.innerHTML = chaptersHTML;
|
|
|
-}
|
|
|
-
|
|
|
-// 显示章节详情
|
|
|
-function showChapterDetail(chapterId) {
|
|
|
- const chapterDetailContent = document.getElementById('chapterDetailContent');
|
|
|
- let chapter = null;
|
|
|
-
|
|
|
- // 查找章节(包括子章节)
|
|
|
- for (const parentChapter of chapters) {
|
|
|
- if (parentChapter.id === chapterId) {
|
|
|
- chapter = parentChapter;
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- for (const subChapter of parentChapter.subChapters) {
|
|
|
- if (subChapter.id === chapterId) {
|
|
|
- chapter = subChapter;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (chapter) break;
|
|
|
- }
|
|
|
-
|
|
|
- if (!chapter) return;
|
|
|
-
|
|
|
- selectedChapterId = chapterId;
|
|
|
-
|
|
|
- chapterDetailContent.innerHTML = `
|
|
|
- <div class="detail-item">
|
|
|
- <div class="detail-label">章节标题</div>
|
|
|
- <div class="detail-value">${chapter.title}</div>
|
|
|
- </div>
|
|
|
- <div class="detail-item">
|
|
|
- <div class="detail-label">章节编号</div>
|
|
|
- <div class="detail-value">${chapter.number}</div>
|
|
|
- </div>
|
|
|
- <div class="detail-item">
|
|
|
- <div class="detail-label">内容类型</div>
|
|
|
- <div class="detail-value">
|
|
|
- <span class="content-type-badge ${contentTypeMap[chapter.contentType].class}">
|
|
|
- ${contentTypeMap[chapter.contentType].text}
|
|
|
- </span>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- <div class="detail-item">
|
|
|
- <div class="detail-label">字数统计</div>
|
|
|
- <div class="detail-value">
|
|
|
- <span class="word-count">
|
|
|
- <i class="fas fa-file-word"></i> ${chapter.wordCount} 字
|
|
|
- </span>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- <div class="detail-item">
|
|
|
- <div class="detail-label">公开状态</div>
|
|
|
- <div class="detail-value">
|
|
|
- <span class="status-badge ${chapter.isPublic ? 'status-public' : 'status-private'}">
|
|
|
- ${chapter.isPublic ? '公开' : '不公开'}
|
|
|
- </span>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- <div class="detail-item">
|
|
|
- <div class="detail-label">内容版本</div>
|
|
|
- <div class="detail-value">
|
|
|
- <span class="version-badge">${chapter.version}</span>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- <div class="detail-item">
|
|
|
- <div class="detail-label">章节描述</div>
|
|
|
- <div class="detail-value">${chapter.description || '暂无描述'}</div>
|
|
|
- </div>
|
|
|
- `;
|
|
|
-
|
|
|
- renderChapters();
|
|
|
-}
|
|
|
-
|
|
|
-// 初始化页面
|
|
|
-document.addEventListener('DOMContentLoaded', function() {
|
|
|
- renderChapters();
|
|
|
-
|
|
|
- // 章节点击事件
|
|
|
- document.addEventListener('click', function(e) {
|
|
|
- const chapterItem = e.target.closest('.chapter-item, .sub-chapter-item');
|
|
|
- if (chapterItem) {
|
|
|
- const chapterId = parseInt(chapterItem.getAttribute('data-id'));
|
|
|
- showChapterDetail(chapterId);
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- // 添加章节按钮
|
|
|
- // document.getElementById('addChapterBtn').addEventListener('click', function() {
|
|
|
- // editingChapterId = null;
|
|
|
- // document.getElementById('modalTitle').textContent = '添加新章节';
|
|
|
- // document.getElementById('chapterForm').reset();
|
|
|
- // document.getElementById('chapterModal').style.display = 'flex';
|
|
|
- // });
|
|
|
-
|
|
|
- // 编辑章节按钮
|
|
|
- document.addEventListener('click', function(e) {
|
|
|
- if (e.target.closest('.edit-btn')) {
|
|
|
- const chapterId = parseInt(e.target.closest('.edit-btn').getAttribute('data-id'));
|
|
|
- editingChapterId = chapterId;
|
|
|
-
|
|
|
- // 查找章节数据
|
|
|
- let chapter = null;
|
|
|
- for (const parentChapter of chapters) {
|
|
|
- if (parentChapter.id === chapterId) {
|
|
|
- chapter = parentChapter;
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- for (const subChapter of parentChapter.subChapters) {
|
|
|
- if (subChapter.id === chapterId) {
|
|
|
- chapter = subChapter;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (chapter) break;
|
|
|
- }
|
|
|
-
|
|
|
- if (chapter) {
|
|
|
- document.getElementById('modalTitle').textContent = '编辑章节';
|
|
|
- document.getElementById('chapterTitle').value = chapter.title;
|
|
|
- document.getElementById('chapterNumber').value = chapter.number;
|
|
|
- document.getElementById('chapterDescription').value = chapter.description || '';
|
|
|
- document.getElementById('chapterContentType').value = chapter.contentType;
|
|
|
- document.getElementById('chapterWordCount').value = chapter.wordCount;
|
|
|
- document.getElementById('chapterPublic').value = chapter.isPublic ? 'true' : 'false';
|
|
|
- document.getElementById('chapterVersion').value = chapter.version;
|
|
|
-
|
|
|
- // 设置父级章节(如果是子章节)
|
|
|
- if (chapter.parentId) {
|
|
|
- document.getElementById('chapterParent').value = chapter.parentId;
|
|
|
- } else {
|
|
|
- document.getElementById('chapterParent').value = '';
|
|
|
- }
|
|
|
-
|
|
|
- document.getElementById('chapterModal').style.display = 'flex';
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- // 关闭模态框
|
|
|
- document.getElementById('closeModal').addEventListener('click', function() {
|
|
|
- document.getElementById('chapterModal').style.display = 'none';
|
|
|
- });
|
|
|
-
|
|
|
- document.getElementById('cancelBtn').addEventListener('click', function() {
|
|
|
- document.getElementById('chapterModal').style.display = 'none';
|
|
|
- });
|
|
|
-
|
|
|
- // 章节表单提交
|
|
|
- document.getElementById('chapterForm').addEventListener('submit', function(e) {
|
|
|
- e.preventDefault();
|
|
|
-
|
|
|
- const title = document.getElementById('chapterTitle').value;
|
|
|
- const number = document.getElementById('chapterNumber').value;
|
|
|
- const description = document.getElementById('chapterDescription').value;
|
|
|
- const contentType = document.getElementById('chapterContentType').value;
|
|
|
- const wordCount = parseInt(document.getElementById('chapterWordCount').value);
|
|
|
- const isPublic = document.getElementById('chapterPublic').value === 'true';
|
|
|
- const version = document.getElementById('chapterVersion').value;
|
|
|
- const parentId = document.getElementById('chapterParent').value ?
|
|
|
- parseInt(document.getElementById('chapterParent').value) : null;
|
|
|
-
|
|
|
- if (!title || !number) {
|
|
|
- alert('请输入章节标题和编号');
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if (editingChapterId) {
|
|
|
- // 编辑现有章节
|
|
|
- for (const parentChapter of chapters) {
|
|
|
- if (parentChapter.id === editingChapterId) {
|
|
|
- parentChapter.title = title;
|
|
|
- parentChapter.number = number;
|
|
|
- parentChapter.description = description;
|
|
|
- parentChapter.contentType = contentType;
|
|
|
- parentChapter.wordCount = wordCount;
|
|
|
- parentChapter.isPublic = isPublic;
|
|
|
- parentChapter.version = version;
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- for (const subChapter of parentChapter.subChapters) {
|
|
|
- if (subChapter.id === editingChapterId) {
|
|
|
- subChapter.title = title;
|
|
|
- subChapter.number = number;
|
|
|
- subChapter.description = description;
|
|
|
- subChapter.contentType = contentType;
|
|
|
- subChapter.wordCount = wordCount;
|
|
|
- subChapter.isPublic = isPublic;
|
|
|
- subChapter.version = version;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- alert('章节更新成功!');
|
|
|
- } else {
|
|
|
- // 添加新章节
|
|
|
- const newChapter = {
|
|
|
- id: chapters.length > 0 ? Math.max(...chapters.map(c => c.id)) + 1 : 1,
|
|
|
- number,
|
|
|
- title,
|
|
|
- description,
|
|
|
- contentType,
|
|
|
- wordCount,
|
|
|
- isPublic,
|
|
|
- version,
|
|
|
- parentId,
|
|
|
- subChapters: []
|
|
|
- };
|
|
|
-
|
|
|
- if (parentId) {
|
|
|
- // 添加到父章节的子章节中
|
|
|
- for (const chapter of chapters) {
|
|
|
- if (chapter.id === parentId) {
|
|
|
- chapter.subChapters.push(newChapter);
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- chapters.push(newChapter);
|
|
|
- }
|
|
|
-
|
|
|
- alert('章节添加成功!');
|
|
|
- }
|
|
|
-
|
|
|
- document.getElementById('chapterModal').style.display = 'none';
|
|
|
- renderChapters();
|
|
|
-
|
|
|
- // 如果正在查看详情,更新详情视图
|
|
|
- if (selectedChapterId) {
|
|
|
- showChapterDetail(selectedChapterId);
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- // 删除章节
|
|
|
- document.addEventListener('click', function(e) {
|
|
|
- if (e.target.closest('.delete-btn')) {
|
|
|
- const chapterId = parseInt(e.target.closest('.delete-btn').getAttribute('data-id'));
|
|
|
-
|
|
|
- if (confirm('确定要删除这个章节吗?此操作不可恢复。')) {
|
|
|
- let deleted = false;
|
|
|
-
|
|
|
- // 查找并删除章节
|
|
|
- for (let i = 0; i < chapters.length; i++) {
|
|
|
- if (chapters[i].id === chapterId) {
|
|
|
- chapters.splice(i, 1);
|
|
|
- deleted = true;
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- for (let j = 0; j < chapters[i].subChapters.length; j++) {
|
|
|
- if (chapters[i].subChapters[j].id === chapterId) {
|
|
|
- chapters[i].subChapters.splice(j, 1);
|
|
|
- deleted = true;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (deleted) break;
|
|
|
- }
|
|
|
-
|
|
|
- if (deleted) {
|
|
|
- renderChapters();
|
|
|
- document.getElementById('chapterDetailContent').innerHTML = `
|
|
|
- <div class="empty-state">
|
|
|
- <i class="fas fa-file-alt"></i>
|
|
|
- <h3>选择章节查看详情</h3>
|
|
|
- <p>点击左侧章节列表中的项目查看详细信息</p>
|
|
|
- </div>
|
|
|
- `;
|
|
|
- selectedChapterId = null;
|
|
|
- alert('章节已删除!');
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
-});
|
|
|
+})
|