Merge pull request 'lyc-dev' (#275) from lyc-dev into main
This commit is contained in:
commit
773a795707
|
@ -14,14 +14,14 @@ const defaultData = {
|
|||
isPdfWin: false, // pdf窗口是否打开
|
||||
isToolWin: false, // 工具窗口是否打开
|
||||
curSubjectNode: {
|
||||
data: {}, // 当前教材节点 (包含当前教材 单元)
|
||||
querySearch: {} // 查询资源所需参数
|
||||
},
|
||||
subject: {
|
||||
subject: { // 不走同步 Pinia
|
||||
bookList: null, // 教材列表
|
||||
curBook: null, // 当前选中的教材
|
||||
curNode: null, // 当前选中的节点
|
||||
defaultExpandedKeys: [], //展开的节点
|
||||
subjectTree: [] // "树结构" 章节
|
||||
}
|
||||
},
|
||||
local: { // 本地(永久localStorage)
|
||||
|
|
|
@ -181,6 +181,8 @@ onMounted( async () => {
|
|||
|
||||
// 章节"树"
|
||||
treeData.value = useSubject.getTreeData(curBook.data.id)
|
||||
sessionStore.set('subject.subjectTree',useSubject.getTreeData(curBook.data.id))
|
||||
|
||||
nextTick(() =>{
|
||||
// 默认展开 选中
|
||||
if(sessionStore.get('subject.curNode')){
|
||||
|
|
|
@ -6,6 +6,9 @@ import { sessionStore } from '@/utils/store'
|
|||
|
||||
// 默认数据
|
||||
const defData = sessionStore.store || {}
|
||||
const exArrs = ['subject']
|
||||
exArrs.forEach(k => Object.keys(defData).includes(k) && (delete defData[k]))
|
||||
|
||||
// 延时
|
||||
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms))
|
||||
|
||||
|
@ -16,7 +19,6 @@ export const useToolState = defineStore('tool', {
|
|||
isPdfWin: false, // pdf窗口是否打开
|
||||
isToolWin: false, // 工具窗口是否打开
|
||||
curSubjectNode: {
|
||||
data: {}, // 当前教材节点 (包含当前教材 单元)
|
||||
querySearch: {} // 查询资源所需参数
|
||||
},
|
||||
...defData // 默认数据-覆盖上面的配置(不要删除, 会导致新窗口-获取状态失败)
|
||||
|
|
|
@ -583,11 +583,7 @@ export default {
|
|||
this.uploadData.levelSecondId = cata[1]
|
||||
this.uploadData.levelThirdId = cata[2]
|
||||
this.uploadData.textbookId = data.textBook.curBookId
|
||||
toolStore.curSubjectNode.data = data
|
||||
// 不要同时修改共享数据,这样只会触发一次
|
||||
this.$nextTick(() => {
|
||||
toolStore.curSubjectNode.querySearch = this.uploadData
|
||||
})
|
||||
this.initHomeWork()
|
||||
await this.asyncAllFile()
|
||||
},
|
||||
|
|
|
@ -62,7 +62,7 @@
|
|||
<span class="unit-top-center">选择目录</span>
|
||||
</div>
|
||||
<div class="unit-content">
|
||||
<Lesson @changeChapter="changeChapter" />
|
||||
<Lesson @changeChapter="changeChapter" :curNode="curNode.data" />
|
||||
</div>
|
||||
</div>
|
||||
</transition>
|
||||
|
@ -70,19 +70,20 @@
|
|||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted, toRaw } from 'vue';
|
||||
import { ref, onMounted, toRaw, nextTick, reactive } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
import useUserStore from '@/store/modules/user'
|
||||
import { getSmarttalkPage } from '@/api/file'
|
||||
import SetHomework from '@/components/set-homework/index.vue'
|
||||
import FileImage from '@/components/file-image/index.vue'
|
||||
import { useGetHomework } from '@/hooks/useGetHomework'
|
||||
import { ipcMsgSend, ipcMsgSend2, ipcMsgInvoke } from '@/utils/tool'
|
||||
import { ipcMsgSend, ipcMsgInvoke } from '@/utils/tool'
|
||||
import { useToolState } from '@/store/modules/tool'
|
||||
import Lesson from './lesson.vue';
|
||||
import { parseCataByNode } from '@/utils/talkFile'
|
||||
import MsgEnum from '@/plugins/imChat/msgEnum' // 消息枚举
|
||||
import { createHomework } from '../createHomework'
|
||||
import { sessionStore } from '@/utils/store'
|
||||
|
||||
const route = useRoute();
|
||||
const usertore = useUserStore().user
|
||||
|
@ -99,6 +100,10 @@ const resourceList = ref([])
|
|||
//当前点击的数据
|
||||
const curRow = ref('')
|
||||
|
||||
const curNode = reactive({
|
||||
data: {}
|
||||
})
|
||||
|
||||
const sendHomework = (row) => {
|
||||
curRow.value = row
|
||||
setTimeout(() => {
|
||||
|
@ -118,6 +123,7 @@ const successHomework = (data)=>{
|
|||
}
|
||||
// 章节目录change
|
||||
const changeChapter = async (data)=>{
|
||||
curNode.data = data
|
||||
const { res } = await useGetHomework(data)
|
||||
dataList.value = res
|
||||
let cata = parseCataByNode(data)
|
||||
|
@ -177,10 +183,10 @@ const getResource = () => {
|
|||
|
||||
//获取作业数据
|
||||
const getHomework = async () => {
|
||||
const data = toRaw(toolStore.curSubjectNode).data.node
|
||||
|
||||
loading.value = true
|
||||
try {
|
||||
const { res } = await useGetHomework(data)
|
||||
const { res } = await useGetHomework(curNode.data)
|
||||
dataList.value = res
|
||||
} finally {
|
||||
loading.value = false
|
||||
|
@ -203,13 +209,16 @@ function leave(el, done) {
|
|||
done();
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
onMounted(async () => {
|
||||
await nextTick()
|
||||
entpcourseid.value = route.query.entpcourseid
|
||||
lesson.value = route.query.label
|
||||
setTimeout(()=>{
|
||||
// 当前节点 mounted 的时候从缓存里拿
|
||||
curNode.data = sessionStore.get('subject.curNode')
|
||||
getHomework()
|
||||
getResource()
|
||||
},200)
|
||||
|
||||
|
||||
})
|
||||
</script>
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
<el-scrollbar>
|
||||
<el-tree ref="refTree" :data="treeData" :props="defaultProps" node-key="id"
|
||||
:default-expanded-keys="defaultExpandedKeys" :current-node-key="currentNodeId" highlight-current
|
||||
:default-expanded-keys="defaultExpandedKeys" :current-node-key="currentNode.data.id" highlight-current
|
||||
@node-click="handleNodeClick">
|
||||
<template #default="{ node }">
|
||||
<span :title="node.label" class="tree-label">{{ node.label }}</span>
|
||||
|
@ -13,133 +13,60 @@
|
|||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted, nextTick, toRaw } from 'vue'
|
||||
import { ref, reactive, onMounted, toRaw, watch } from 'vue'
|
||||
import { useToolState } from '@/store/modules/tool'
|
||||
import { sessionStore } from '@/utils/store'
|
||||
import { cloneDeep } from 'lodash'
|
||||
|
||||
const emit = defineEmits(['changeChapter'])
|
||||
const props = defineProps(['curNode'])
|
||||
|
||||
const toolStore = useToolState()
|
||||
const treeData = ref([])
|
||||
const defaultProps = {
|
||||
children: 'children',
|
||||
label: 'label',
|
||||
label: 'itemtitle',
|
||||
class: 'textbook-tree'
|
||||
}
|
||||
// 当前选中的节点ID
|
||||
const currentNodeId = ref(0)
|
||||
// 当前选中的节点名称
|
||||
const currentNodeName = ref('')
|
||||
const currentNode = reactive({
|
||||
data: {}
|
||||
})
|
||||
|
||||
watch(() => props.curNode , (newVal) =>{
|
||||
currentNode.data = newVal
|
||||
console.log(currentNode.data)
|
||||
},
|
||||
{deep: true, immediate: true})
|
||||
|
||||
// 默认展开的节点
|
||||
const defaultExpandedKeys = ref([])
|
||||
// tree
|
||||
const refTree = ref(null)
|
||||
// 教材ID
|
||||
const curBookId = ref('')
|
||||
//
|
||||
const evaluationList = ref([])
|
||||
|
||||
const getTreeData = () => {
|
||||
evaluationList.value = JSON.parse(localStorage.getItem('unitList'))
|
||||
|
||||
//上册
|
||||
/**
|
||||
* 不区分上下册
|
||||
* 2024/08/20调整
|
||||
*/
|
||||
let volumeOne = evaluationList.value.filter(item => item.level == 1)
|
||||
|
||||
//数据过滤
|
||||
|
||||
let upData = transData(volumeOne)
|
||||
if(upData.length){
|
||||
treeData.value = [...upData]
|
||||
}
|
||||
else{
|
||||
treeData.value = []
|
||||
return
|
||||
}
|
||||
nextTick(() => {
|
||||
let defaultKey
|
||||
if(toolStore.curSubjectNode.querySearch.levelSecondId){
|
||||
defaultKey = toolStore.curSubjectNode.querySearch.levelSecondId
|
||||
}
|
||||
else{
|
||||
defaultKey = toolStore.curSubjectNode.querySearch.levelFirstId
|
||||
}
|
||||
currentNodeId.value = defaultKey
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
const handleNodeClick = (data, node) => {
|
||||
const handleNodeClick = (data) => {
|
||||
/**
|
||||
* data : 当前节点数据
|
||||
* node : 当前节点对象 包含当前节点所有数据 parent属性 指向父节点Node对象
|
||||
*/
|
||||
currentNode.data = data
|
||||
let nodeData = cloneDeep(toRaw(data));
|
||||
|
||||
const nodeData = data;
|
||||
const parentNode = node.parent.data;
|
||||
|
||||
if (Array.isArray(parentNode)) {
|
||||
nodeData.parentNode = null
|
||||
//增加一个label 之前取的label
|
||||
nodeData.label = nodeData.itemtitle
|
||||
// 父级节点 如果当前是一级节点 父级则为null
|
||||
let parent = {
|
||||
id: nodeData.parentid,
|
||||
label: nodeData.parenttitle,
|
||||
itemtitle: nodeData.parenttitle
|
||||
}
|
||||
else {
|
||||
const parentNode = nodeData.parentid ? parent : null
|
||||
nodeData.parentNode = parentNode
|
||||
}
|
||||
|
||||
emit('changeChapter', toRaw(nodeData))
|
||||
emit('changeChapter', nodeData)
|
||||
}
|
||||
|
||||
|
||||
// 根据教材章节单元ID 查询作业列表所需ID
|
||||
const getChapterId = () => {
|
||||
return listEntpcourse({
|
||||
evalid: this.uploadData.levelSecondId,
|
||||
edituserid: this.userStore.userId,
|
||||
pageSize: 500
|
||||
})
|
||||
}
|
||||
|
||||
const transData = (data) => {
|
||||
let ary = []
|
||||
data.forEach(item => {
|
||||
let obj = {}
|
||||
if (item.rootid == curBookId.value) {
|
||||
obj.label = item.itemtitle
|
||||
obj.id = item.id
|
||||
obj.itemtitle = item.itemtitle
|
||||
obj.edudegree = item.edudegree
|
||||
obj.edustage = item.edustage
|
||||
obj.edusubject = item.edusubject
|
||||
let ary2 = []
|
||||
evaluationList.value.forEach(el => {
|
||||
let obj2 = {}
|
||||
if (item.id == el.parentid) {
|
||||
obj2 = {
|
||||
label: el.itemtitle,
|
||||
id: el.id,
|
||||
itemtitle : el.itemtitle,
|
||||
edudegree : el.edudegree,
|
||||
edustage : el.edustage,
|
||||
edusubject : el.edusubject,
|
||||
}
|
||||
ary2.push(obj2)
|
||||
}
|
||||
obj.children = ary2
|
||||
})
|
||||
ary.push(obj)
|
||||
}
|
||||
})
|
||||
return ary
|
||||
}
|
||||
|
||||
|
||||
onMounted(()=>{
|
||||
setTimeout(()=>{
|
||||
let data = toRaw(toolStore.curSubjectNode)
|
||||
curBookId.value = data.data.textBook.curBookId
|
||||
getTreeData()
|
||||
},500)
|
||||
|
||||
treeData.value = sessionStore.get('subject.subjectTree')
|
||||
defaultExpandedKeys.value = sessionStore.get('subject.defaultExpandedKeys')
|
||||
})
|
||||
</script>
|
||||
|
||||
|
|
Loading…
Reference in New Issue