fix [P-227]: сдача, несдача тестирования

This commit is contained in:
Denis Voinovich committed 2025-05-29 11:29:48 +03:00
1 parent 25810b0fcc
commit c78b427546
2 files changed
+122 -2

No files matched your search

@@ -34,6 +34,9 @@
:answeredQuestions="answeredQuestions"
:totalQuestions="data.question_count"
:formattedTime="formattedTime"
:questions="data?.questions"
:userAnswers="answers"
@restart="startTest"
/>
<!-- Диалог подтверждения завершения теста -->
@@ -138,11 +141,19 @@ export default {
const startTest = async () => {
await deactivateOldTestings(testId);
await getTestById(testId);
testStarted.value = true;
testFinished.value = false;
answers.value = Array(data.value.questions.length).fill(null);
data.value = { ...data.value, time: data.value.time * 60 };
if (timer) {
clearInterval(timer);
}
timer = setInterval(() => {
if (data.value?.time > 0) {
data.value = { ...data.value, time: data.value.time - 1 };
@@ -14,17 +14,35 @@
<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 class="text-body-1 error--text fade-in">Попробуйте еще раз</div>
<v-btn
v-if="isPracticeMode"
color="teal-darken-4"
class="mt-4 px-6"
@click="$emit('restart')"
>
Пройти заново
<v-icon class="ml-2">mdi-reload</v-icon>
</v-btn>
</div>
</div>
<v-row class="mt-2">
<v-col cols="12" sm="4">
<v-card class="pa-4 text-center result-card" elevation="2" :color="testPassed ? 'success-light' : 'error-light'">
<v-card
class="pa-4 text-center result-card"
elevation="2"
:color="testPassed ? 'success-light' : 'error-light'"
:class="{ 'cursor-pointer': isPracticeMode }"
@click="showAnswersDialog = isPracticeMode"
>
<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">Правильных ответов</div>
<div class="text-body-2">
Правильных ответов
<v-icon v-if="isPracticeMode" small color="primary">mdi-information</v-icon>
</div>
</v-card>
</v-col>
@@ -44,11 +62,63 @@
</v-card>
</v-col>
</v-row>
<!-- Модальное окно с правильными ответами -->
<v-dialog v-model="showAnswersDialog" max-width="600" v-if="isPracticeMode">
<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="isQuestionCorrect(index) ? 'success' : 'error'"
class="mr-2"
>
{{ isQuestionCorrect(index) ? 'mdi-check-circle' : 'mdi-close-circle' }}
</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-1">
<v-icon
:color="answer.right_wrong ? 'success' : ''"
size="small"
class="mr-1"
>
{{ answer.right_wrong ? 'mdi-check' : 'mdi-minus' }}
</v-icon>
<span :class="{ 'font-weight-bold': answer.right_wrong }">
{{ answer.name }}
</span>
<span v-if="answer.right_wrong" class="text-success">(правильный ответ)</span>
</div>
</v-expansion-panel-text>
</v-expansion-panel>
</v-expansion-panels>
</v-card-text>
</v-card>
</v-dialog>
</v-card>
</template>
<script>
import { ref, computed } from 'vue';
import { useRoute } from 'vue-router';
export default {
emits: ['restart'],
props: {
testFinished: Boolean,
testPassed: Boolean,
@@ -56,6 +126,41 @@ export default {
answeredQuestions: Number,
totalQuestions: Number,
formattedTime: String,
questions: {
type: Array,
required: true
},
userAnswers: {
type: Array,
required: true
}
},
setup(props) {
const route = useRoute();
const showAnswersDialog = ref(false);
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));
}
return question.answers.find(a => a.name === userAnswer)?.right_wrong || false;
};
return {
showAnswersDialog,
isPracticeMode,
isQuestionCorrect
};
}
};
</script>
@@ -88,6 +193,10 @@ export default {
transform: translateY(-5px);
}
.cursor-pointer {
cursor: pointer;
}
.success-light {
background-color: #E8F5E9 !important;
}