作业批改列表:逻辑代码优化

This commit is contained in:
白了个白 2024-11-05 17:28:16 +08:00
parent 1cc0bf965e
commit a918aa18e9
2 changed files with 224 additions and 325 deletions

View File

@ -1,28 +0,0 @@
import { defineStore } from 'pinia'
import { } from '@/api/classTask/index.js'
import { listClassmain } from '@/api/classManage/index'
const useClassTaskStore = defineStore('classTask',{
state: () => ({
classListIds: [],
}),
actions: {
listClassmain(params) {
// 获取班级列表
return new Promise((resolve, reject) => {
listClassmain(params)
.then((res) => {
this.classListIds = res.rows&&res.rows.map((item) => item.id)
resolve(res)
})
.catch((error) => {
reject(error)
})
})
},
},
persist: true
})
export default useClassTaskStore

View File

@ -61,7 +61,6 @@ import TaskItem from '@/views/classTask/container/classTask/task-item.vue'
import { useToolState } from '@/store/modules/tool' import { useToolState } from '@/store/modules/tool'
import { getCurrentTime, getDateFormatDate, getTheOtherDay, getTheOtheNextDay } from '@/utils/date' import { getCurrentTime, getDateFormatDate, getTheOtherDay, getTheOtheNextDay } from '@/utils/date'
import useUserStore from '@/store/modules/user' import useUserStore from '@/store/modules/user'
import useClassTaskStore from "@/store/modules/classTask";
import {createWindow} from '@/utils/tool' import {createWindow} from '@/utils/tool'
import {sessionStore} from '@/utils/store' import {sessionStore} from '@/utils/store'
import {debounce } from '@/utils/comm' import {debounce } from '@/utils/comm'
@ -69,7 +68,6 @@ import {debounce } from '@/utils/comm'
const toolState = useToolState(); const toolState = useToolState();
const classTaskStore = useClassTaskStore()
const userStore = useUserStore().user const userStore = useUserStore().user
// const itemDialogRef = ref(null) // const itemDialogRef = ref(null)
const tabOptions = ref(['待批改', '已批改']) const tabOptions = ref(['待批改', '已批改'])
@ -96,15 +94,16 @@ const loading = ref(false)
const activeDataList = computed(() => { const activeDataList = computed(() => {
return classWorkList.value return classWorkList.value
}) })
const doneDataList = computed(() => {
return classWorkList.value
})
const deleteReserv = (item) => { const deleteReserv = (item) => {
console.log('删除待开发', item) console.log('删除待开发', item)
// dataList.value = dataList.value.filter((is) => { // dataList.value = dataList.value.filter((is) => {
// return is.id !== item.id // return is.id !== item.id
// }) // })
} }
const doneDataList = computed(() => {
return classWorkList.value
})
// //
const disabledDate = (time) => { const disabledDate = (time) => {
@ -120,36 +119,22 @@ const changeStartEndDate = (val) => {
const getData = async () => { const getData = async () => {
classWorkList.value = [] classWorkList.value = []
loading.value = true loading.value = true
// 1 // 1
// getClassList()
// 2
await getClassWorkList() await getClassWorkList()
// 3 // 2
getStudentClassWorkData() getStudentClassWorkData()
loading.value = false loading.value = false
} }
/** /**
* 1获取班级列表数据 * 1获取班级作业
* TODO 这里暂时取班级id的list后续需要在修改
*/
const getClassList = () => {
if(classTaskStore.classListIds.length==0){
// ids idlist
classTaskStore.listClassmain({ classuserid: userStore.userId, pageSize: 100, status: 'open' })
}
}
/**
* 2获取班级作业
*/ */
const getClassWorkList = async () => { const getClassWorkList = async () => {
//if(classTaskStore.classListIds.length>0){
{
// homeworklist // homeworklist
const response = await listByDeadDate({ const response = await listByDeadDate({
edituserid: userStore.userId, // id edituserid: userStore.userId, // id
edustage: userStore.edustage, // edustage: userStore.edustage, //
edusubject: userStore.edusubject,// edusubject: userStore.edusubject,//
// deaddate: tabActive.value === ''? getTomorrow() : EndDate.value,//
startdate: tabActive.value === '待批改'? '' : getDateFormatDate(startEndDate.value[0]), startdate: tabActive.value === '待批改'? '' : getDateFormatDate(startEndDate.value[0]),
deaddate: tabActive.value === '待批改'? '' : getDateFormatDate(startEndDate.value[1]),// deaddate: tabActive.value === '待批改'? '' : getDateFormatDate(startEndDate.value[1]),//
status: tabActive.value === '待批改'? '1' : '2', // 1- status: tabActive.value === '待批改'? '1' : '2', // 1-
@ -157,26 +142,12 @@ const getClassWorkList = async () => {
pageSize: 100, pageSize: 100,
}) })
/** 2024-11-02
* 2024-10-17 由于 后面截止时间加了 时分特加判断
* 1待批改以前是以明天判断现改为传当天的日期并根据当前日期的时分与截止日期进行判断
* 2已批改以前默认是以明天判断现依然以明天为判断并根据当前日期时分大于截止日期时分判断
*/
// let list = [];
// if(tabActive.value === ''){
// //
// list = response.rows&&response.rows.filter(item => item.deaddate && getCurrentTime('YYYY-MM-DD HH:mm') < item.deaddate); //
// }else{
// list = response.rows&&response.rows.filter(item => item.deaddate && getCurrentTime('YYYY-MM-DD HH:mm') > item.deaddate); //
// }
let list = response.rows || []; let list = response.rows || [];
for (var i = 0; i < list.length; i++) { for (var i = 0; i < list.length; i++) {
// //
list[i].workdatalist = [] list[i].workdatalist = [] //
list[i].workdatalistVisible = false list[i].workdatalistVisible = false
list[i].workdatafeedbackcount = 0 // list[i].feedtimelength = 0 //
list[i].feedtimelength = 0
list[i].rightAnswerCount = 0 list[i].rightAnswerCount = 0
list[i].scoingRate = 0 + '%' // list[i].scoingRate = 0 + '%' //
list[i].averagetime = 0 // list[i].averagetime = 0 //
@ -206,6 +177,7 @@ const getClassWorkList = async () => {
list[i].entpcourseworklistarray = [] list[i].entpcourseworklistarray = []
} }
} }
// (workdataresultsum)>0 // (workdataresultsum)>0
if (list && list.length > 0) { if (list && list.length > 0) {
classWorkList.value = list && list.filter((item) => item.workdataresultsum > 0) classWorkList.value = list && list.filter((item) => item.workdataresultsum > 0)
@ -216,40 +188,25 @@ const getClassWorkList = async () => {
total.value = 0 total.value = 0
} }
loading.value = false loading.value = false
}
} }
/** /**
* 3获取多个班级学生作业数据 * 2获取多个班级学生作业数据
* 查询已交的列表
* @param workList 需要更新的作业list
* @param Refresh true 不用刷新false 需要刷新
*/ */
const getStudentClassWorkData = async() => { const getStudentClassWorkData = async(workList = [], Refresh = true) => {
// const { chapterId } = await useGetHomework(props.bookobj.node) // (workdataresultcount )
// this.entpcourseid = chapterId let SubmitClWorkList = [];
//if(classTaskStore.classListIds.length>0){ if(Refresh){
// listClassworkdataByDeadDate({ SubmitClWorkList = classWorkList.value.filter((item) => item.workdataresultcount > 0) ;
// edituserid: userStore.userId, // id }else{
// classids: classTaskStore.classListIds.join(','), SubmitClWorkList = workList;
// edusubject: userStore.edusubject,// }
// deaddate: tabActive.value === ''? getTomorrow() : EndDate.value,//
// deaddate: EndDate.value,//
// startdate: tabActive.value === ''? '' : getDateFormatDate(startEndDate.value[0]),
// deaddate:tabActive.value === ''? '' : getDateFormatDate(startEndDate.value[1]),
// //status: tabActive.value === ''? '1' : '2', // 1-
// orderby: "deaddate DESC",//
// pageSize: 1000,
// })
// listClassworkdataNew({ console.log('有提交的作业', SubmitClWorkList)
// classworkids: ids, // id const ids = SubmitClWorkList&&SubmitClWorkList.map((item) => item.id).join(',');
// edituserid: userStore.userId, // id
// edusubject: userStore.edusubject,//
// evalStatus: 1,
// pageSize: 1000,
// })
{
const ids = classWorkList.value.map((item) => item.id).join(',');
if (ids == '') { if (ids == '') {
return; return;
} }
@ -259,13 +216,14 @@ const getStudentClassWorkData = async() => {
}).then((res) => { }).then((res) => {
for (var t = 0; t < classWorkList.value.length; t++) { for (var t = 0; t < classWorkList.value.length; t++) {
for (var i = 0; i < res.rows.length; i++) { for (var i = 0; i < res.rows.length; i++) {
// finishtimelength != '0'
if (res.rows[i].classworkid == classWorkList.value[t].id && res.rows[i].finishtimelength != '0') { if (res.rows[i].classworkid == classWorkList.value[t].id && res.rows[i].finishtimelength != '0') {
console.log('==================') console.log('==================')
// / // /
// resultcount0 // resultcount0
classWorkList.value[t].workdatafeedbackcount++ //classWorkList.value[t].workdataresultcount++
// //
classWorkList.value[t].feedtimelength += parseInt(res.rows[i].finishtimelength) classWorkList.value[t].feedtimelength += parseInt(res.rows[i].finishtimelength)
// //
@ -308,11 +266,10 @@ const getStudentClassWorkData = async() => {
classWorkList.value[t].workdatalist.push(res.rows[i]) classWorkList.value[t].workdatalist.push(res.rows[i])
} }
} }
// workdataresultsum0
if (
classWorkList.value[t].workdataresultcount > 0 && // : workdataresultcount ; workdataresultsum 0;
classWorkList.value[t].workdataresultsum > 0 if (classWorkList.value[t].workdataresultcount > 0 && classWorkList.value[t].workdataresultsum > 0 ) {
) {
classWorkList.value[t].finishpercent = parseInt( classWorkList.value[t].finishpercent = parseInt(
(classWorkList.value[t].workdataresultcount / classWorkList.value[t].workdataresultsum) * 100 (classWorkList.value[t].workdataresultcount / classWorkList.value[t].workdataresultsum) * 100
) )
@ -324,7 +281,6 @@ const getStudentClassWorkData = async() => {
// workdataresultsum teacherrationgcount // workdataresultsum teacherrationgcount
// (-) / * 100 // (-) / * 100
if (classWorkList.value[t].workdataresultsum > 0) { if (classWorkList.value[t].workdataresultsum > 0) {
// teacherCorrectionProgress :
classWorkList.value[t].teacherCorrectionProgress = parseInt( classWorkList.value[t].teacherCorrectionProgress = parseInt(
((classWorkList.value[t].teacherrationgcount) / classWorkList.value[t].workdataresultsum) * 100 ((classWorkList.value[t].teacherrationgcount) / classWorkList.value[t].workdataresultsum) * 100
) )
@ -335,16 +291,13 @@ const getStudentClassWorkData = async() => {
// //
// 2024-04-12by jackyshen // 2024-04-12by jackyshen
// // /
if (classWorkList.value[t].workdatafeedbackcount > 0) { if (classWorkList.value[t].workdataresultcount > 0) {
classWorkList.value[t].averagetime = Math.ceil(classWorkList.value[t].feedtimelength / classWorkList.value[t].workdatafeedbackcount / 60).toFixed(0) classWorkList.value[t].averagetime = Math.ceil(classWorkList.value[t].feedtimelength / classWorkList.value[t].workdataresultcount / 60).toFixed(0)
} else { } else {
classWorkList.value[t].averagetime = 0 classWorkList.value[t].averagetime = 0
} }
//
//
// /**100 // /**100
if ( if (
classWorkList.value[t].entpcourseworklistarray && classWorkList.value[t].entpcourseworklistarray &&
@ -359,11 +312,9 @@ const getStudentClassWorkData = async() => {
} else { } else {
classWorkList.value[t].scoingRate = '0%' classWorkList.value[t].scoingRate = '0%'
} }
//
//
} }
}) })
}
} }
@ -424,91 +375,56 @@ onUnmounted(() => {
// [] - // [] -
const getStudentVisible = async () => { const getStudentVisible = async () => {
if (classTaskStore.classListIds.length <= 0) { if(!classWorkList.value.length>0){
return return;
} }
//
const response = await listByDeadDate({ const response = await listByDeadDate({
classidarray: classTaskStore.classListIds.join(','),
edituserid: userStore.userId, // id edituserid: userStore.userId, // id
edustage: userStore.edustage,// edustage: userStore.edustage, //
edusubject: userStore.edusubject,// edusubject: userStore.edusubject,//
// deaddate: tabActive.value === ''? getTomorrow() : EndDate.value,//
// deaddate: EndDate.value,//
startdate: tabActive.value === '待批改'? '' : getDateFormatDate(startEndDate.value[0]), startdate: tabActive.value === '待批改'? '' : getDateFormatDate(startEndDate.value[0]),
deaddate: tabActive.value === '待批改'? '' : getDateFormatDate(startEndDate.value[1]), deaddate: tabActive.value === '待批改'? '' : getDateFormatDate(startEndDate.value[1]),//
status: tabActive.value === '待批改'? '1' : '2', // 1- status: tabActive.value === '待批改'? '1' : '2', // 1-
// orderby: 'concat(deaddate,uniquekey) DESC',
orderby: 'deaddate DESC', orderby: 'deaddate DESC',
pageSize: 100 pageSize: 100,
}) })
/** let list = response.rows || [];
* 2024-10-17 由于 后面截止时间加了 时分特加判断
* 1待批改以前是以明天判断现改为传当天的日期并根据当前日期的时分与截止日期进行判断 let newList = [];
* 2已批改以前默认是以明天判断现依然以明天为判断并根据当前日期时分大于截止日期时分判断 for(let i = 0; i < classWorkList.value.length; i++){
*/ // listidlistid listlist
let list = []; const isList = list.filter((item) => item.id === classWorkList.value[i].id);
if(tabActive.value === '待批改'){ if(isList.length === 0){
// // listidlistidlist
list = response.rows&&response.rows.filter(item => item.deaddate && getCurrentTime('YYYY-MM-DD HH:mm') < item.deaddate); // classWorkList.value.splice(i,1);
}else{
list = response.rows&&response.rows.filter(item => item.deaddate && getCurrentTime('YYYY-MM-DD HH:mm') > item.deaddate); //
} }
for(let j = 0; j < list.length; j++){
const curWorkList = list // workdataresultcount ;
if(classWorkList.value[i].id === list[j].id && classWorkList.value[i].workdataresultcount != list[j].workdataresultcount){
/** // =
* warn: 这里仅更新了finishpercent(进度条), 且当前作业布置推送新任务时, curWorkList中会查到新的任务与当前页面中this.classWorkList长度不一致, newList.push(list[j]);
* 故这里需循环this.classWorkList且只更新当前页面中的存在的任务进度
*/
for (let t = 0; t < classWorkList.value.length; t++) {
// []
// if( getDateTime > classWorkList.value[t].deaddate ){
// continue;
// }
// (index)
let curWork = curWorkList.find((work) => work.id === classWorkList.value[t].id)
// workdataresultcount workdataresultsum0
if (curWork && curWork.workdataresultcount > 0 && classWorkList.value[t].workdataresultsum > 0) {
classWorkList.value[t].workdataresultcount = curWork.workdataresultcount
//
classWorkList.value[t].finishpercent = parseInt(
(classWorkList.value[t].workdataresultcount / classWorkList.value[t].workdataresultsum) * 100
)
//
if (classWorkList.value[t].workdatafeedbackcount > 0) {
classWorkList.value[t].averagetime = Math.ceil(classWorkList.value[t].feedtimelength / classWorkList.value[t].workdatafeedbackcount / 60).toFixed(0)
} else {
classWorkList.value[t].averagetime = 0
} }
// teacherrationgcount
} else { if(classWorkList.value[i].id === list[j].id && classWorkList.value[i].teacherrationgcount != list[j].teacherrationgcount){
// //
if(curWork && curWork.workdataresultcount == 0){ if (classWorkList.value[i].workdataresultsum > 0) {
// //
classWorkList.value[t].teacherrationgcount = curWork.teacherrationgcount classWorkList.value[i].teacherrationgcount = list[j].teacherrationgcount;
} classWorkList.value[i].teacherCorrectionProgress = parseInt(
classWorkList.value[t].finishpercent = 0 ((list[j].teacherrationgcount) / list[j].workdataresultsum) * 100
}
/** 计算 已批阅进度 */
// workdataresultsum teacherrationgcount
// (-) / * 100
if (curWork && curWork.workdataresultsum > 0) {
//
classWorkList.value[t].teacherrationgcount = curWork.teacherrationgcount
// teacherCorrectionProgress :
classWorkList.value[t].teacherCorrectionProgress = parseInt(
((curWork.teacherrationgcount) / curWork.workdataresultsum) * 100
) )
} else { } else {
classWorkList.value[t].teacherCorrectionProgress = 0 classWorkList.value[i].teacherCorrectionProgress = 0
} }
} }
}
return 1 }
if(newList.length>0){
//
const list = newList&&newList.filter((item) => item.workdataresultcount > 0) ;
getStudentClassWorkData(list,false);
}
} }
@ -516,16 +432,27 @@ const getStudentVisible = async () => {
watch( watch(
() => [dataList, toolState.isTaskWin], () => [dataList, toolState.isTaskWin],
() => { () => {
console.log('=监听到批改窗口打开了===', toolState.isTaskWin) console.log('监听--批改窗口是否打开===', toolState.isTaskWin)
if(!toolState.isTaskWin){ if(!toolState.isTaskWin){
if(tabActive.value === '待批改'){
closeDialog();// closeDialog();//
} }
} }
}
) )
watch(tabActive, (newVal,oldVal)=>{ watch(tabActive, (newVal,oldVal)=>{
console.log('newVal',newVal); console.log('newVal',newVal);
getData() // getData() //
if(newVal === '待批改'){
//
console.log('监听---开启轮询')
closeDialog();
}else{
//
console.log('监听---关闭轮询')
clearInterval(pollingST.value);
}
}) })
</script> </script>