From 9ad759c694a4dc45d03205cd484d901fee7e3fdd Mon Sep 17 00:00:00 2001 From: chenpei Date: Mon, 13 Jul 2026 18:39:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=80=83=E6=A0=B8=E8=B0=83?= =?UTF-8?q?=E7=A0=94=E8=AF=84=E5=88=86=E8=BF=9B=E5=BA=A6=E5=9B=9E=E6=98=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/performance-survey/[[...path]]/page.tsx | 17 ++++--- ...rformance-survey-response-progress.test.ts | 44 +++++++++++++++++++ lib/performance-survey-response-progress.ts | 30 +++++++++++++ 3 files changed, 85 insertions(+), 6 deletions(-) create mode 100644 lib/__tests__/performance-survey-response-progress.test.ts create mode 100644 lib/performance-survey-response-progress.ts diff --git a/app/performance-survey/[[...path]]/page.tsx b/app/performance-survey/[[...path]]/page.tsx index e513183a..7c4f2211 100644 --- a/app/performance-survey/[[...path]]/page.tsx +++ b/app/performance-survey/[[...path]]/page.tsx @@ -8,6 +8,7 @@ import { useSession } from 'next-auth/react' import { pinyin } from 'pinyin-pro' import { createPortal } from 'react-dom' import { sortPerformanceSurveyImagesByName } from '@/lib/performance-survey-image-order' +import { calculatePerformanceSurveyResponseProgress } from '@/lib/performance-survey-response-progress' type ApiState = { loading: boolean @@ -3850,9 +3851,13 @@ function SurveySubmit({ surveyId, session }: { surveyId: string; session: any }) const activeTarget = detail.data.targets.find((target: any) => target.id === activeTargetId) const submitted = activeTarget?.currentAssignment?.status === 'submitted' - const scoreValues = questions.map((question) => Number(scores[question.id] ?? 0)) - const scoreTotal = scoreValues.reduce((sum, value) => sum + value, 0) - const ratedCount = questions.filter((question) => Number.isFinite(scores[question.id])).length + const submittedScores = activeTarget?.currentAssignment?.response?.scores + const progress = calculatePerformanceSurveyResponseProgress({ + questions, + draftScores: scores, + submittedScores: submittedScores && typeof submittedScores === 'object' ? submittedScores : {}, + submitted, + }) const surveyStatusLabel = getSurveyStatusLabel(detail.data.status) const dueLabel = detail.data.dueAt ? `截止 ${formatDate(detail.data.dueAt)}` : '无截止时间' const viewer = session?.user || {} @@ -3913,12 +3918,12 @@ function SurveySubmit({ surveyId, session }: { surveyId: string; session: any })
填写进度 - {ratedCount}/{questions.length || 0} · {scoreTotal} 分 + {progress.ratedCount}/{progress.totalCount} · {progress.totalScore} 分
0 ? Math.min(100, (ratedCount / questions.length) * 100) : 0}%` }} + style={{ width: `${progress.percent}%` }} />
@@ -4078,7 +4083,7 @@ function SurveySubmit({ surveyId, session }: { surveyId: string; session: any })