删除 hooks、useGetClassWork.js

This commit is contained in:
lyc 2024-10-14 15:12:05 +08:00
parent 35af866a53
commit bf642ddc79
1 changed files with 0 additions and 202 deletions

View File

@ -1,202 +0,0 @@
import { nextTick, toRaw } from 'vue'
import useUserStore from '@/store/modules/user'
import { listEvaluation } from '@/api/subject'
const userStore = useUserStore()
const { edustage, edusubject } = userStore.user
let evaluationList = []; // 教材版本list
let subjectList = []; // 教材list
//当前教材ID
let curBookId = -1;
/**
* 外部链接初始化获取 跳转web端的 unitId 专用
* 暂时 初始化作业设计专用后期可能会取消
*/
export const useGetClassWork = async () => {
const params = {
edusubject,
edustage,
// entpcourseedituserid: userId,
itemgroup: 'textbook',
orderby: 'orderidx asc',
pageSize: 10000
}
if(localStorage.getItem('evaluationList')){
evaluationList = JSON.parse(localStorage.getItem('evaluationList'))
}else{
const { rows } = await listEvaluation(params)
localStorage.setItem('evaluationList', JSON.stringify(rows))
evaluationList = rows
}
//获取教材版本
await getSubject()
//上册
/**
* 不区分上下册
* 2024/08/20调整
*/
// volumeOne = data.filter(item => item.level == 1 && item.semester == '上册')
// volumeTwo = data.filter(item => item.level == 1 && item.semester == '下册')
getTreeData()
}
//获取教材
const getSubject = async () => {
if(localStorage.getItem('subjectList')){
subjectList = JSON.parse(localStorage.getItem('subjectList'))
}else{
const { rows } = await listEvaluation({ itemkey: "version", edusubject, edustage, pageSize: 10000,orderby: 'orderidx asc', })
// subjectList = rows.filter(item => item.edustage == edustage && item.edusubject == edusubject)
subjectList = rows
localStorage.setItem('subjectList', JSON.stringify(subjectList))
}
// 默认第一个
if(!subjectList.length) return
// curBookName = subjectList[0].itemtitle
curBookId = subjectList[0].id
// curBookImg = BaseUrl + subjectList[0].avartar
// curBookPath = subjectList[0].fileurl
}
const getTreeData = () => {
//数据过滤
let upData = transData(evaluationList)
if(upData.length){
// treeData = [...upData]
}else{
// treeData = []
return
}
nextTick(() => {
// defaultExpandedKeys = [treeData[0].id]
// let currentNodeObj = {...getLastLevelData(upData)[0]}
let currentNodeId = getLastLevelData(upData)[0].id
let currentNodeName = getLastLevelData(upData)[0].label
let curNode = {
id: currentNodeId,
label: currentNodeName,
// itemtitle: currentNodeObj.itemtitle,
// edudegree: currentNodeObj.edudegree,
// edustage: currentNodeObj.edustage,
// edusubject: currentNodeObj.edusubject,
}
let parentNode = findParentByChildId(upData, currentNodeId)
curNode.parentNode = toRaw(parentNode)
let levelFirstId = '';
let levelSecondId = '';
if (curNode.parentNode) {
levelFirstId = curNode.parentNode.id
} else {
levelFirstId = curNode.id
levelSecondId = ''
}
let bookeId = curBookId
// 头部 教材分析、作业设计打开外部链接需要当前章节ID
localStorage.setItem('unitId', JSON.stringify({ levelFirstId, levelSecondId, bookeId}))
// const data = {
// textBook: {
// curBookId: curBookId,
// curBookName: curBookName,
// curBookImg: curBookImg,
// curBookPath: curBookPath
// },
// node: curNode
// }
// emit('changeBook', data)
})
}
const getLastLevelData = (tree) => {
let lastLevelData = [];
// 递归函数遍历树形结构
function traverseTree(nodes) {
nodes.forEach((node) => {
// 如果当前节点有子节点,继续遍历
if (node.children && node.children.length > 0) {
traverseTree(node.children);
} else {
// 如果没有子节点,说明是最后一层的节点
lastLevelData.push(node);
}
});
}
// 调用递归函数开始遍历
traverseTree(tree);
// 返回最后一层的数据
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 = findParentByChildId(node.children, targetNodeId);
if (parentNode) {
return parentNode;
}
}
}
// 如果未找到匹配的父节点,则返回 null 或者适当的默认值
return null;
}
const transData = (data) => {
let ary = []
data.forEach(item => {
let obj = {}
// 根据当前教材ID 过滤出对应的单元、章节
if (item.rootid == curBookId) {
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.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
}