diff --git a/src/renderer/src/hooks/useGetClassWork.js b/src/renderer/src/hooks/useGetClassWork.js new file mode 100644 index 0000000..7aa313a --- /dev/null +++ b/src/renderer/src/hooks/useGetClassWork.js @@ -0,0 +1,201 @@ +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 = '' + } + // 头部 教材分析、作业设计:打开外部链接需要当前章节ID + localStorage.setItem('unitId', JSON.stringify({ levelFirstId, levelSecondId})) + + // 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 +} + diff --git a/src/renderer/src/router/index.js b/src/renderer/src/router/index.js index 5e0caa1..7bc8424 100644 --- a/src/renderer/src/router/index.js +++ b/src/renderer/src/router/index.js @@ -80,6 +80,12 @@ export const constantRoutes = [ name: 'classCorrect', meta: {title: '作业批改'}, }, + { + path: '/newClassTask', + component: () => import('@/views/classTask/newClassTask.vue'), + name: 'newClassCorrect', + meta: {title: '作业设计'}, + }, { path: '/examReport', component: () => import('@/views/examReport/index.vue'), diff --git a/src/renderer/src/utils/date.js b/src/renderer/src/utils/date.js index 2adf3d5..29b0f44 100644 --- a/src/renderer/src/utils/date.js +++ b/src/renderer/src/utils/date.js @@ -97,6 +97,9 @@ export const getCurrentTime = (format)=> { if(format == 'HH:mm'){ return `${hours}:${minutes}`; } + if(format == 'MMDD'){ + return `${month}${day}`; + } } /** * diff --git a/src/renderer/src/views/classTask/container/newTask/taskTypeView.vue b/src/renderer/src/views/classTask/container/newTask/taskTypeView.vue new file mode 100644 index 0000000..e0f3ac9 --- /dev/null +++ b/src/renderer/src/views/classTask/container/newTask/taskTypeView.vue @@ -0,0 +1,454 @@ + + + + + + + + + + {{ item }} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 查找 + + + + + + + + + + 题目内容 + + + + + + + + {{ scope.row.entpname }} {{ scope.row.editusername }} + {{ scope.row.worktag }} + + + + + + + 添加 + + + + + + + + + + + + + + + + + + + + + 删除 + + + + + + + + + + + + {{ item.worktype }} + + + + + + + 预览 + 删除 + + + + + + + + + + + + + + + + + diff --git a/src/renderer/src/views/classTask/newClassTask.vue b/src/renderer/src/views/classTask/newClassTask.vue new file mode 100644 index 0000000..3bf6214 --- /dev/null +++ b/src/renderer/src/views/classTask/newClassTask.vue @@ -0,0 +1,164 @@ + + + + + + + + + + + + + + + + 作业范围 + + + + + + + + + + + + + + + + + + + + diff --git a/src/renderer/src/views/desktop/index.vue b/src/renderer/src/views/desktop/index.vue index 66190e1..69913c6 100644 --- a/src/renderer/src/views/desktop/index.vue +++ b/src/renderer/src/views/desktop/index.vue @@ -45,6 +45,8 @@ import { useRouter } from 'vue-router' import workTrend from './container/work-trend.vue' import outLink from '@/utils/linkConfig' import * as echarts from 'echarts' +import { useGetClassWork } from '@/hooks/useGetClassWork' + const router = useRouter() const { ipcRenderer } = window.electron || {} @@ -104,7 +106,10 @@ const menuList = [{ { name: '作业设计', icon: 'icon-jiaoxuefansi', - path: '/classTaskAssign' + isOuter: true, + path: '/teaching/classtaskassign?titleName=作业布置&openDialog=newClassTask' + //path: '/newClassTask' + //path: '/classTaskAssign' //isOuter: true, //path: '/teaching/classtaskassign?titleName=作业布置&&openDialog=newClassTask' }, @@ -161,6 +166,13 @@ const clickMenu = ({isOuter, path, disabled}) =>{ if(isOuter){ let configObj = outLink().getBaseData() let fullPath = configObj.fullPath + path + if(path == '/teaching/classtaskassign?titleName=作业布置&openDialog=newClassTask'){ + // 头部 教材分析打开外部链接需要当前章节ID + const { levelFirstId, levelSecondId } = JSON.parse(localStorage.getItem('unitId')) + + let unitId = levelSecondId ? levelSecondId : levelFirstId + fullPath = fullPath + `&unitId=${unitId}` + } fullPath = fullPath.replaceAll('//', '/') // 通知主进程 ipcRenderer.send('openWindow', { @@ -219,8 +231,21 @@ onMounted(async ()=>{ ] } chartInstance.setOption(option); + // 初始化 获取教材下面的单元 + 章节 + getSubjectInit(); }) + +const getSubjectInit = async () => { + //查看本地是否有缓存 + let unitId = localStorage.getItem('unitId') + if(unitId){ + // 有缓存不用管 + } else{ + // 没有 就获取 获取教材下面的单元 + 章节 + useGetClassWork(); + } +}