|
@@ -3,7 +3,7 @@
|
|
|
<div class="breadcrumb">
|
|
|
<ul>
|
|
|
<li>
|
|
|
- <span @click="$router.push('/')">教材管理</span>
|
|
|
+ <span class="pointer" @click="$router.push('/')">教材管理</span>
|
|
|
</li>
|
|
|
<li>
|
|
|
<span class="separator">></span>
|
|
@@ -40,28 +40,28 @@
|
|
|
</div>
|
|
|
|
|
|
<div v-for="{ id, name, nodes: children } in nodes" :key="id" class="catalogue">
|
|
|
+ <!-- 一级目录 -->
|
|
|
<div class="catalogue-title">{{ name }}</div>
|
|
|
<template v-for="item in children">
|
|
|
+ <!-- 二级目录或内容 -->
|
|
|
<div
|
|
|
:key="item.id"
|
|
|
:class="['catalogue-item', item.is_leaf_chapter === 'true' ? 'content' : 'subdirectory']"
|
|
|
>
|
|
|
<span class="name">{{ item.name }}</span>
|
|
|
<span class="time">{{ item.time }} {{ item.editor }}</span>
|
|
|
- <span
|
|
|
- v-if="item.is_leaf === 'true' && item.is_leaf_chapter === 'true'"
|
|
|
- class="edit"
|
|
|
- @click="editBookContent(item.id)"
|
|
|
- >编辑</span
|
|
|
- >
|
|
|
+ <span v-if="item.is_leaf_chapter === 'true'" class="edit" @click="editBookContent(item.id)">编辑</span>
|
|
|
</div>
|
|
|
- <div v-for="li in item.nodes" :key="li.id">
|
|
|
- <div :class="['catalogue-item', 'children']">
|
|
|
- <span class="name">{{ li?.name }}</span>
|
|
|
- <span class="time">{{ li?.time }} {{ li.editor }}</span>
|
|
|
- <span v-if="li.is_leaf_chapter === 'true'" class="edit" @click="editBookContent(li.id)">编辑</span>
|
|
|
+ <!-- 二级目录的内容 -->
|
|
|
+ <template v-if="item.is_leaf_chapter === 'false' && item.nodes?.length > 0">
|
|
|
+ <div v-for="li in item.nodes" :key="li.id">
|
|
|
+ <div :class="['catalogue-item', 'children']">
|
|
|
+ <span class="name">{{ li?.name }}</span>
|
|
|
+ <span class="time">{{ li?.time }} {{ li.editor }}</span>
|
|
|
+ <span v-if="li.is_leaf_chapter === 'true'" class="edit" @click="editBookContent(li.id)">编辑</span>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
- </div>
|
|
|
+ </template>
|
|
|
</template>
|
|
|
</div>
|
|
|
</template>
|
|
@@ -238,6 +238,12 @@ export default {
|
|
|
this.nodes = nodes ?? [];
|
|
|
});
|
|
|
},
|
|
|
+ /**
|
|
|
+ * @description 确认编辑节点
|
|
|
+ * @param {string} id 节点id
|
|
|
+ * @param {string} parent_id 父节点id
|
|
|
+ * @param {string} is_leaf_chapter 是否是内容目录
|
|
|
+ */
|
|
|
confirmEditNode(id, parent_id, is_leaf_chapter) {
|
|
|
const position = this.findNodeIndexById(this.nodes, id);
|
|
|
let nodes = this.nodes;
|
|
@@ -249,7 +255,7 @@ export default {
|
|
|
this.$message.error('请输入名称');
|
|
|
return;
|
|
|
}
|
|
|
- if (nodes[position[position.length - 1]].temporary) {
|
|
|
+ if (nodes[position[position.length - 1]]?.temporary) {
|
|
|
this.addChapterToBook(name, parent_id, is_leaf_chapter);
|
|
|
} else {
|
|
|
this.updateChapter(id, name);
|
|
@@ -266,6 +272,10 @@ export default {
|
|
|
this.curEditNodeId = '';
|
|
|
});
|
|
|
},
|
|
|
+ /**
|
|
|
+ * @description 删除目录
|
|
|
+ * @param {string} id 目录id
|
|
|
+ */
|
|
|
deleteChapter(id) {
|
|
|
this.$confirm('确定删除该目录吗?', '提示', {
|
|
|
confirmButtonText: '确定',
|
|
@@ -273,14 +283,19 @@ export default {
|
|
|
type: 'warning',
|
|
|
})
|
|
|
.then(() => {
|
|
|
- DeleteChapter({ id, is_force_delete: 'true' }).then(() => {
|
|
|
- this.$message.success('删除成功');
|
|
|
- this.getBookChapterStruct();
|
|
|
- });
|
|
|
+ DeleteChapter({ id, is_force_delete: 'true' })
|
|
|
+ .then(() => {
|
|
|
+ this.$message.success('删除成功');
|
|
|
+ this.getBookChapterStruct();
|
|
|
+ })
|
|
|
+ .catch(() => {});
|
|
|
})
|
|
|
.catch(() => {});
|
|
|
},
|
|
|
createCatalogue() {
|
|
|
+ if (this.curEditNodeId) {
|
|
|
+ this.cancelEditNode(this.curEditNodeId);
|
|
|
+ }
|
|
|
let id = new Date().getTime();
|
|
|
const level_index = this.nodes.length;
|
|
|
this.nodes.push({
|
|
@@ -293,7 +308,15 @@ export default {
|
|
|
});
|
|
|
this.curEditNodeId = id;
|
|
|
},
|
|
|
+ /**
|
|
|
+ * 创建子目录或内容
|
|
|
+ * @param {string} parent_id 父目录id
|
|
|
+ * @param {string} is_leaf_chapter 是否是内容目录
|
|
|
+ */
|
|
|
createChildCatalogue(parent_id, is_leaf_chapter) {
|
|
|
+ if (this.curEditNodeId) {
|
|
|
+ this.cancelEditNode(this.curEditNodeId);
|
|
|
+ }
|
|
|
let id = new Date().getTime();
|
|
|
let position = this.findNodeIndexById(this.nodes, parent_id);
|
|
|
|
|
@@ -319,6 +342,9 @@ export default {
|
|
|
});
|
|
|
this.curEditNodeId = id;
|
|
|
},
|
|
|
+ /**
|
|
|
+ * 设置当前编辑节点id
|
|
|
+ */
|
|
|
setCurEditNodeId(id) {
|
|
|
this.curEditNodeId = id;
|
|
|
},
|
|
@@ -355,7 +381,7 @@ export default {
|
|
|
nodes = nodes[indexArr[i]].nodes;
|
|
|
}
|
|
|
// 删除临时节点
|
|
|
- if (nodes[indexArr[indexArr.length - 1]].temporary) {
|
|
|
+ if (nodes[indexArr[indexArr.length - 1]]?.temporary) {
|
|
|
nodes.splice(indexArr[indexArr.length - 1], 1);
|
|
|
}
|
|
|
this.curEditNodeId = '';
|