提交 58d8afeb authored 作者: 王鹏飞's avatar 王鹏飞

chore: update

上级 b3ca2028
差异被折叠。
...@@ -70,10 +70,10 @@ const generateId = () => { ...@@ -70,10 +70,10 @@ const generateId = () => {
// 添加根节点 // 添加根节点
const addRootNode = () => { const addRootNode = () => {
if (treeData.value.length > 0) { // if (treeData.value.length > 0) {
ElMessage.warning('只能添加一个根节点') // ElMessage.warning('只能添加一个根节点')
return // return
} // }
const newNode = { const newNode = {
id: generateId(), id: generateId(),
...@@ -226,7 +226,7 @@ onMounted(() => { ...@@ -226,7 +226,7 @@ onMounted(() => {
</script> </script>
<template> <template>
<el-dialog draggable width="800px" title="添加知识点" :model-value="true" @close="emit('update:modelValue', false)"> <el-dialog draggable width="1000px" title="添加知识点" :model-value="true" @close="emit('update:modelValue', false)">
<el-tabs v-model="activeName"> <el-tabs v-model="activeName">
<el-tab-pane label="树状结构" name="first"> <el-tab-pane label="树状结构" name="first">
<div class="knowledge-tree-container"> <div class="knowledge-tree-container">
......
...@@ -103,7 +103,7 @@ onMounted(() => { ...@@ -103,7 +103,7 @@ onMounted(() => {
<el-dialog <el-dialog
:model-value="isShowKnowledgeGraphPreview" :model-value="isShowKnowledgeGraphPreview"
:title="title || '知识点脑图预览'" :title="title || '知识点脑图预览'"
width="800px" width="1000px"
:before-close="handleClose" :before-close="handleClose"
draggable draggable
destroy-on-close destroy-on-close
......
...@@ -16,8 +16,9 @@ import AddTextbookDialog from '../components/stepTwoComponents/AddTextbookDialog ...@@ -16,8 +16,9 @@ import AddTextbookDialog from '../components/stepTwoComponents/AddTextbookDialog
import AddGraphbookDialog from '../components/stepTwoComponents/AddGraphbookDialog.vue' import AddGraphbookDialog from '../components/stepTwoComponents/AddGraphbookDialog.vue'
import AddKnowledge from '../components/stepTwoComponents/AddKnowledge.vue' import AddKnowledge from '../components/stepTwoComponents/AddKnowledge.vue'
import KnowledgeGraphPreview from '../components/stepTwoComponents/KnowledgeGraphPreview.vue' import KnowledgeGraphPreview from '../components/stepTwoComponents/KnowledgeGraphPreview.vue'
import { knowledgeTree } from '../assets/demo'
import OpenRules from '../components/stepTwoComponents/OpenRules.vue' import OpenRules from '../components/stepTwoComponents/OpenRules.vue'
const route = useRoute() const route = useRoute()
const router = useRouter() const router = useRouter()
const isEditCourse = route.query.isEditCourse as string const isEditCourse = route.query.isEditCourse as string
...@@ -111,9 +112,122 @@ const handleChapterList = () => { ...@@ -111,9 +112,122 @@ const handleChapterList = () => {
}) })
} }
}) })
// 设置知识点默认值
setDefaultKnowledgePoints(res.data[0])
}) })
} }
// 设置知识点默认值
const setDefaultKnowledgePoints = (courseData: any) => {
if (!courseData) return
const courseName = courseData.name
const storageKey = 'knowledge'
// 获取现有的知识点数据
let existingData = []
try {
existingData = JSON.parse(localStorage.getItem(storageKey) || '[]')
} catch (error) {
console.error('读取localStorage失败:', error)
existingData = []
}
// 遍历课程章节数据,匹配knowledgeTree中的默认知识点
const processChapters = (chapters: any[], parentChapterName = '') => {
chapters.forEach((chapter) => {
if (chapter.depth === '1') {
// 处理章,递归处理其子节点(节)
const chapterName = chapter.name
if (chapter.children && chapter.children.length > 0) {
processChapters(chapter.children, chapterName)
}
} else if (chapter.depth === '2') {
// 只有节才有知识点,处理节
const sectionName = chapter.name
const fullChapterName = parentChapterName
// 在knowledgeTree中查找匹配的知识点
const matchedKnowledge = knowledgeTree.find(
(item: any) =>
item.courseName === courseName && item.chapterName === fullChapterName && item.sectionName === sectionName
)
if (matchedKnowledge) {
// 检查是否已经存在该节的知识点数据
const existingSectionData = existingData.find((item: any) => item.section_id === chapter.id)
if (!existingSectionData) {
// 转换知识点数据格式,添加必要的字段
// matchedKnowledge.children 包含多个根知识点,每个根知识点都有自己的子知识点树
const knowledgeData = convertKnowledgeToStorageFormat(
matchedKnowledge.children,
courseData.id,
chapter.parent_id,
chapter.id
)
// 添加到现有数据中
existingData.push(...knowledgeData)
console.log(`为节 "${sectionName}" 设置了默认知识点`)
}
}
}
})
}
// 处理课程数据
if (courseData.children && courseData.children.length > 0) {
processChapters(courseData.children)
}
// 保存到localStorage
try {
localStorage.setItem(storageKey, JSON.stringify(existingData))
console.log('知识点默认值设置完成')
} catch (error) {
console.error('保存知识点数据到localStorage失败:', error)
}
}
// 转换知识点数据格式
const convertKnowledgeToStorageFormat = (
knowledgeNodes: any[],
courseId: string,
chapterId: string,
sectionId: string
): any[] => {
const result: any[] = []
const processNode = (node: any): any => {
const convertedNode = {
id: node.id,
label: node.label,
course_id: id,
chapter_id: chapterId,
section_id: sectionId,
children: [] as any[],
}
if (node.children && node.children.length > 0) {
node.children.forEach((child: any) => {
convertedNode.children.push(processNode(child))
})
}
return convertedNode
}
// 处理每个根知识点及其子知识点树
knowledgeNodes.forEach((rootNode) => {
result.push(processNode(rootNode))
})
return result
}
// 新增章节 // 新增章节
const handleAddChapter = () => { const handleAddChapter = () => {
isShowDialog.value = true isShowDialog.value = true
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论