章节切换 edit

This commit is contained in:
lyc 2024-09-24 17:36:43 +08:00
parent 09159ae2d8
commit 9329da9ddf
6 changed files with 71 additions and 130 deletions

View File

@ -16,6 +16,12 @@ const defaultData = {
curSubjectNode: { curSubjectNode: {
data: {}, // 当前教材节点 (包含当前教材 单元) data: {}, // 当前教材节点 (包含当前教材 单元)
querySearch: {} // 查询资源所需参数 querySearch: {} // 查询资源所需参数
},
subject: {
bookList: null, // 教材列表
curBook: null, // 当前选中的教材
curNode: null, // 当前选中的节点
defaultExpandedKeys: [], //展开的节点
} }
}, },
local: { // 本地(永久localStorage) local: { // 本地(永久localStorage)

View File

@ -44,11 +44,12 @@
<script setup> <script setup>
import { onMounted, ref, nextTick, toRaw, reactive } from 'vue'; import { onMounted, ref, nextTick, toRaw, reactive } from 'vue';
import { cloneDeep } from 'lodash' import { cloneDeep } from 'lodash'
import { sessionStore } from '@/utils/store'
import { useGetSubject } from '@/hooks/useGetSubject' import { useGetSubject } from '@/hooks/useGetSubject'
const BaseUrl = import.meta.env.VITE_APP_BUILD_BASE_PATH const BaseUrl = import.meta.env.VITE_APP_BUILD_BASE_PATH
// emit // emit
const emit = defineEmits(['nodeClick', 'changeBook']) const emit = defineEmits(['nodeClick'])
let useSubject = null let useSubject = null
const subjectList = ref([]) const subjectList = ref([])
const dialogVisible = ref(false) const dialogVisible = ref(false)
@ -74,8 +75,7 @@ const defaultExpandedKeys = ref([])
// //
const changeBook = (data) => { const changeBook = (data) => {
curBook.data = data curBook.data = data
sessionStore.set('subject.curBook', data)
localStorage.setItem('curBook', JSON.stringify(data))
treeData.value = useSubject.getTreeData(data.id) treeData.value = useSubject.getTreeData(data.id)
// //
@ -83,9 +83,7 @@ const changeBook = (data) => {
defaultExpandedKeys.value = [treeData.value[0].id] defaultExpandedKeys.value = [treeData.value[0].id]
curNode.data = getLastLevelData(treeData.value)[0] curNode.data = getLastLevelData(treeData.value)[0]
localStorage.setItem('defaultExpandedKeys', JSON.stringify(defaultExpandedKeys.value)) handleNodeClick(curNode.data)
localStorage.setItem('curNode',JSON.stringify(curNode.data))
emitChangeBook()
}) })
// //
setTimeout(() => { setTimeout(() => {
@ -93,40 +91,6 @@ const changeBook = (data) => {
}, 100); }, 100);
} }
const emitChangeBook = async () => {
let curData = cloneDeep(toRaw(curNode.data))
let parentNode = findParentByChildId(treeData.value, curData.id)
curData.parentNode = toRaw(parentNode)
//label label
curData.label = curData.itemtitle
const data = {
textBook: {
curBookId: curBook.data.id,
curBookName: curBook.data.itemtitle,
curBookImg: BaseUrl + curBook.data.avartar,
curBookPath: curBook.data.fileurl
},
node: curData
}
/**
* 临时用 后续删除 unitId
*/
let levelFirstId = null
let levelSecondId = null
let bookeId = curBook.data.id
if (curData.parentNode) {
levelFirstId = curData.parentNode.id
levelSecondId = curData.id
} else {
levelFirstId = curData.id
levelSecondId = ''
}
localStorage.setItem('unitId', JSON.stringify({ levelFirstId, levelSecondId, bookeId}))
emit('changeBook', data)
}
const getLastLevelData = (tree) => { const getLastLevelData = (tree) => {
let lastLevelData = []; let lastLevelData = [];
// //
@ -171,25 +135,22 @@ const findParentByChildId = (treeData, targetNodeId) => {
} }
const handleNodeClick = (data, node) => { const handleNodeClick = (data) => {
/** /**
* data : 当前节点数据 * data : 当前节点数据
* node : 当前节点对象 包含当前节点所有数据 parent属性 指向父节点Node对象
*/ */
let nodeData = cloneDeep(toRaw(data)); let nodeData = cloneDeep(toRaw(data));
//label label
nodeData.label = nodeData.itemtitle
const parentNode = node.parent.data;
// parentNode
if (Array.isArray(parentNode)) {
//
nodeData.parentNode = null
}
else {
// parentNode
nodeData.parentNode = toRaw(parentNode)
}
//label label
nodeData.label = nodeData.itemtitle
// null
let parent = {
id: nodeData.parentid,
label: nodeData.parenttitle,
itemtitle: nodeData.parenttitle
}
const parentNode = nodeData.parentid ? parent : null
nodeData.parentNode = parentNode
let curData = { let curData = {
textBook: { textBook: {
curBookId: curBook.data.id, curBookId: curBook.data.id,
@ -197,63 +158,40 @@ const handleNodeClick = (data, node) => {
curBookImg: BaseUrl + curBook.data.avartar, curBookImg: BaseUrl + curBook.data.avartar,
curBookPath: curBook.data.fileurl curBookPath: curBook.data.fileurl
}, },
node: toRaw(nodeData) node: nodeData
} }
localStorage.setItem('defaultExpandedKeys', parentNode ? JSON.stringify([parentNode.id]) : JSON.stringify([data.id])) // :electron-store
localStorage.setItem('curNode', JSON.stringify(nodeData)) let defaultExpandedKeys = parentNode ? [parentNode.id] : [nodeData.id]
sessionStore.set('subject.defaultExpandedKeys', defaultExpandedKeys)
/** sessionStore.set('subject.curNode', nodeData)
* 临时用 后续删除 unitId
*/
let levelFirstId = null
let levelSecondId = null
let bookeId = curBook.data.id
if (nodeData.parentNode) {
levelFirstId = nodeData.parentNode.id
levelSecondId = nodeData.id
} else {
levelFirstId = nodeData.id
levelSecondId = ''
}
localStorage.setItem('unitId', JSON.stringify({ levelFirstId, levelSecondId, bookeId}))
emit('nodeClick', curData) emit('nodeClick', curData)
} }
onMounted( async () => { onMounted( async () => {
treeLoading.value = true treeLoading.value = true
try{ try{
useSubject = await useGetSubject() useSubject = await useGetSubject()
subjectList.value = useSubject.subjectList subjectList.value = sessionStore.get('subject.bookList')
//
if(sessionStore.get('subject.curBook')){
curBook.data = sessionStore.get('subject.curBook')
}
else{
curBook.data = subjectList.value[0]
}
let book = localStorage.getItem('curBook') // ""
if(book){ treeData.value = useSubject.getTreeData(curBook.data.id)
book = JSON.parse(book)
curBook.data = book
treeData.value = useSubject.getTreeData(book.id)
}
else{
curBook.data = useSubject.subjectList[0]
localStorage.setItem('curBook', JSON.stringify(curBook.data))
treeData.value = useSubject.treeData
}
//
nextTick(() =>{ nextTick(() =>{
// //
let node = localStorage.getItem('curNode') if(sessionStore.get('subject.curNode')){
if(node){ defaultExpandedKeys.value = sessionStore.get('subject.defaultExpandedKeys')
curNode.data = JSON.parse(node) curNode.data = sessionStore.get('subject.curNode')
defaultExpandedKeys.value = JSON.parse(localStorage.getItem('defaultExpandedKeys')) }else{
}
else{
defaultExpandedKeys.value = [treeData.value[0].id] defaultExpandedKeys.value = [treeData.value[0].id]
curNode.data = getLastLevelData(treeData.value)[0] curNode.data = getLastLevelData(treeData.value)[0]
//
localStorage.setItem('defaultExpandedKeys', JSON.stringify(defaultExpandedKeys.value))
localStorage.setItem('curNode', JSON.stringify(curNode.data))
} }
emitChangeBook() handleNodeClick(curNode.data)
}) })
} finally{ } finally{

View File

@ -1,13 +1,13 @@
import { ref } from 'vue' import { ref } from 'vue'
import useUserStore from '@/store/modules/user' import useUserStore from '@/store/modules/user'
import { listEvaluation } from '@/api/subject' import { listEvaluation } from '@/api/subject'
import { sessionStore } from '@/utils/store'
export const useGetSubject = async () =>{ export const useGetSubject = async () =>{
// user store // user store
const userStore = useUserStore() const userStore = useUserStore()
const { edustage, edusubject, userId } = userStore.user const { edustage, edusubject, userId } = userStore.user
const BaseUrl = import.meta.env.VITE_APP_BUILD_BASE_PATH
// 章节List // 章节List
const unitList = ref([]) const unitList = ref([])
// 教材List // 教材List
@ -16,11 +16,10 @@ export const useGetSubject = async () =>{
let treeData = null let treeData = null
// 根据 学科 + 学段 获取所有单元章节 // 根据学科 + 学段 获取所有单元章节
const getSubjectUnit = async () =>{ const getSubjectUnit = async () =>{
let strUnit = localStorage.getItem('unitList') if(sessionStore.get('subject.unitList')){
if(strUnit){ unitList.value = sessionStore.get('subject.unitList')
unitList.value = JSON.parse(strUnit)
} }
else{ else{
const unitParams = { const unitParams = {
@ -32,18 +31,17 @@ export const useGetSubject = async () =>{
} }
const { rows } = await listEvaluation(unitParams) const { rows } = await listEvaluation(unitParams)
unitList.value = rows unitList.value = rows
localStorage.setItem('unitList', JSON.stringify(rows)) sessionStore.set('subject.unitList', rows)
} }
await getSubject() await getSubject()
} }
// 获取 学科 + 学段 获取教材 // 根据学科 + 学段 获取教材
const getSubject = async () =>{ const getSubject = async () =>{
let strSubject = localStorage.getItem('subjectList') if(sessionStore.get('subject.bookList')){
if(strSubject){ subjectList = sessionStore.get('subject.bookList')
subjectList = JSON.parse(strSubject)
} }
else{ else{
const subjectParams = { const subjectParams = {
@ -55,13 +53,20 @@ export const useGetSubject = async () =>{
} }
const { rows } = await listEvaluation(subjectParams) const { rows } = await listEvaluation(subjectParams)
subjectList = rows subjectList = rows
localStorage.setItem('subjectList', JSON.stringify(rows)) sessionStore.set('subject.bookList', rows)
treeData = getTreeData(subjectList[0].id)
// 设置一个默认的curNode
let curNode
if(treeData[0].children){
curNode = treeData[0].children[0]
}
else{
curNode = treeData[0]
}
sessionStore.set('subject.curNode', curNode)
console.log(curNode,treeData)
} }
// 默认选中第一个教材
if(subjectList && subjectList.length){
treeData = getTreeData(subjectList[0].id)
}
} }
// 单元章节数据转为“树”结构 // 单元章节数据转为“树”结构
@ -71,6 +76,7 @@ export const useGetSubject = async () =>{
data.forEach( item => { data.forEach( item => {
item.children = unitList.value.filter( item2 => item2.parentid == item.id && item2.level == 2) item.children = unitList.value.filter( item2 => item2.parentid == item.id && item2.level == 2)
}) })
sessionStore.set('subject.subjectTree', data)
return data return data
} }

View File

@ -45,7 +45,8 @@ import { useRouter } from 'vue-router'
import workTrend from './container/work-trend.vue' import workTrend from './container/work-trend.vue'
import outLink from '@/utils/linkConfig' import outLink from '@/utils/linkConfig'
import * as echarts from 'echarts' import * as echarts from 'echarts'
import { useGetClassWork } from '@/hooks/useGetClassWork' import { useGetSubject } from '@/hooks/useGetSubject'
import { sessionStore } from '@/utils/store'
const router = useRouter() const router = useRouter()
const { ipcRenderer } = window.electron || {} const { ipcRenderer } = window.electron || {}
@ -169,13 +170,12 @@ const clickMenu = ({isOuter, path, disabled, id}) =>{
let fullPath = configObj.fullPath + path let fullPath = configObj.fullPath + path
if(id == '1-2' || id == '2-1' || id == '2-2' ){ if(id == '1-2' || id == '2-1' || id == '2-2' ){
// ID // ID
const { levelFirstId, levelSecondId, bookeId } = JSON.parse(localStorage.getItem('unitId')) const { id, rootid } = sessionStore.get('subject.curNode')
let unitId = levelSecondId ? levelSecondId : levelFirstId
if(fullPath.indexOf('?') == -1){ if(fullPath.indexOf('?') == -1){
fullPath += `?unitId=${unitId}&bookeId=${bookeId}` fullPath += `?unitId=${id}&bookeId=${rootid}`
} }
else{ else{
fullPath += `&unitId=${unitId}&bookeId=${bookeId}` fullPath += `&unitId=${id}&bookeId=${id}`
} }
} }
fullPath = fullPath.replaceAll('//', '/') fullPath = fullPath.replaceAll('//', '/')
@ -191,6 +191,8 @@ const clickMenu = ({isOuter, path, disabled, id}) =>{
} }
onMounted(async ()=>{ onMounted(async ()=>{
await useGetSubject()
// DOM // DOM
await nextTick() await nextTick()
chartInstance = echarts.init(chartDom.value) chartInstance = echarts.init(chartDom.value)
@ -236,21 +238,10 @@ onMounted(async ()=>{
] ]
} }
chartInstance.setOption(option); chartInstance.setOption(option);
// +
getSubjectInit();
}) })
const getSubjectInit = async () => {
//
let unitId = localStorage.getItem('unitId')
if(unitId){
//
} else{
// +
useGetClassWork();
}
}
</script> </script>

View File

@ -1,6 +1,6 @@
<template> <template>
<div v-loading="isLoading" class="page-resource flex"> <div v-loading="isLoading" class="page-resource flex">
<ChooseTextbook @change-book="nodeClick" @node-click="nodeClick" /> <ChooseTextbook @node-click="nodeClick" />
<div class="page-center-wrap"> <div class="page-center-wrap">
<el-tabs v-model="activeAptTab" style="height: 100%;"> <el-tabs v-model="activeAptTab" style="height: 100%;">
<el-tab-pane label="教学课件" name="教学课件" class="prepare-center-jxkj"> <el-tab-pane label="教学课件" name="教学课件" class="prepare-center-jxkj">

View File

@ -2,7 +2,7 @@
<div class="page-resource flex"> <div class="page-resource flex">
<!--左侧 教材 目录--> <!--左侧 教材 目录-->
<Third v-if="isThird" @node-click="getDataOther"></Third> <Third v-if="isThird" @node-click="getDataOther"></Third>
<ChooseTextbook v-else @change-book="getData" @node-click="getData" /> <ChooseTextbook v-else @node-click="getData" />
<div class="page-right"> <div class="page-right">
<!-- 搜索 --> <!-- 搜索 -->