|
|
@@ -274,7 +274,7 @@
|
|
|
<script lang="ts" setup>
|
|
|
import useApis from "@/apis";
|
|
|
import {ref, reactive, computed, onMounted} from "vue";
|
|
|
- import {useRouter} from "vue-router";
|
|
|
+ import {useRouter, useRoute} from "vue-router";
|
|
|
import {Refresh, Search, Document, ArrowDown, ArrowRight, User, CircleCheck, WarningFilled, Sort, ZoomIn} from "@element-plus/icons-vue";
|
|
|
import type {ClassDTO, StudentAssignmentStatusDTO} from "@/types/dto";
|
|
|
import type {CourseVO, IAssignment} from "@/types/vo";
|
|
|
@@ -282,6 +282,7 @@
|
|
|
import {useStore} from "@/store";
|
|
|
const store = useStore()
|
|
|
const router = useRouter()
|
|
|
+ const route = useRoute()
|
|
|
|
|
|
const apis = useApis()
|
|
|
const selectedAssignment = ref(null)
|
|
|
@@ -830,9 +831,58 @@
|
|
|
searchResults.value = []
|
|
|
}
|
|
|
|
|
|
+ // 自动选中课程和作业的函数
|
|
|
+ const autoSelectFromRoute = () => {
|
|
|
+ const courseIdFromRoute = route.query.courseId
|
|
|
+ const assignmentIdFromRoute = route.query.assignmentId
|
|
|
+ const fromCorrect = route.query.fromCorrect
|
|
|
+
|
|
|
+ if (fromCorrect && courseIdFromRoute && assignmentIdFromRoute) {
|
|
|
+ const courseId = Number(courseIdFromRoute)
|
|
|
+ const assignmentId = Number(assignmentIdFromRoute)
|
|
|
+
|
|
|
+ console.log('准备自动选中:', { courseId, assignmentId })
|
|
|
+
|
|
|
+ // 使用递归检查数据是否加载完成
|
|
|
+ const checkAndSelect = (attempts = 0) => {
|
|
|
+ if (attempts > 20) { // 最多尝试20次,避免无限循环
|
|
|
+ console.warn('自动选中超时,数据可能未加载完成')
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ const course = courseList.find(c => c.courseId === courseId)
|
|
|
+ if (course && course.assignments.length > 0) {
|
|
|
+ // 数据已加载,执行选中
|
|
|
+ course.expanded = true
|
|
|
+
|
|
|
+ // 确保作业存在
|
|
|
+ const assignment = course.assignments.find(a => a.assignmentId === assignmentId)
|
|
|
+ if (assignment) {
|
|
|
+ selectAssignment(assignmentId)
|
|
|
+ console.log('自动选中成功:', { courseName: course.courseName, assignmentName: assignment.assignmentName })
|
|
|
+
|
|
|
+ // 清理URL参数,避免刷新时重复执行
|
|
|
+ router.replace({
|
|
|
+ name: 'myCorrectWithCourse'
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ console.warn('未找到指定的作业:', assignmentId)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 数据未加载完成,继续等待
|
|
|
+ setTimeout(() => checkAndSelect(attempts + 1), 200)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ checkAndSelect()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 组件挂载时加载数据
|
|
|
- onMounted(() => {
|
|
|
- loadCourses()
|
|
|
+ onMounted(async () => {
|
|
|
+ await loadCourses()
|
|
|
+ // 检查是否需要自动选中
|
|
|
+ autoSelectFromRoute()
|
|
|
})
|
|
|
</script>
|
|
|
|