From 58df855801607bd4aae3921994c6001f545c58d5 Mon Sep 17 00:00:00 2001 From: AfyerCu <20569838@qq.com> Date: Fri, 21 Nov 2025 21:05:19 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96=E9=98=85?= =?UTF-8?q?=E5=8D=B7=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/marking/MarkingLayout.vue | 20 +++- .../marking/composables/useMarkingData.ts | 2 - src/composables/marking/MarkingContext.ts | 7 +- .../marking/ReviewMarkingContext.ts | 99 +++++++++++++++++++ src/pages/marking/grading.vue | 30 ++++-- src/pages/marking/review.vue | 98 +++++++++++------- 6 files changed, 202 insertions(+), 54 deletions(-) create mode 100644 src/composables/marking/ReviewMarkingContext.ts diff --git a/src/components/marking/MarkingLayout.vue b/src/components/marking/MarkingLayout.vue index ba98631..68fc7e7 100644 --- a/src/components/marking/MarkingLayout.vue +++ b/src/components/marking/MarkingLayout.vue @@ -6,6 +6,7 @@ import { useMarkingSettings } from '@/components/marking/composables/useMarkingS import { useMarkingHistory } from '@/composables/marking/useMarkingHistory' interface Props { + mode: string isLandscape: boolean currentQuestionIndex: number totalQuestions: number @@ -135,6 +136,7 @@ const currentHistoryIndexInList = computed(() => { { - {{ isViewingHistory ? historyModeText : `${currentTaskSubmit}/${totalQuestions}` }} + {{ + mode === 'review' + ? '回评模式' + : (isViewingHistory ? historyModeText : `${Math.min(currentTaskSubmit, totalQuestions)}/${totalQuestions}`) + }} @@ -242,6 +248,7 @@ const currentHistoryIndexInList = computed(() => { { - {{ currentTaskSubmit }}/{{ totalQuestions }} + {{ mode === 'review' ? '回评模式' : (isViewingHistory ? historyModeText : `${Math.min(currentTaskSubmit, totalQuestions)}/${totalQuestions}`) }} @@ -311,12 +318,17 @@ const currentHistoryIndexInList = computed(() => { - + - + + + diff --git a/src/components/marking/composables/useMarkingData.ts b/src/components/marking/composables/useMarkingData.ts index c4ddfe9..08d9e05 100644 --- a/src/components/marking/composables/useMarkingData.ts +++ b/src/components/marking/composables/useMarkingData.ts @@ -252,8 +252,6 @@ function createMarkingData(options: UseMarkingDataOptions) { } // 重新获取下一题 - questionData.value = [] - currentMarkingSubmitData.value = [] markingStartTime.value = 0 await refetchQuestion() processQuestionData() diff --git a/src/composables/marking/MarkingContext.ts b/src/composables/marking/MarkingContext.ts index 8014b50..fc3b320 100644 --- a/src/composables/marking/MarkingContext.ts +++ b/src/composables/marking/MarkingContext.ts @@ -8,6 +8,7 @@ import type { ExamStudentMarkingQuestionResponse, ExamStudentMarkingQuestionsResponse, } from '@/api' +import { injectLocal, provideLocal } from '@vueuse/core' import { examMarkingTaskApi } from '@/api' // 分页响应接口 @@ -265,14 +266,16 @@ export const MarkingContextSymbol = Symbol('MarkingContext') * 提供阅卷上下文 */ export function provideMarkingContext(context: MarkingContext) { - provide(MarkingContextSymbol, context) + provideLocal(MarkingContextSymbol, context) + + return context } /** * 使用阅卷上下文 */ export function useMarkingContext(): MarkingContext | null { - return inject(MarkingContextSymbol) || null + return injectLocal(MarkingContextSymbol) || null } /** diff --git a/src/composables/marking/ReviewMarkingContext.ts b/src/composables/marking/ReviewMarkingContext.ts new file mode 100644 index 0000000..bf7e9e4 --- /dev/null +++ b/src/composables/marking/ReviewMarkingContext.ts @@ -0,0 +1,99 @@ +import type { + MarkingDataProvider, + MarkingHistoryProvider, + MarkingHistoryRecord, + PaginatedResponse, + SubmitResponse, +} from './MarkingContext' +import type { + ExamBatchCreateMarkingTaskRecordRequest, + ExamStudentMarkingQuestionResponse, +} from '@/api' +import { ref } from 'vue' +import { examMarkingTaskApi } from '@/api' +import { provideMarkingContext } from './MarkingContext' + +// Store for the question to be reviewed +const currentReviewQuestion = ref(null) + +/** + * 设置当前回评的题目 + */ +export function setReviewQuestion(question: ExamStudentMarkingQuestionResponse) { + currentReviewQuestion.value = question +} + +/** + * 回评数据提供者 + * 直接返回预设的题目数据 + */ +export class ReviewMarkingDataProvider implements MarkingDataProvider { + async getSingleQuestion(_taskId: number): Promise { + return currentReviewQuestion.value + } + + async getMultipleQuestions( + taskId: number, + _options: { count: number }, + ): Promise<{ questions: ExamStudentMarkingQuestionResponse[] } | null> { + const question = await this.getSingleQuestion(taskId) + return question ? { questions: [question] } : null + } + + async submitRecords(data: ExamBatchCreateMarkingTaskRecordRequest): Promise { + // 允许提交(重新打分) + const response = await examMarkingTaskApi.batchCreate({ ...data, is_review: true }) + if (!response) + return null + + return { + success_count: response.success_count || 0, + fail_data: response.fail_data?.map(item => ({ message: item.message || '' })), + success_data: response.success_data?.map(item => ({ + id: item.id || 0, + question_id: item.question_id || 0, + score: item.score || 0, + remark: item.remark, + is_excellent: item.is_excellent || 0, + is_model: item.is_model || 0, + is_problem: item.is_problem || 0, + })), + is_end: response.is_end || false, + } + } + + async createProblemRecord(data: any): Promise { + await examMarkingTaskApi.problemRecordCreate(data) + } +} + +/** + * 回评历史提供者 + * 返回空历史,禁用历史功能 + */ +export class ReviewMarkingHistoryProvider implements MarkingHistoryProvider { + async getHistoryPage( + _taskId: number, + _options: { page: number, page_size: number }, + ): Promise> { + return { + list: [], + page: 1, + page_size: 20, + total: 0, + has_more: false, + } + } +} + +/** + * 提供回评上下文 + */ +export function provideReviewMarkingContext() { + provideMarkingContext({ + dataProvider: new ReviewMarkingDataProvider(), + historyProvider: new ReviewMarkingHistoryProvider(), + isHistory: false, + defaultPosition: 'last', + }) +} diff --git a/src/pages/marking/grading.vue b/src/pages/marking/grading.vue index 1c41670..06dd234 100644 --- a/src/pages/marking/grading.vue +++ b/src/pages/marking/grading.vue @@ -8,9 +8,10 @@