Compare commits

..

4 Commits

Author SHA1 Message Date
qinqing e7a36ddfba Merge branch 'main' into qinqing_dev 2024-09-25 13:46:13 +08:00
lyc 38d3e6a906 Merge pull request 'lyc-dev' (#267) from lyc-dev into main 2024-09-25 11:25:30 +08:00
lyc a24da0f6a6 Merge branch 'main' into lyc-dev 2024-09-25 11:24:38 +08:00
lyc bb486e2bd2 教材切换 edit 2024-09-25 11:24:23 +08:00
5 changed files with 92 additions and 202 deletions

View File

@ -77,12 +77,11 @@ const changeBook = (data) => {
curBook.data = data
sessionStore.set('subject.curBook', data)
treeData.value = useSubject.getTreeData(data.id)
sessionStore.set('subject.subjectTree', useSubject.getTreeData(data.id))
//
nextTick(() =>{
defaultExpandedKeys.value = [treeData.value[0].id]
curNode.data = getLastLevelData(treeData.value)[0]
handleNodeClick(curNode.data)
})
//

View File

@ -1,5 +1,5 @@
<template>
<el-dialog v-model="dialogVisible" append-to-body :show-close="false" width="630" :before-close="beforeClose"
<el-dialog v-model="model" append-to-body :show-close="false" width="630"
style="border-radius: 5px;padding-top: 0">
<div class="dialog-title flex">
<span>{{ title }}</span>
@ -7,13 +7,13 @@
</div>
<div class="dialog-content">
<div class="book-name flex" @click="bookVisible = true">
<span>{{ curBookName }}</span>
<span>{{ curNode.data.itemtitle }}</span>
<i class="iconfont icon-yidongdaozu"></i>
</div>
<el-scrollbar height="400px">
<div class="book-data">
<el-tree ref="refTree" :data="treeData" :props="defaultProps" node-key="id"
:default-expanded-keys="defaultExpandedKeys" :current-node-key="currentNodeId" highlight-current
<el-tree :data="treeData" :props="defaultProps" node-key="id"
:default-expanded-keys="defaultExpandedKeys" :current-node-key="curNode.data.id" highlight-current
@node-click="handleNodeClick">
<template #default="{ node }">
<span :title="node.label" class="tree-label">{{ node.label }}</span>
@ -24,7 +24,7 @@
</div>
<template #footer>
<div class="dialog-footer">
<el-button @click="closeDialog">取消</el-button>
<el-button @click="model = false">取消</el-button>
<el-button type="primary" @click="onSubmit">
确定
</el-button>
@ -43,9 +43,12 @@
<div class="textbook-container">
<el-scrollbar height="450px">
<div class="textbook-item flex" v-for="item in subjectList" :class="curBookId == item.id ? 'active-item' : ''"
<div class="textbook-item flex" v-for="item in subjectList" :class="curBook.data.id == item.id ? 'active-item' : ''"
:key="item.id" @click="changeBook(item)">
<img :src="item.avartar" class="textbook-img" alt="">
<img v-if="item.avartar" :src="item.avartar.indexOf('http') === 0 ? item.avartar : BaseUrl + item.avartar" class="textbook-img" alt="">
<div v-else class="textbook-img">
<i class="iconfont icon-jiaocaixuanze" style="font-size: 40px;"></i>
</div>
<span class="book-name">{{ item.itemtitle }}</span>
</div>
</el-scrollbar>
@ -54,9 +57,10 @@
</template>
<script setup>
import { ref, reactive, toRaw, onMounted, nextTick, watch } from 'vue'
import useUserStore from '@/store/modules/user'
import { listEvaluation } from '@/api/subject'
import { ref, reactive, toRaw, onMounted, nextTick } from 'vue'
import { sessionStore } from '@/utils/store'
import { useGetSubject } from '@/hooks/useGetSubject'
import { cloneDeep } from 'lodash'
const props = defineProps({
modelValue: {
@ -68,134 +72,35 @@ const props = defineProps({
default: '移动至'
}
})
const userStore = useUserStore()
const { edustage, edusubject, userId } = userStore.user
const model = defineModel({ type: Boolean, default: false })
const BaseUrl = import.meta.env.VITE_APP_BUILD_BASE_PATH
let useSubject = null
const dialogVisible = ref(false)
const bookVisible = ref(false)
//
const subjectList = ref([])
const evaluationList = ref([])
const treeData = ref([])
const defaultProps = {
children: 'children',
label: 'label',
label: 'itemtitle',
class: 'textbook-tree'
}
//ID
const curBookId = ref(-1)
//
const curBookName = ref('')
//
const volumeOne = ref([])
//
const currentNode = reactive({
//
const curBook = reactive({
data: {}
})
// ID
const currentNodeId = ref(0)
//
const currentNodeName = ref('')
//
const curNode = reactive({
data:{}
})
//
let submitNode = null
//
const defaultExpandedKeys = ref([])
// tree
const refTree = ref(null)
// emit
const emit = defineEmits(['update:modelValue', 'onSubmit'])
watch(() => props.modelValue, (newVal) => {
dialogVisible.value = newVal
})
const getSubjectContent = async () => {
const params = {
edusubject,
edustage,
// entpcourseedituserid: userId,
itemgroup: 'textbook',
orderby: 'orderidx asc',
pageSize: 10000
}
let data;
const { rows } = await listEvaluation(params)
localStorage.setItem('evaluationList', JSON.stringify(rows))
evaluationList.value = rows
data = rows
//
getSubject()
//
/**
* 不区分上下册
* 2024/08/20调整
*/
// volumeOne.value = data.filter(item => item.level == 1)
getTreeData()
}
const getSubject = async () => {
if (localStorage.getItem('subjectList')) {
subjectList.value = JSON.parse(localStorage.getItem('subjectList'))
}
else {
const { rows } = await listEvaluation({ itemkey: "version", edusubject, edustage, pageSize: 10000, orderby: 'orderidx asc', })
subjectList.value = rows
localStorage.setItem('subjectList', JSON.stringify(subjectList.value))
}
//
if(!subjectList.value.length) return
curBookName.value = subjectList.value[0].itemtitle
curBookId.value = subjectList.value[0].id
}
const isHaveUnit = (id) => {
return evaluationList.value.some(item => {
return item.rootid == id
})
}
const getTreeData = () => {
//
let upData = transData(evaluationList.value)
if(upData.length){
treeData.value = [...upData]
}
else{
treeData.value = []
return
}
nextTick(() => {
defaultExpandedKeys.value = [treeData.value[0].id]
currentNodeId.value = getLastLevelData(treeData.value)[0].id
currentNodeName.value = getLastLevelData(treeData.value)[0].label
emitChangeBook()
})
}
const emitChangeBook = () => {
let curNode = {
id: currentNodeId.value,
label: currentNodeName.value
}
let parentNode = findParentByChildId(treeData.value, currentNodeId.value)
curNode.parentNode = toRaw(parentNode)
const data = {
textBook: {
curBookId: curBookId.value,
curBookName: curBookName.value
},
node: curNode
}
currentNode.data = data
}
const emit = defineEmits(['onSubmit'])
// id
const findParentByChildId = (treeData, targetNodeId) => {
@ -219,70 +124,32 @@ const findParentByChildId = (treeData, targetNodeId) => {
return null;
}
const handleNodeClick = (data, node) => {
const handleNodeClick = (data) => {
/**
* data : 当前节点数据
* node : 当前节点对象 包含当前节点所有数据 parent属性 指向父节点Node对象
*/
const nodeData = data;
const parentNode = node.parent.data;
if (Array.isArray(parentNode)) {
nodeData.parentNode = null
let nodeData = cloneDeep(toRaw(data));
//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
}
let curData = {
textBook: {
curBookId: curBookId.value,
curBookName: curBookName.value
curBookId: curBook.data.id,
curBookName: curBook.data.itemtitle
},
node: toRaw(nodeData)
node: nodeData
}
submitNode = curData
}
currentNode.data = curData
// emit('nodeClick', curData)
}
const transData = (data) => {
let ary = []
data.forEach(item => {
let obj = {}
// ID
if (item.rootid == curBookId.value) {
if(item.level == 1){
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
}
//
const getLastLevelData = (tree) => {
let lastLevelData = [];
@ -307,33 +174,53 @@ const getLastLevelData = (tree) => {
}
//
const changeBook = ({ id, itemtitle }) => {
curBookId.value = id
curBookName.value = itemtitle
getTreeData()
const changeBook = (data) => {
curBook.data = data
treeData.value = useSubject.getTreeData(data.id)
//
nextTick(() =>{
defaultExpandedKeys.value = [treeData.value[0].id]
curNode.data = getLastLevelData(treeData.value)[0]
handleNodeClick(curNode.data)
})
setTimeout(() => {
bookVisible.value = false
}, 0);
}
const onSubmit = () => {
emit('onSubmit', toRaw(currentNode.data))
closeDialog()
emit('onSubmit', submitNode)
model.value = false
}
const closeDialog = () => {
emit('update:modelValue', false)
onMounted(async () => {
//
useSubject = await useGetSubject()
subjectList.value = sessionStore.get('subject.bookList')
//
if(sessionStore.get('subject.curBook')){
curBook.data = sessionStore.get('subject.curBook')
}
else{
curBook.data = subjectList.value[0]
}
//
const beforeClose = (done) => {
emit('update:modelValue', false)
done()
// ""
treeData.value = useSubject.getTreeData(curBook.data.id)
nextTick(() =>{
//
if(sessionStore.get('subject.curNode')){
defaultExpandedKeys.value = sessionStore.get('subject.defaultExpandedKeys')
curNode.data = sessionStore.get('subject.curNode')
}else{
defaultExpandedKeys.value = [treeData.value[0].id]
curNode.data = getLastLevelData(treeData.value)[0]
}
handleNodeClick(curNode.data)
})
onMounted(() => {
getSubjectContent()
})
</script>

View File

@ -63,7 +63,6 @@ export const useGetSubject = async () =>{
}
sessionStore.set('subject.curNode', curNode)
}
}
// 单元章节数据转为“树”结构
@ -73,9 +72,7 @@ export const useGetSubject = async () =>{
data.forEach( item => {
item.children = unitList.value.filter( item2 => item2.parentid == item.id && item2.level == 2)
})
sessionStore.set('subject.subjectTree', data)
return data
}
await getSubjectUnit()

View File

@ -175,7 +175,13 @@ function setLayout() {
}
//
const changeSubject = async (command) =>{
clearBookInfo()
let sessionSubject = {
bookList: null,
curBook: null,
curNode: null,
defaultExpandedKeys: [],
}
sessionStore.set( 'subject', sessionSubject)
const { userId, userName, phonenumber, plainpwd } = userStore.user
const data = {
userId,

View File

@ -512,6 +512,7 @@ export default {
})
this.currentFileList.splice(index, 1)
})
ElMessage.success('操作成功')
}
})
},