From 2c6da76cf77367efa86fbb7ecc841b08166973bf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=99=BD=E4=BA=86=E4=B8=AA=E7=99=BD?= <543593352@qq.com>
Date: Thu, 19 Sep 2024 10:52:33 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E8=AE=BE=E8=AE=A1=E8=B7=B3?=
=?UTF-8?q?=E8=BD=ACweb=E7=AB=AF=E9=80=BB=E8=BE=91=E4=BF=AE=E6=94=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/renderer/src/hooks/useGetClassWork.js | 201 ++++++++
src/renderer/src/utils/date.js | 3 +
.../container/newTask/taskTypeView.vue | 454 ++++++++++++++++++
.../src/views/classTask/newClassTask.vue | 177 +++----
src/renderer/src/views/desktop/index.vue | 28 +-
5 files changed, 757 insertions(+), 106 deletions(-)
create mode 100644 src/renderer/src/hooks/useGetClassWork.js
create mode 100644 src/renderer/src/views/classTask/container/newTask/taskTypeView.vue
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/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 @@
+
+