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

This commit is contained in:
lyc 2024-09-25 11:25:30 +08:00
commit 38d3e6a906
5 changed files with 92 additions and 202 deletions

View File

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

View File

@ -1,5 +1,5 @@
<template> <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"> style="border-radius: 5px;padding-top: 0">
<div class="dialog-title flex"> <div class="dialog-title flex">
<span>{{ title }}</span> <span>{{ title }}</span>
@ -7,13 +7,13 @@
</div> </div>
<div class="dialog-content"> <div class="dialog-content">
<div class="book-name flex" @click="bookVisible = true"> <div class="book-name flex" @click="bookVisible = true">
<span>{{ curBookName }}</span> <span>{{ curNode.data.itemtitle }}</span>
<i class="iconfont icon-yidongdaozu"></i> <i class="iconfont icon-yidongdaozu"></i>
</div> </div>
<el-scrollbar height="400px"> <el-scrollbar height="400px">
<div class="book-data"> <div class="book-data">
<el-tree ref="refTree" :data="treeData" :props="defaultProps" node-key="id" <el-tree :data="treeData" :props="defaultProps" node-key="id"
:default-expanded-keys="defaultExpandedKeys" :current-node-key="currentNodeId" highlight-current :default-expanded-keys="defaultExpandedKeys" :current-node-key="curNode.data.id" highlight-current
@node-click="handleNodeClick"> @node-click="handleNodeClick">
<template #default="{ node }"> <template #default="{ node }">
<span :title="node.label" class="tree-label">{{ node.label }}</span> <span :title="node.label" class="tree-label">{{ node.label }}</span>
@ -24,7 +24,7 @@
</div> </div>
<template #footer> <template #footer>
<div class="dialog-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 type="primary" @click="onSubmit">
确定 确定
</el-button> </el-button>
@ -43,9 +43,12 @@
<div class="textbook-container"> <div class="textbook-container">
<el-scrollbar height="450px"> <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)"> :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> <span class="book-name">{{ item.itemtitle }}</span>
</div> </div>
</el-scrollbar> </el-scrollbar>
@ -54,9 +57,10 @@
</template> </template>
<script setup> <script setup>
import { ref, reactive, toRaw, onMounted, nextTick, watch } from 'vue' import { ref, reactive, toRaw, onMounted, nextTick } from 'vue'
import useUserStore from '@/store/modules/user' import { sessionStore } from '@/utils/store'
import { listEvaluation } from '@/api/subject' import { useGetSubject } from '@/hooks/useGetSubject'
import { cloneDeep } from 'lodash'
const props = defineProps({ const props = defineProps({
modelValue: { modelValue: {
@ -68,134 +72,35 @@ const props = defineProps({
default: '移动至' default: '移动至'
} }
}) })
const userStore = useUserStore() const model = defineModel({ type: Boolean, default: false })
const { edustage, edusubject, userId } = userStore.user const BaseUrl = import.meta.env.VITE_APP_BUILD_BASE_PATH
let useSubject = null
const dialogVisible = ref(false)
const bookVisible = ref(false) const bookVisible = ref(false)
// //
const subjectList = ref([]) const subjectList = ref([])
const evaluationList = ref([])
const treeData = ref([]) const treeData = ref([])
const defaultProps = { const defaultProps = {
children: 'children', children: 'children',
label: 'label', label: 'itemtitle',
class: 'textbook-tree' class: 'textbook-tree'
} }
//ID //
const curBookId = ref(-1) const curBook = reactive({
//
const curBookName = ref('')
//
const volumeOne = ref([])
//
const currentNode = reactive({
data: {} data: {}
}) })
// ID //
const currentNodeId = ref(0) const curNode = reactive({
// data:{}
const currentNodeName = ref('') })
//
let submitNode = null
// //
const defaultExpandedKeys = ref([]) const defaultExpandedKeys = ref([])
// tree
const refTree = ref(null)
// emit // emit
const emit = defineEmits(['update:modelValue', 'onSubmit']) const emit = defineEmits(['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
}
// id // id
const findParentByChildId = (treeData, targetNodeId) => { const findParentByChildId = (treeData, targetNodeId) => {
@ -219,70 +124,32 @@ const findParentByChildId = (treeData, targetNodeId) => {
return null; return null;
} }
const handleNodeClick = (data, node) => { const handleNodeClick = (data) => {
/** /**
* data : 当前节点数据 * data : 当前节点数据
* node : 当前节点对象 包含当前节点所有数据 parent属性 指向父节点Node对象
*/ */
const nodeData = data; let nodeData = cloneDeep(toRaw(data));
const parentNode = node.parent.data; //label label
nodeData.label = nodeData.itemtitle
if (Array.isArray(parentNode)) { // null
nodeData.parentNode = null let parent = {
id: nodeData.parentid,
label: nodeData.parenttitle,
itemtitle: nodeData.parenttitle
} }
else { const parentNode = nodeData.parentid ? parent : null
nodeData.parentNode = parentNode nodeData.parentNode = parentNode
}
let curData = { let curData = {
textBook: { textBook: {
curBookId: curBookId.value, curBookId: curBook.data.id,
curBookName: curBookName.value 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) => { const getLastLevelData = (tree) => {
let lastLevelData = []; let lastLevelData = [];
@ -307,33 +174,53 @@ const getLastLevelData = (tree) => {
} }
// //
const changeBook = ({ id, itemtitle }) => { const changeBook = (data) => {
curBookId.value = id curBook.data = data
curBookName.value = itemtitle treeData.value = useSubject.getTreeData(data.id)
getTreeData()
//
nextTick(() =>{
defaultExpandedKeys.value = [treeData.value[0].id]
curNode.data = getLastLevelData(treeData.value)[0]
handleNodeClick(curNode.data)
})
setTimeout(() => { setTimeout(() => {
bookVisible.value = false bookVisible.value = false
}, 0); }, 0);
} }
const onSubmit = () => { const onSubmit = () => {
emit('onSubmit', toRaw(currentNode.data)) emit('onSubmit', submitNode)
closeDialog() model.value = false
} }
const closeDialog = () => { onMounted(async () => {
emit('update:modelValue', false) //
} 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) => { treeData.value = useSubject.getTreeData(curBook.data.id)
emit('update:modelValue', false) nextTick(() =>{
done() //
} 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> </script>

View File

@ -63,7 +63,6 @@ export const useGetSubject = async () =>{
} }
sessionStore.set('subject.curNode', curNode) sessionStore.set('subject.curNode', curNode)
} }
} }
// 单元章节数据转为“树”结构 // 单元章节数据转为“树”结构
@ -73,9 +72,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
} }
await getSubjectUnit() await getSubjectUnit()

View File

@ -175,7 +175,13 @@ function setLayout() {
} }
// //
const changeSubject = async (command) =>{ 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 { userId, userName, phonenumber, plainpwd } = userStore.user
const data = { const data = {
userId, userId,

View File

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