lyc-dev #223

Merged
lyc merged 3 commits from lyc-dev into main 2024-09-19 15:15:27 +08:00
1 changed files with 49 additions and 10 deletions
Showing only changes of commit db2be260a7 - Show all commits

View File

@ -6,7 +6,7 @@
<i class="iconfont icon-xiangyou"></i> <i class="iconfont icon-xiangyou"></i>
</div> </div>
<div class="book-list" v-loading="treeLoading"> <div class="book-list" v-loading="treeLoading">
<el-tree ref="refTree" :data="treeData" :props="defaultProps" node-key="id" <el-tree ref="refTree" :data="treeData" accordion :props="defaultProps" node-key="id"
:default-expanded-keys="defaultExpandedKeys" :current-node-key="currentNodeId" highlight-current :default-expanded-keys="defaultExpandedKeys" :current-node-key="currentNodeId" highlight-current
@node-click="handleNodeClick"> @node-click="handleNodeClick">
<template #default="{ node }"> <template #default="{ node }">
@ -134,6 +134,10 @@ const changeBook = ({ id, itemtitle, avartar, fileurl }) => {
curBookName.value = itemtitle curBookName.value = itemtitle
curBookImg.value = BaseUrl + avartar curBookImg.value = BaseUrl + avartar
curBookPath.value = fileurl curBookPath.value = fileurl
localStorage.removeItem('defaultExpandedKeys')
localStorage.removeItem('currentNodeId')
localStorage.setItem('curBook', JSON.stringify({id, itemtitle, avartar, fileurl}))
getTreeData() getTreeData()
setTimeout(() => { setTimeout(() => {
dialogVisible.value = false dialogVisible.value = false
@ -144,7 +148,6 @@ const getTreeData = () => {
// //
let upData = transData(evaluationList.value) let upData = transData(evaluationList.value)
if(upData.length){ if(upData.length){
treeData.value = [...upData] treeData.value = [...upData]
} }
@ -153,10 +156,22 @@ const getTreeData = () => {
return return
} }
nextTick(() => { nextTick(() => {
let defaultCurNodeId = localStorage.getItem('currentNodeId')
if(defaultCurNodeId){
defaultCurNodeId = JSON.parse(defaultCurNodeId)
const data = findNode(defaultCurNodeId)
currentNode.data = findNode(defaultCurNodeId)
currentNodeId.value = data.id
currentNodeName.value = data.label
}
else{
defaultExpandedKeys.value = [treeData.value[0].id] defaultExpandedKeys.value = [treeData.value[0].id]
currentNode.data = getLastLevelData(treeData.value)[0] currentNode.data = getLastLevelData(treeData.value)[0]
currentNodeId.value = getLastLevelData(treeData.value)[0].id currentNodeId.value = getLastLevelData(treeData.value)[0].id
currentNodeName.value = getLastLevelData(treeData.value)[0].label currentNodeName.value = getLastLevelData(treeData.value)[0].label
}
emitChangeBook() emitChangeBook()
}) })
@ -183,6 +198,9 @@ const emitChangeBook = () => {
}, },
node: curNode node: curNode
} }
localStorage.setItem('defaultExpandedKeys', JSON.stringify(defaultExpandedKeys.value))
localStorage.setItem('currentNodeId', JSON.stringify(currentNodeId.value))
emit('changeBook', data) emit('changeBook', data)
} }
@ -230,6 +248,11 @@ const findParentByChildId = (treeData, targetNodeId) => {
return null; return null;
} }
const findNode = (id) =>{
if(!id) return
return evaluationList.value.find( item => item.id == id)
}
const transData = (data) => { const transData = (data) => {
let ary = [] let ary = []
data.forEach(item => { data.forEach(item => {
@ -281,10 +304,21 @@ const getSubject = async () => {
// //
if(!subjectList.value.length) return if(!subjectList.value.length) return
let curBook = localStorage.getItem('curBook')
if(curBook){
curBook = JSON.parse(curBook)
curBookName.value = curBook.itemtitle
curBookId.value = curBook.id
curBookImg.value = BaseUrl + curBook.avartar
curBookPath.value = curBook.fileurl
}
else{
curBookName.value = subjectList.value[0].itemtitle curBookName.value = subjectList.value[0].itemtitle
curBookId.value = subjectList.value[0].id curBookId.value = subjectList.value[0].id
curBookImg.value = BaseUrl + subjectList.value[0].avartar curBookImg.value = BaseUrl + subjectList.value[0].avartar
curBookPath.value = subjectList.value[0].fileurl curBookPath.value = subjectList.value[0].fileurl
localStorage.setItem('curBookId', curBookId.value)
}
} }
@ -321,7 +355,12 @@ const handleNodeClick = (data, node) => {
node: toRaw(nodeData) node: toRaw(nodeData)
} }
currentNode.data = curData currentNode.data = curData
localStorage.setItem('defaultExpandedKeys', nodeData.parentNode ? JSON.stringify([parentNode.id]) : JSON.stringify([data.id]))
localStorage.setItem('currentNodeId', JSON.stringify(data.id))
emit('nodeClick', curData) emit('nodeClick', curData)
} }
onMounted(() => { onMounted(() => {
getSubjectContent() getSubjectContent()