fix [P-227]: результаты тестирования для завершенных тестов

This commit is contained in:
Denis Voinovich committed 2025-06-02 08:56:17 +03:00
1 parent a78a21edf9
commit d456952d6c
2 files changed
+194 -32

No files matched your search

+164 -25
View File
@@ -19,17 +19,18 @@
<v-row class="mt-2">
<v-col cols="12" sm="4">
<v-card
class="pa-4 text-center result-card"
class="pa-4 text-center result-card"
:class="{ 'cursor-pointer': isPracticeMode }"
elevation="2"
:color="testPassed ? 'success-light' : 'error-light'"
@click="isPracticeMode && (showAnswersDialog = true)"
>
<v-icon size="36" :color="testPassed ? 'success' : 'error'" class="mb-2">
mdi-checkbox-marked-circle
</v-icon>
<p class="text-h5 mb-1">{{ correctAnswers }}/{{ totalQuestions }}</p>
<div class="text-body-2">
Правильных ответов
<v-icon v-if="isPracticeMode" small color="primary">mdi-information</v-icon>
{{ isPracticeMode ? 'Правильных ответов (нажмите чтобы увидеть детали)' : 'Правильных ответов' }}
</div>
</v-card>
</v-col>
@@ -51,7 +52,7 @@
</v-col>
</v-row>
<!-- Модальное окно с правильными ответами отображается только в режиме тренировки -->
<!-- Модальное окно с правильными ответами (только для тренировочного режима) -->
<v-dialog v-if="isPracticeMode" v-model="showAnswersDialog" max-width="600">
<v-card>
<v-card-title class="d-flex align-center text-h6 font-weight-bold px-4 py-3 bg-teal-darken-4 text-white">
@@ -68,10 +69,10 @@
<v-expansion-panel-title>
<div class="d-flex align-center">
<v-icon
:color="isQuestionCorrect(index) ? 'success' : 'error'"
:color="getQuestionStatusColor(index)"
class="mr-2"
>
{{ isQuestionCorrect(index) ? 'mdi-check-circle' : 'mdi-close-circle' }}
{{ getQuestionStatusIcon(index) }}
</v-icon>
<span>Вопрос {{ index + 1 }}</span>
</div>
@@ -79,18 +80,32 @@
<v-expansion-panel-text>
<p class="mb-2 font-weight-bold">{{ question.name }}</p>
<v-divider class="mb-2"></v-divider>
<div v-for="answer in question.answers" :key="answer.id" class="mb-1">
<div v-for="answer in question.answers" :key="answer.id" class="mb-2 d-flex align-center">
<v-icon
:color="answer.right_wrong ? 'success' : ''"
:color="getAnswerColor(index, answer)"
size="small"
class="mr-1"
class="mr-2"
>
{{ answer.right_wrong ? 'mdi-check' : 'mdi-minus' }}
{{ getAnswerIcon(index, answer) }}
</v-icon>
<span :class="{ 'font-weight-bold': answer.right_wrong }">
<span :class="{ 'font-weight-bold': isAnswerCorrect(index, answer) }">
{{ answer.name }}
</span>
<span v-if="answer.right_wrong" class="text-success">(правильный ответ)</span>
<v-chip
v-if="answer.isUserAnswer"
size="small"
class="ml-2"
:color="answer.right_wrong === true ? 'success' : 'error'"
variant="outlined"
>
Ваш ответ
</v-chip>
</div>
<div v-if="hasUserAnswer(index)" class="mt-4">
<v-divider class="mb-2"></v-divider>
<div class="text-caption">
{{ isQuestionCorrect(index) ? 'Правильно ✓' : 'Неправильно ✗' }}
</div>
</div>
</v-expansion-panel-text>
</v-expansion-panel>
@@ -98,6 +113,19 @@
</v-card-text>
</v-card>
</v-dialog>
<!-- Кнопка "Попробовать ещё раз" для тренировочного режима -->
<div v-if="isPracticeMode && !fromCompletedTab" class="d-flex justify-center mt-6">
<v-btn
color="teal-darken-1"
@click="$emit('restart')"
class="px-6"
size="large"
>
<v-icon start>mdi-refresh</v-icon>
Попробовать ещё раз
</v-btn>
</div>
</v-card>
</template>
@@ -125,6 +153,10 @@ export default {
userAnswers: {
type: Array,
required: true
},
fromCompletedTab: {
type: Boolean,
default: false
}
},
setup(props) {
@@ -133,25 +165,132 @@ export default {
const isPracticeMode = computed(() => !route.query.mode || route.query.mode === 'practice');
const isQuestionCorrect = (questionIndex) => {
const question = props.questions[questionIndex];
const userAnswer = props.userAnswers[questionIndex];
if (!userAnswer) return false;
if (Array.isArray(userAnswer)) {
const correctAnswers = question.answers.filter(a => a.right_wrong).map(a => a.name);
return userAnswer.length === correctAnswers.length &&
userAnswer.every(answer => correctAnswers.includes(answer));
const getQuestionStatusColor = (questionIndex) => {
if (!props.questions[questionIndex]?.answers) return 'grey';
if (props.fromCompletedTab) {
return 'grey';
}
return question.answers.find(a => a.name === userAnswer)?.right_wrong || false;
const hasCorrectAnswers = props.questions[questionIndex].answers.some(a => a.right_wrong === true);
return hasCorrectAnswers ? 'success' : 'grey';
};
const getQuestionStatusIcon = (questionIndex) => {
if (!props.questions[questionIndex]?.answers) return 'mdi-circle-outline';
if (props.fromCompletedTab) {
return '';
}
const hasCorrectAnswers = props.questions[questionIndex].answers.some(a => a.right_wrong === true);
return hasCorrectAnswers ? 'mdi-check-circle' : 'mdi-circle-outline';
};
const hasUserAnswer = (index) => {
const answer = props.userAnswers?.[index];
return answer !== null && answer !== undefined;
};
const showUserAnswer = (index, answerName) => {
const userAnswer = props.userAnswers?.[index];
if (!userAnswer) return false;
if (Array.isArray(userAnswer)) {
return userAnswer.includes(answerName);
}
return userAnswer === answerName;
}; const isQuestionCorrect = (questionIndex) => {
const question = props.questions?.[questionIndex];
if (!question?.answers || !Array.isArray(question.answers)) return false;
const userAnswer = props.userAnswers?.[questionIndex];
if (!userAnswer) return false;
const correctAnswers = question.answers.filter(a => a.right_wrong === true);
if (correctAnswers.length === 0) return false;
if (Array.isArray(userAnswer)) {
return correctAnswers.length === userAnswer.length &&
correctAnswers.every(a => userAnswer.includes(a.name)) &&
userAnswer.every(ua => correctAnswers.some(ca => ca.name === ua));
}
return correctAnswers.some(a => a.name === userAnswer);
};
const isAnswerCorrect = (questionIndex, answer) => {
if (!answer || !answer.name || questionIndex === undefined || questionIndex === null) {
return false;
}
if (!props.fromCompletedTab) {
return answer.right_wrong === true;
}
const userAnswer = props.userAnswers?.[questionIndex];
if (!userAnswer) return false;
const isSelected = Array.isArray(userAnswer)
? userAnswer.includes(answer.name)
: userAnswer === answer.name;
return isSelected && answer.right_wrong === true;
};
const getAnswerColor = (questionIndex, answer) => {
if (!answer?.name) return 'grey';
if (answer.right_wrong === true) {
return 'success';
}
const userAnswer = props.userAnswers?.[questionIndex];
if (userAnswer) {
const isSelected = Array.isArray(userAnswer)
? userAnswer.includes(answer.name)
: userAnswer === answer.name;
if (isSelected) {
return 'error';
}
}
return 'grey';
};
const getAnswerIcon = (questionIndex, answer) => {
if (!answer?.name) return 'mdi-circle-outline';
if (answer.right_wrong === true) {
return 'mdi-check-circle';
}
const userAnswer = props.userAnswers?.[questionIndex];
if (userAnswer) {
const isSelected = Array.isArray(userAnswer)
? userAnswer.includes(answer.name)
: userAnswer === answer.name;
if (isSelected) {
return 'mdi-close-circle';
}
}
return 'mdi-circle-outline';
};
return {
showAnswersDialog,
isPracticeMode,
isQuestionCorrect
isQuestionCorrect,
hasUserAnswer,
showUserAnswer,
isAnswerCorrect,
getAnswerColor,
getAnswerIcon,
getQuestionStatusColor,
getQuestionStatusIcon
};
}
};
+30 -7
View File
@@ -175,6 +175,7 @@
:formattedTime="testResults.time_spent"
:questions="testResults.questions"
:userAnswers="testResults.user_answers"
:fromCompletedTab="testResults.fromCompletedTab"
/>
</v-card-text>
</v-card>
@@ -387,14 +388,36 @@ export default {
axiosApiInstance.get(`/api/tests/testresultview/?id=${id}`)
]);
const questions = (testDetailResponse.data.questions || []).map(q => ({
...q,
answers: (q.answers || []).map(a => ({
...a,
isUserAnswer: false
}))
}));
const userAnswers = questions.map(question => {
const userAnswer = resultResponse.data.user_answers?.[question.id];
if (!userAnswer) return null;
question.answers.forEach(answer => {
answer.isUserAnswer = Array.isArray(userAnswer)
? userAnswer.includes(answer.name)
: userAnswer === answer.name;
});
return userAnswer;
});
testResults.value = {
passed: resultResponse.data.is_passed,
total_questions: testDetailResponse.data.question_count,
total_answers: resultResponse.data.answered_questions_total,
correct_answers: resultResponse.data.score,
time_spent: `${testDetailResponse.data.time} мин`,
questions: [],
userAnswers: []
passed: resultResponse.data.is_passed || false,
total_questions: testDetailResponse.data.question_count || 0,
total_answers: resultResponse.data.answered_questions_total || 0,
correct_answers: resultResponse.data.score || 0,
time_spent: `${testDetailResponse.data.time || 0} мин`,
questions: questions,
userAnswers: userAnswers,
fromCompletedTab: activeTab.value === 1
};
showResultsDialog.value = true;