refactor [P-36 УМТ]: карточки тестов
This commit is contained in:
1 parent
50ca51820c
commit
09b9980c09
42 files changed
+599
-67142
No files matched your search
@@ -1,18 +1,159 @@
|
||||
<template>
|
||||
<v-container>
|
||||
<HeaderDetailTesting />
|
||||
<v-container class="pa-4">
|
||||
<!-- Верхняя панель -->
|
||||
<HeaderDetailTesting
|
||||
:testStarted="testStarted"
|
||||
:formattedTime="formattedTime"
|
||||
:finishTest="openFinishDialog"
|
||||
:currentQuestion="currentQuestion"
|
||||
:totalQuestions="questions.length"
|
||||
@change-question="changeQuestion"
|
||||
/>
|
||||
|
||||
</v-container>
|
||||
<!-- Блок информации о тесте -->
|
||||
<BodyDetailTesting v-if="!testStarted && !testFinished" :startTest="startTest" />
|
||||
|
||||
<!-- Вопросы теста -->
|
||||
<QuestionBlock
|
||||
v-if="testStarted"
|
||||
:question="questions[currentQuestion]"
|
||||
:currentQuestion="currentQuestion"
|
||||
:totalQuestions="questions.length"
|
||||
:answers="answers"
|
||||
@change-question="changeQuestion"
|
||||
/>
|
||||
|
||||
<!-- Результаты теста -->
|
||||
<TestResults
|
||||
v-if="testFinished"
|
||||
:testFinished="testFinished"
|
||||
:testPassed="testPassed"
|
||||
:correctAnswers="correctAnswers"
|
||||
:answeredQuestions="answeredQuestions"
|
||||
:totalQuestions="questions.length"
|
||||
:formattedTime="formattedTime"
|
||||
/>
|
||||
|
||||
<!-- Диалог подтверждения завершения теста -->
|
||||
<v-dialog v-model="showFinishDialog" persistent max-width="400px">
|
||||
<v-card>
|
||||
<v-card-title class="text-h6">Завершить тест?</v-card-title>
|
||||
<v-card-text>Вы уверены, что хотите завершить тестирование?</v-card-text>
|
||||
<v-card-actions class="d-flex justify-end">
|
||||
<v-btn color="teal-darken-1" @click="finishTest">Да, завершить</v-btn>
|
||||
<v-btn color="grey" @click="showFinishDialog = false">Отмена</v-btn>
|
||||
</v-card-actions>
|
||||
</v-card>
|
||||
</v-dialog>
|
||||
</v-container>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import HeaderDetailTesting from './HeaderDetailTesting.vue';
|
||||
|
||||
import { computed, ref, onUnmounted } from 'vue';
|
||||
import HeaderDetailTesting from '@/components/testing/HeaderDetailTesting.vue';
|
||||
import BodyDetailTesting from '@/components/testing/BodyDetailTesting.vue';
|
||||
import QuestionBlock from '@/components/testing/QuestionBlock.vue';
|
||||
import TestResults from '@/components/testing/TestResults.vue';
|
||||
|
||||
export default {
|
||||
components: {
|
||||
HeaderDetailTesting,
|
||||
}
|
||||
}
|
||||
components: { BodyDetailTesting, HeaderDetailTesting, QuestionBlock, TestResults },
|
||||
setup() {
|
||||
const timeLeft = ref(900);
|
||||
const testStarted = ref(false);
|
||||
const testFinished = ref(false);
|
||||
const showFinishDialog = ref(false);
|
||||
const currentQuestion = ref(0);
|
||||
let timer = null;
|
||||
|
||||
</script>
|
||||
const questions = ref([
|
||||
{
|
||||
question: 'Ваши родители знают что Вы гей?',
|
||||
options: ['Да', 'Нет'],
|
||||
correct: 'Да',
|
||||
},
|
||||
{
|
||||
question: 'Какой цвет у неба?',
|
||||
options: ['Синий', 'Зеленый', 'Красный', 'Желтый'],
|
||||
correct: 'Синий',
|
||||
},
|
||||
{ question: 'Сколько дней в неделе?', options: ['5', '6', '7', '8'], correct: '7' },
|
||||
{
|
||||
question: 'Как называется столица Франции?',
|
||||
options: ['Берлин', 'Париж', 'Лондон', 'Рим'],
|
||||
correct: 'Париж',
|
||||
},
|
||||
{ question: 'Сколько ног у паука?', options: ['4', '6', '8', '10'], correct: '8' },
|
||||
]);
|
||||
|
||||
const answers = ref(new Array(questions.value.length).fill(null));
|
||||
|
||||
const formattedTime = computed(() => {
|
||||
const minutes = Math.floor(timeLeft.value / 60);
|
||||
const seconds = timeLeft.value % 60;
|
||||
return `${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`;
|
||||
});
|
||||
|
||||
const correctAnswers = computed(
|
||||
() =>
|
||||
answers.value.filter((answer, index) => answer === questions.value[index].correct).length,
|
||||
);
|
||||
|
||||
const answeredQuestions = computed(
|
||||
() => answers.value.filter((answer) => answer !== null).length,
|
||||
);
|
||||
|
||||
const testPassed = computed(() => correctAnswers.value >= questions.value.length / 2);
|
||||
|
||||
const startTest = () => {
|
||||
testStarted.value = true;
|
||||
testFinished.value = false;
|
||||
timer = setInterval(() => {
|
||||
if (timeLeft.value > 0) {
|
||||
timeLeft.value--;
|
||||
} else {
|
||||
clearInterval(timer);
|
||||
openFinishDialog();
|
||||
}
|
||||
}, 1000);
|
||||
};
|
||||
|
||||
const changeQuestion = (newIndex) => {
|
||||
if (newIndex >= 0 && newIndex < questions.value.length) {
|
||||
currentQuestion.value = newIndex;
|
||||
}
|
||||
};
|
||||
|
||||
const openFinishDialog = () => {
|
||||
showFinishDialog.value = true;
|
||||
};
|
||||
|
||||
const finishTest = () => {
|
||||
clearInterval(timer);
|
||||
testStarted.value = false;
|
||||
testFinished.value = true;
|
||||
showFinishDialog.value = false;
|
||||
};
|
||||
|
||||
onUnmounted(() => {
|
||||
if (timer) clearInterval(timer);
|
||||
});
|
||||
|
||||
return {
|
||||
testStarted,
|
||||
testFinished,
|
||||
formattedTime,
|
||||
startTest,
|
||||
finishTest,
|
||||
questions,
|
||||
answers,
|
||||
currentQuestion,
|
||||
changeQuestion,
|
||||
showFinishDialog,
|
||||
openFinishDialog,
|
||||
correctAnswers,
|
||||
answeredQuestions,
|
||||
testPassed,
|
||||
};
|
||||
},
|
||||
};
|
||||
</script>
|
||||
Reference in new issue
Block a user