|
|
|
@ -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
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
nodeData.parentNode = parentNode
|
|
|
|
|
let nodeData = cloneDeep(toRaw(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
|
|
|
|
|
|
|
|
|
|
let curData = {
|
|
|
|
|
textBook: {
|
|
|
|
|
curBookId: curBookId.value,
|
|
|
|
|
curBookName: curBookName.value
|
|
|
|
|
curBookId: curBook.data.id,
|
|
|
|
|
curBookName: curBook.data.itemtitle
|
|
|
|
|
},
|
|
|
|
|
node: toRaw(nodeData)
|
|
|
|
|
node: nodeData
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
currentNode.data = curData
|
|
|
|
|
// emit('nodeClick', curData)
|
|
|
|
|
|
|
|
|
|
submitNode = 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>
|
|
|
|
|
|
|
|
|
|