Files
PORTAL_COD2/src/front/src/components/testing/TestResults.vue
T

421 lines
12 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<v-card v-if="testFinished" class="mt-4 pa-4 results-card" flat>
<v-card-title v-if="!hideTitle" class="text-h5 font-weight-bold text-center mb-6">
Результаты тестирования
</v-card-title>
<div class="result-animation-container mb-6">
<div v-if="testPassed" class="result-animation success">
<v-icon size="64" color="success" class="bounce">mdi-check-circle</v-icon>
<div class="text-h6 success--text mt-2 fade-in">Поздравляем!</div>
<div class="text-body-1 success--text fade-in">Тест успешно пройден</div>
</div>
<div v-else class="result-animation error">
<v-icon size="64" color="error" class="shake">mdi-close-circle</v-icon>
<div class="text-h6 error--text mt-2 fade-in">Не пройдено</div>
</div>
</div>
<v-row class="mt-2">
<v-col cols="12" sm="4">
<v-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">
{{ isPracticeMode ? 'Правильных ответов (нажмите чтобы увидеть детали)' : 'Правильных ответов' }}
</div>
</v-card>
</v-col>
<v-col cols="12" sm="4">
<v-card class="pa-4 text-center result-card" elevation="2">
<v-icon size="36" color="primary" class="mb-2">mdi-notebook-check</v-icon>
<p class="text-h5 mb-1">{{ answeredQuestions }}/{{ totalQuestions }}</p>
<div class="text-body-2">Ответов дано</div>
</v-card>
</v-col>
<v-col cols="12" sm="4">
<v-card class="pa-4 text-center result-card" elevation="2">
<v-icon size="36" color="primary" class="mb-2">mdi-clock-outline</v-icon>
<p class="text-h5 mb-1">{{ formattedTime }}</p>
<div class="text-body-2">Затраченное время</div>
</v-card>
</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">
<span>Правильные ответы</span>
<v-spacer></v-spacer>
<v-btn icon="mdi-close" variant="text" @click="showAnswersDialog = false" color="white"></v-btn>
</v-card-title>
<v-card-text class="pa-4">
<v-expansion-panels>
<v-expansion-panel
v-for="(question, index) in questions"
:key="index"
>
<v-expansion-panel-title>
<div class="d-flex align-center">
<v-icon
:color="getQuestionStatusColor(index)"
class="mr-2"
>
{{ getQuestionStatusIcon(index) }}
</v-icon>
<span>Вопрос {{ index + 1 }}</span>
</div>
</v-expansion-panel-title>
<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-2 d-flex align-center">
<v-icon
:color="getAnswerColor(index, answer)"
size="small"
class="mr-2"
>
{{ getAnswerIcon(index, answer) }}
</v-icon>
<span :class="{ 'font-weight-bold': isAnswerCorrect(index, answer) }">
{{ answer.name }}
</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>
</v-expansion-panels>
</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>
<script>
import { ref, computed } from 'vue';
import { useRoute } from 'vue-router';
export default {
emits: ['restart'],
props: {
hideTitle: {
type: Boolean,
default: false
},
testFinished: Boolean,
testPassed: Boolean,
correctAnswers: Number,
answeredQuestions: Number,
totalQuestions: Number,
formattedTime: String,
questions: {
type: Array,
required: true
},
userAnswers: {
type: Array,
required: true
},
fromCompletedTab: {
type: Boolean,
default: false
}
},
setup(props) {
const route = useRoute();
const showAnswersDialog = ref(false);
const isPracticeMode = computed(() => !route.query.mode || route.query.mode === 'practice');
const getQuestionStatusColor = (questionIndex) => {
if (!props.questions[questionIndex]?.answers) return 'grey';
if (props.fromCompletedTab) {
return 'grey';
}
const userAnswer = props.userAnswers?.[questionIndex];
if (!userAnswer) return 'grey';
const correctAnswers = props.questions[questionIndex].answers.filter(a => a.right_wrong === true);
const isCorrect = Array.isArray(userAnswer)
? correctAnswers.length === userAnswer.length &&
correctAnswers.every(a => userAnswer.includes(a.name)) &&
userAnswer.every(ua => correctAnswers.some(ca => ca.name === ua))
: correctAnswers.some(a => a.name === userAnswer);
return isCorrect ? 'success' : 'error';
};
const getQuestionStatusIcon = (questionIndex) => {
if (!props.questions[questionIndex]?.answers) return 'mdi-circle-outline';
if (props.fromCompletedTab) {
return '';
}
const userAnswer = props.userAnswers?.[questionIndex];
if (!userAnswer) return 'mdi-circle-outline';
const correctAnswers = props.questions[questionIndex].answers.filter(a => a.right_wrong === true);
const isCorrect = Array.isArray(userAnswer)
? correctAnswers.length === userAnswer.length &&
correctAnswers.every(a => userAnswer.includes(a.name)) &&
userAnswer.every(ua => correctAnswers.some(ca => ca.name === ua))
: correctAnswers.some(a => a.name === userAnswer);
return isCorrect ? 'mdi-check-circle' : 'mdi-close-circle';
};
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,
hasUserAnswer,
showUserAnswer,
isAnswerCorrect,
getAnswerColor,
getAnswerIcon,
getQuestionStatusColor,
getQuestionStatusIcon
};
}
};
</script>
<style scoped>
.results-card {
max-width: 1200px;
margin: 0 auto;
}
.result-animation-container {
display: flex;
justify-content: center;
align-items: center;
min-height: 160px;
}
.result-animation {
text-align: center;
animation: fadeIn 0.5s ease-out;
}
.result-card {
height: 100%;
transition: transform 0.3s ease;
border-radius: 12px;
}
.result-card:hover {
transform: translateY(-5px);
}
.cursor-pointer {
cursor: pointer;
}
.success-light {
background-color: #E8F5E9 !important;
}
.error-light {
background-color: #FFEBEE !important;
}
.bounce {
animation: bounce 1s ease infinite;
}
.shake {
animation: shake 0.5s ease-in-out;
}
.fade-in {
animation: fadeIn 0.5s ease-out forwards;
opacity: 0;
animation-delay: 0.3s;
}
@keyframes bounce {
0%, 100% {
transform: translateY(0);
}
50% {
transform: translateY(-10px);
}
}
@keyframes shake {
0%, 100% {
transform: translateX(0);
}
20%, 60% {
transform: translateX(-5px);
}
40%, 80% {
transform: translateX(5px);
}
}
@keyframes fadeIn {
from {
opacity: 0;
transform: translateY(10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@media (max-width: 600px) {
.results-card {
padding: 16px !important;
}
.result-card {
margin-bottom: 16px;
}
.text-h5 {
font-size: 1.25rem !important;
}
.text-body-2 {
font-size: 0.875rem !important;
}
}
</style>