|
|
@@ -118,11 +118,12 @@
|
|
|
<script lang="ts" setup>
|
|
|
import {ZoomIn, Search} from "@element-plus/icons-vue";
|
|
|
import {Calendar,Check,Close} from "@element-plus/icons-vue";
|
|
|
- import {onMounted, reactive, ref, computed} from "vue";
|
|
|
+ import {onMounted, reactive, ref, computed, watch} from "vue";
|
|
|
import useApis from "@/apis";
|
|
|
import {useStore} from "@/store";
|
|
|
import type {CourseVO, IAssignment} from "@/types/vo";
|
|
|
import router from "@/router";
|
|
|
+ import {useRoute} from "vue-router";
|
|
|
|
|
|
import {useFormatDate} from "@/hooks/useFormatDate";
|
|
|
|
|
|
@@ -130,6 +131,9 @@
|
|
|
const store = useStore()
|
|
|
const {formatDate} = useFormatDate()
|
|
|
const role:'teachers' | 'student' = store.user.role === 'STUDENT' ? 'student':'teachers';
|
|
|
+
|
|
|
+ // 获取路由信息
|
|
|
+ const route = useRoute()
|
|
|
|
|
|
// 课程列表
|
|
|
const courseList = ref<CourseVO[]>([])
|
|
|
@@ -253,11 +257,43 @@
|
|
|
|
|
|
// 选择课程
|
|
|
const selectCourse = (courseId: number) => {
|
|
|
+ console.log('selectCourse 被调用,课程ID:', courseId)
|
|
|
selectedCourseId.value = courseId
|
|
|
// 筛选当前课程的作业
|
|
|
currentCourseAssignments.value = allAssignments.value.filter(
|
|
|
assignment => assignment.courseId === courseId
|
|
|
)
|
|
|
+ console.log('选中课程后,当前课程作业数量:', currentCourseAssignments.value.length)
|
|
|
+ console.log('allAssignments总数:', allAssignments.value.length)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理路由参数 - 从其他页面返回时自动选中课程
|
|
|
+ const handleRouteParams = () => {
|
|
|
+ const { courseId, fromAssignment } = route.query
|
|
|
+
|
|
|
+ console.log('handleRouteParams 被调用,参数:', { courseId, fromAssignment })
|
|
|
+ console.log('课程列表长度:', courseList.value.length, '作业总数:', allAssignments.value.length)
|
|
|
+
|
|
|
+ // 如果有课程ID参数且是从作业页面返回的
|
|
|
+ if (courseId && fromAssignment === 'true') {
|
|
|
+ const targetCourseId = Number(courseId)
|
|
|
+ console.log('目标课程ID:', targetCourseId)
|
|
|
+
|
|
|
+ // 检查目标课程是否存在
|
|
|
+ const targetCourse = courseList.value.find(course => course.courseId === targetCourseId)
|
|
|
+ if (targetCourse) {
|
|
|
+ console.log('找到目标课程,开始选择课程')
|
|
|
+ selectCourse(targetCourseId)
|
|
|
+
|
|
|
+ // 清除路由参数,避免重复处理
|
|
|
+ router.replace({
|
|
|
+ name: 'myHomework',
|
|
|
+ query: {}
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ console.log('未找到目标课程')
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 重置搜索
|
|
|
@@ -389,12 +425,15 @@
|
|
|
}
|
|
|
|
|
|
const fetchHomeworkListByCourseId = (courseId:number) => {
|
|
|
+ console.log('开始获取课程', courseId, '的作业数据')
|
|
|
apis.getAssignmentByCourseId(courseId)
|
|
|
.then((res: any) => {
|
|
|
let total = res.data.data.total
|
|
|
+ console.log('课程', courseId, '总作业数:', total)
|
|
|
apis.getAssignmentByCourseId(courseId, 1, total)
|
|
|
.then((res: any) => {
|
|
|
let data = res.data.data.records
|
|
|
+ console.log('课程', courseId, '获取到', data.length, '个作业')
|
|
|
for(let i = 0; i < data.length; i++) {
|
|
|
data[i].endTime = formatDate(data[i].endTime)
|
|
|
data[i].courseId = courseId // 添加课程ID
|
|
|
@@ -402,7 +441,16 @@
|
|
|
data[i].submissionStatus = getRandomSubmissionStatus()
|
|
|
homeworkList.tableData.push(data[i])
|
|
|
allAssignments.value.push(data[i]) // 添加到所有作业数组
|
|
|
+ console.log('添加作业:', data[i].assignmentName, 'courseId:', data[i].courseId)
|
|
|
+ }
|
|
|
+ console.log('课程', courseId, '作业加载完成,当前allAssignments总数:', allAssignments.value.length)
|
|
|
+
|
|
|
+ // 如果有选中的课程且正好是这个课程ID,立即重新筛选
|
|
|
+ if (selectedCourseId.value === courseId) {
|
|
|
+ console.log('检测到当前选中课程', courseId, '的作业已加载,重新筛选')
|
|
|
+ selectCourse(courseId)
|
|
|
}
|
|
|
+
|
|
|
processedHomeworkList.tableData = homeworkList.tableData
|
|
|
Object.assign(pageInfo, {
|
|
|
tableData: getSlice(pageInfo.pages, pageInfo.size),
|
|
|
@@ -424,6 +472,30 @@
|
|
|
return processedHomeworkList.tableData.slice((page-1)*size, page*size)
|
|
|
}
|
|
|
|
|
|
+ // 监听课程列表变化,数据加载完成后处理路由参数
|
|
|
+ watch(courseList, (newCourseList) => {
|
|
|
+ console.log('courseList 变化,课程数量:', newCourseList.length)
|
|
|
+ if (newCourseList.length > 0) {
|
|
|
+ handleRouteParams()
|
|
|
+ }
|
|
|
+ }, { immediate: false })
|
|
|
+
|
|
|
+ // 监听作业数据变化,确保作业数据也加载完成
|
|
|
+ watch(allAssignments, (newAssignments) => {
|
|
|
+ console.log('allAssignments 变化,作业数量:', newAssignments.length)
|
|
|
+
|
|
|
+ // 如果有选中的课程且作业数据更新了,重新筛选作业
|
|
|
+ if (selectedCourseId.value && newAssignments.length > 0) {
|
|
|
+ console.log('重新筛选选中课程的作业,课程ID:', selectedCourseId.value)
|
|
|
+ selectCourse(selectedCourseId.value)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果作业数据加载完成,再次尝试处理路由参数
|
|
|
+ if (newAssignments.length > 0) {
|
|
|
+ handleRouteParams()
|
|
|
+ }
|
|
|
+ }, { immediate: false })
|
|
|
+
|
|
|
onMounted(() => {
|
|
|
fetchData()
|
|
|
})
|