Merge pull request 'lyc-dev' (#275) from lyc-dev into main

This commit is contained in:
lyc 2024-09-26 16:39:19 +08:00
commit 773a795707
6 changed files with 61 additions and 125 deletions

View File

@ -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)

View File

@ -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')){

View File

@ -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 // 默认数据-覆盖上面的配置(不要删除, 会导致新窗口-获取状态失败)

View File

@ -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
})
toolStore.curSubjectNode.querySearch = this.uploadData
this.initHomeWork()
await this.asyncAllFile()
},

View File

@ -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(()=>{
getHomework()
getResource()
},200)
// mounted
curNode.data = sessionStore.get('subject.curNode')
getHomework()
getResource()
})
</script>

View File

@ -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;
//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
if (Array.isArray(parentNode)) {
nodeData.parentNode = null
}
else {
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>