教材change #20

Merged
lyc merged 1 commits from lyc-dev into main 2024-07-15 15:22:49 +08:00
3 changed files with 126 additions and 45 deletions
Showing only changes of commit 0cac6ef996 - Show all commits

View File

@ -1,18 +1,22 @@
<template> <template>
<div class="book-wrap"> <div class="book-wrap">
<el-scrollbar height="100%">
<div class="book-name flex" @click="dialogVisible = true"> <div class="book-name flex" @click="dialogVisible = true">
<span>{{ curBookName }}</span> <span>{{ curBookName }}</span>
<i class="iconfont icon-xiangyou"></i> <i class="iconfont icon-xiangyou"></i>
</div> </div>
<div class="book-list"> <div class="book-list">
<el-tree ref="treeref" :data="treeData" :props="defaultProps" node-key="id"
:default-expanded-keys="defaultExpandedKeys" <el-tree ref="refTree" :data="treeData" :props="defaultProps" node-key="id"
:current-node-key="currentNode" highlight-current @node-click="handleNodeClick"> :default-expanded-keys="defaultExpandedKeys" :current-node-key="currentNode" highlight-current
@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>
</template> </template>
</el-tree> </el-tree>
</div> </div>
</el-scrollbar>
</div> </div>
<!--弹窗 选择教材--> <!--弹窗 选择教材-->
<el-dialog v-model="dialogVisible" append-to-body :show-close="false" width="550" <el-dialog v-model="dialogVisible" append-to-body :show-close="false" width="550"
@ -37,12 +41,12 @@
</template> </template>
<script setup> <script setup>
import { onMounted, ref, nextTick } from 'vue'; import { onMounted, ref, nextTick, toRaw } from 'vue';
import useUserStore from '@/store/modules/user' import useUserStore from '@/store/modules/user'
import { listEvaluation } from '@/api/subject' import { listEvaluation } from '@/api/subject'
// emit // emit
const emit = defineEmits(['nodeClick']) const emit = defineEmits(['nodeClick', 'changeBook'])
// store // store
const userStore = useUserStore() const userStore = useUserStore()
const { edustage, edusubject, userId } = userStore.user const { edustage, edusubject, userId } = userStore.user
@ -65,12 +69,14 @@ const curBookName = ref('')
const volumeOne = ref([]) const volumeOne = ref([])
// //
const volumeTwo = ref([]) const volumeTwo = ref([])
// // ID
const currentNode = ref(0) const currentNode = ref(0)
//
const currentNodeName = ref('')
// //
const defaultExpandedKeys = ref([]) const defaultExpandedKeys = ref([])
// tree // tree
const treeref = ref(null) const refTree = ref(null)
// //
@ -101,7 +107,6 @@ const changeBook = ({ id, itemtitle }) => {
setTimeout(() => { setTimeout(() => {
dialogVisible.value = false dialogVisible.value = false
}, 100); }, 100);
} }
const getTreeData = () => { const getTreeData = () => {
@ -112,10 +117,31 @@ const getTreeData = () => {
defaultExpandedKeys.value = [treeData.value[0].id] defaultExpandedKeys.value = [treeData.value[0].id]
nextTick(() => { nextTick(() => {
currentNode.value = getLastLevelData(treeData.value)[0].id currentNode.value = getLastLevelData(treeData.value)[0].id
currentNodeName.value = getLastLevelData(treeData.value)[0].label
emitChangeBook()
}) })
} }
const emitChangeBook = () => {
let curNode = {
id: currentNode.value,
label: currentNodeName.value
}
let parentNode = findParentByChildId(treeData.value, currentNode.value)
curNode.parentNode = toRaw(parentNode)
const data = {
textBook: {
curBookId: curBookId.value,
curBookName: curBookName.value
},
node: curNode
}
emit('changeBook', data)
}
const getLastLevelData = (tree) => { const getLastLevelData = (tree) => {
let lastLevelData = []; let lastLevelData = [];
// //
@ -137,7 +163,27 @@ const getLastLevelData = (tree) => {
// //
return lastLevelData; return lastLevelData;
} }
// id
const findParentByChildId = (treeData, targetNodeId) => {
//
//
for (let node of treeData) {
// ID
if (node.children && node.children.some(child => child.id === targetNodeId)) {
// ID ID
return node;
}
//
if (node.children) {
let parentNode = findParentNode(node.children, targetNodeId);
if (parentNode) {
return parentNode;
}
}
}
// null
return null;
}
const transData = (data) => { const transData = (data) => {
let ary = [] let ary = []
@ -170,6 +216,7 @@ const transData = (data) => {
const getSubject = async () => { const getSubject = async () => {
const { rows } = await listEvaluation({ itemkey: "version", pageSize: 500 }) const { rows } = await listEvaluation({ itemkey: "version", pageSize: 500 })
subjectList.value = rows.filter(item => item.edustage == edustage && item.edusubject == edusubject && isHaveUnit(item.id)) subjectList.value = rows.filter(item => item.edustage == edustage && item.edusubject == edusubject && isHaveUnit(item.id))
//
curBookName.value = subjectList.value[0].itemtitle curBookName.value = subjectList.value[0].itemtitle
curBookId.value = subjectList.value[0].id curBookId.value = subjectList.value[0].id
} }
@ -182,8 +229,32 @@ const isHaveUnit = (id) => {
} }
const handleNodeClick = (data) => { const handleNodeClick = (data, node) => {
emit('nodeClick', data) /**
* data : 当前节点数据
* node : 当前节点对象 包含当前节点所有数据 parent属性 指向父节点Node对象
*/
const currentNode = data;
const parentNode = node.parent.data;
if (Array.isArray(parentNode)) {
let node = parentNode.filter(item => item.id == currentNode.id)
currentNode.parentNode = { ...(node[0]) }
}
else {
currentNode.parentNode = parentNode
}
let curData = {
textBook: {
curBookId: curBookId.value,
curBookName: curBookName.value
},
node: toRaw(currentNode)
}
emit('nodeClick', curData)
} }
onMounted(() => { onMounted(() => {
@ -193,7 +264,6 @@ onMounted(() => {
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.book-wrap { .book-wrap {
width: 300px; width: 300px;
height: 100%; height: 100%;
@ -202,10 +272,17 @@ onMounted(() => {
box-shadow: 0px 0px 20px 0px rgba(99, 99, 99, 0.06); box-shadow: 0px 0px 20px 0px rgba(99, 99, 99, 0.06);
display: flex; display: flex;
flex-direction: column; flex-direction: column;
position: relative;
.book-name { .book-name {
background-color: #ffffff;
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 45px; height: 45px;
padding: 0 15px; padding: 0 15px;
z-index: 1;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
color: #3b3b3b; color: #3b3b3b;
@ -216,6 +293,7 @@ onMounted(() => {
} }
.book-list { .book-list {
padding-top: 45px;
padding-left: 10px; padding-left: 10px;
flex: 1; flex: 1;
} }
@ -290,5 +368,4 @@ onMounted(() => {
background-color: #d9e8fe !important; background-color: #d9e8fe !important;
color: #409EFF color: #409EFF
} }
</style> </style>

View File

@ -49,8 +49,8 @@ const openDialog = ()=>{
} }
const submitFile = (fileList)=>{ const submitFile = (fileList)=>{
console.log(toRaw(fileList)) // console.log(toRaw(fileList))
uploaderState().pushFile(toRaw(fileList)) // uploaderState().pushFile(toRaw(fileList))
} }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

View File

@ -1,6 +1,6 @@
<template> <template>
<div class="page-resource flex"> <div class="page-resource flex">
<ChooseTextbook @nodeClick="nodeClick" /> <ChooseTextbook @changeBook="changeBook" @nodeClick="nodeClick" />
<div class="page-right"> <div class="page-right">
<template v-if="!sourceStore.isCreate"> <template v-if="!sourceStore.isCreate">
@ -15,7 +15,6 @@
</template> </template>
<script setup> <script setup>
import { toRaw } from 'vue'
import useResoureStore from './store' import useResoureStore from './store'
import ChooseTextbook from '@/components/choose-textbook/index.vue' import ChooseTextbook from '@/components/choose-textbook/index.vue'
import ResoureSearch from './container/resoure-search.vue' import ResoureSearch from './container/resoure-search.vue'
@ -27,9 +26,14 @@ const { ipcRenderer } = window.electron || {}
// ipcRenderer.send('set-winsize',{x:1100,y: 700}) // ipcRenderer.send('set-winsize',{x:1100,y: 700})
const nodeClick = (data) => { const nodeClick = (data) => {
console.log(toRaw(data)) console.log(data)
} }
const changeBook = (data) => {
console.log(data)
}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>