diff --git a/src/renderer/src/store/modules/classTask.js b/src/renderer/src/store/modules/classTask.js index 17b008d..fc64a44 100644 --- a/src/renderer/src/store/modules/classTask.js +++ b/src/renderer/src/store/modules/classTask.js @@ -7,7 +7,7 @@ const useClassTaskStore = defineStore('classTask',{ state: () => ({ experimentObj:{ edustage: '小学', // 教育阶段 - edusubject: '', // 学科 + edusubject: '数学', // 学科 experimentList: [], // 实验科目列表 updateEduInfo: '小学-数学', //实际需上传的学段+学科信息(用于上传及回显实验内的学段学科) }, diff --git a/src/renderer/src/views/classTask/newClassTaskAssign/experimentQuestion/components/experimentList.vue b/src/renderer/src/views/classTask/newClassTaskAssign/experimentQuestion/components/experimentList.vue index c19db84..a7ff24a 100644 --- a/src/renderer/src/views/classTask/newClassTaskAssign/experimentQuestion/components/experimentList.vue +++ b/src/renderer/src/views/classTask/newClassTaskAssign/experimentQuestion/components/experimentList.vue @@ -42,7 +42,7 @@ const updateLabel = (val) => { const onSelectOption = (option) => { classTaskStore.updateEduInfo = `${classTaskStore.edustage}-${classTaskStore.edusubject}`; - console.log('updateEduInfo->', classTaskStore.experimentList.updateEduInfo); + console.log('updateEduInfo->', classTaskStore.updateEduInfo); console.log(option,'选择的实验课-------') emit('selectItem', classTaskStore.experimentList.filter(item => item.label === option)[0]) } diff --git a/src/renderer/src/views/classTask/newClassTaskAssign/experimentQuestion/components/selectClass.vue b/src/renderer/src/views/classTask/newClassTaskAssign/experimentQuestion/components/selectClass.vue index d076cee..635643d 100644 --- a/src/renderer/src/views/classTask/newClassTaskAssign/experimentQuestion/components/selectClass.vue +++ b/src/renderer/src/views/classTask/newClassTaskAssign/experimentQuestion/components/selectClass.vue @@ -56,7 +56,7 @@ const subjectList = ref([]) const chooseGrade= ref({}) const expList = ref([]) // 当前年级的所有课程 const checkList = ref([])// 当前年级对应学科的课程, - +const isLoaded = ref(false); // 获取基础的学科 const getSubject = () => { @@ -80,8 +80,15 @@ const getSubject = () => { }) }) console.log(subjectList,'subjectList'); + // 默认读取一个学科 - handleUserEduStage(useClassTaskStore().experimentObj.edustage) + const edusubject = useClassTaskStore().experimentObj.edusubject; + handleUserEduStage(useClassTaskStore().experimentObj.edustage); + // 这里确保第一次初始化时, 该任务是从左侧作业列表中进来而存在指定的学科时, 重新赋值回来. + useClassTaskStore().experimentObj.edusubject = edusubject; + // 执行完毕后标志位[置位] + isLoaded.value = true; + //console.log('初始化执行完毕----'); } // 展示有 实验科目的学科 const isExpList = (edusubject) => { @@ -108,7 +115,8 @@ const isExpList = (edusubject) => { // 选择学段 const handleUserEduStage = (item) => { // userStore.edustage = item - useClassTaskStore().experimentObj.edustage = item + useClassTaskStore().experimentObj.edustage = item; + //清空操作 expList.value = [] if(item === '小学'){ @@ -121,6 +129,7 @@ const handleUserEduStage = (item) => { useClassTaskStore().experimentObj.edusubject = name; // 更改学科默认与学科下的实验科目 handleUserEduSubject(name) + break; } } }else if(item === '初中'){ @@ -133,6 +142,7 @@ const handleUserEduStage = (item) => { useClassTaskStore().experimentObj.edusubject = name; // 更改学科默认与学科下的实验科目 handleUserEduSubject(name) + break; } } }else if(item === '高中'){ @@ -145,6 +155,7 @@ const handleUserEduStage = (item) => { useClassTaskStore().experimentObj.edusubject = name; // 更改学科默认与学科下的实验科目 handleUserEduSubject(name) + break; } } } @@ -177,20 +188,50 @@ const handleUserEduSubject = (item) => { // emit('experlist',checkList.value) } -const updateCheckList = () => { - const edustage = useClassTaskStore().experimentObj.edustage; - if(edustage === '小学'){ - chooseGrade.value = jsonData.data.primary - }else if(edustage === '初中'){ - chooseGrade.value = jsonData.data.junior - }else if(edustage === '高中'){ - chooseGrade.value = jsonData.data.senior +const updateCheckList = async () => { + try { + await waitForSubjectData(); + + //console.log('父组件执行开始-------', ); + //console.log('experimentObj-> ', useClassTaskStore().experimentObj); + // 再执行更新逻辑 + const edustage = useClassTaskStore().experimentObj.edustage; + if(edustage === '小学'){ + chooseGrade.value = jsonData.data.primary + }else if(edustage === '初中'){ + chooseGrade.value = jsonData.data.junior + }else if(edustage === '高中'){ + chooseGrade.value = jsonData.data.senior + } + expList.value = chooseGrade.value + const edusubject = useClassTaskStore().experimentObj.edusubject; + handleUserEduSubject(edusubject); + } catch (error) { + console.error(error); } - expList.value = chooseGrade.value - const edusubject = useClassTaskStore().experimentObj.edusubject; - handleUserEduSubject(edusubject); } +const waitForSubjectData = () => { + return new Promise((resolve, reject) => { + let timeoutId; + let intervalId; + + const checkIsLoaded = () => { + if (isLoaded.value) { + clearInterval(intervalId); + clearTimeout(timeoutId); + resolve(); + } + }; + + intervalId = setInterval(checkIsLoaded, 100); + timeoutId = setTimeout(() => { + clearInterval(intervalId); + reject(new Error('该作业-等待[科学实验]学科学段初始化超时')); + }, 5000); + }); +}; + onMounted(() => { getSubject() diff --git a/src/renderer/src/views/classTask/newClassTaskAssign/index.vue b/src/renderer/src/views/classTask/newClassTaskAssign/index.vue index 6448666..51cb2d7 100644 --- a/src/renderer/src/views/classTask/newClassTaskAssign/index.vue +++ b/src/renderer/src/views/classTask/newClassTaskAssign/index.vue @@ -537,7 +537,7 @@ const handleClassWorkFormQuizRemove = (index) =>{ if(isShow.value === false){ if(classWorkForm.id != '' ) {// 编辑状态 有id editWork(cform); // 编辑作业 - return; + return; } } @@ -600,7 +600,8 @@ const handleClassWorkFormQuizRemove = (index) =>{ } else if(classWorkForm.worktype === "科学实验"){ if (classWorkForm.fileHomeworkList.length == 0) return ElMessage({ type: 'warning', message: '请选择科学实验的课程!'}); - cform.workcodes = JSON.stringify(classWorkForm.fileHomeworkList); + cform.worktag = useClassTaskStores.experimentObj.updateEduInfo; // 当前实验的学段学科, 格式为[小学-数学] + cform.workcodes = JSON.stringify(classWorkForm.fileHomeworkList); // 实验信息 cform.entpcourseworklist = JSON.stringify([{'id':-3, 'score': '10'}]); try { console.log(cform,'科学实验')