feat [P-227]: валидация вопросов в конструткоре, подсказка при множественном выборе ответов
This commit is contained in:
1 parent
aaf2b44749
commit
04840193e2
4 files changed
+37
-25
No files matched your search
@@ -38,6 +38,7 @@
|
||||
|
||||
<!-- Множественный выбор -->
|
||||
<div v-else>
|
||||
<p class="text-subtitle-1 text-grey-darken-1 mb-4">Возможно несколько верных ответов</p>
|
||||
<v-checkbox
|
||||
v-for="(option, index) in question.answers"
|
||||
:key="index"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<v-card v-if="testFinished" class="mt-4 pa-4 results-card" flat>
|
||||
<v-card-title class="text-h5 font-weight-bold text-center mb-6">
|
||||
<v-card-title v-if="!hideTitle" class="text-h5 font-weight-bold text-center mb-6">
|
||||
Результаты тестирования
|
||||
</v-card-title>
|
||||
|
||||
@@ -120,6 +120,10 @@ import { useRoute } from 'vue-router';
|
||||
export default {
|
||||
emits: ['restart'],
|
||||
props: {
|
||||
hideTitle: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
testFinished: Boolean,
|
||||
testPassed: Boolean,
|
||||
correctAnswers: Number,
|
||||
|
||||
@@ -425,6 +425,12 @@ export default {
|
||||
const errorMessage = ref('');
|
||||
|
||||
const validateAnswers = () => {
|
||||
if (props.isTest) {
|
||||
return form.value.questions.some((question) => {
|
||||
const hasCorrectAnswer = question.answers.some(answer => answer.right_wrong);
|
||||
return !hasCorrectAnswer || question.answers.some(answer => !answer.text || answer.text.trim() === '');
|
||||
});
|
||||
}
|
||||
return form.value.questions.some((question) => {
|
||||
if (question.settings.choice === 'free') {
|
||||
return question.answers.some((answer) => !answer.text || answer.text.trim() === '');
|
||||
@@ -436,6 +442,15 @@ export default {
|
||||
const saveVoting = async () => {
|
||||
try {
|
||||
if (props.isTest) {
|
||||
const invalidQuestions = form.value.questions.filter(question =>
|
||||
!question.answers.some(answer => answer.right_wrong)
|
||||
);
|
||||
|
||||
if (invalidQuestions.length > 0) {
|
||||
alert('Каждый вопрос должен иметь хотя бы один правильный ответ');
|
||||
return;
|
||||
}
|
||||
|
||||
const testData = {
|
||||
name: form.value.title,
|
||||
description: form.value.description,
|
||||
|
||||
@@ -164,22 +164,22 @@
|
||||
<v-spacer></v-spacer>
|
||||
<v-btn icon="mdi-close" variant="text" @click="showResultsDialog = false" color="white"></v-btn>
|
||||
</v-card-title>
|
||||
<v-card-text class="pa-4">
|
||||
<TestResults
|
||||
v-if="testResults"
|
||||
:testFinished="true"
|
||||
:testPassed="testResults.passed"
|
||||
:correctAnswers="testResults.correct_answers"
|
||||
:answeredQuestions="testResults.total_answers"
|
||||
:totalQuestions="testResults.total_questions"
|
||||
:formattedTime="testResults.time_spent"
|
||||
:questions="testResults.questions"
|
||||
:userAnswers="testResults.user_answers"
|
||||
/>
|
||||
<v-card-text class="pa-4"> <TestResults
|
||||
v-if="testResults"
|
||||
:hideTitle="true"
|
||||
:testFinished="true"
|
||||
:testPassed="testResults.passed"
|
||||
:correctAnswers="testResults.correct_answers"
|
||||
:answeredQuestions="testResults.total_answers"
|
||||
:totalQuestions="testResults.total_questions"
|
||||
:formattedTime="testResults.time_spent"
|
||||
:questions="testResults.questions"
|
||||
:userAnswers="testResults.user_answers"
|
||||
/>
|
||||
</v-card-text>
|
||||
</v-card>
|
||||
</v-dialog>
|
||||
</v-container>
|
||||
</v-container>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
@@ -350,22 +350,19 @@ export default {
|
||||
}
|
||||
};
|
||||
|
||||
// Начать прохождение теста
|
||||
const startTest = (id) => {
|
||||
router.push(`/test/testdetail/${id}?mode=exam`);
|
||||
};
|
||||
|
||||
// Показать результаты теста
|
||||
const showResults = async (id) => {
|
||||
try {
|
||||
const response = await axiosApiInstance.get(`/api/tests/testdetail/${id}/`);
|
||||
|
||||
// Преобразуем данные теста в формат, ожидаемый компонентом TestResults
|
||||
testResults.value = {
|
||||
passed: true, // В данном случае всегда true, так как это завершенный тест
|
||||
passed: true,
|
||||
total_questions: response.data.question_count,
|
||||
total_answers: response.data.question_count, // В завершенном тесте все ответы даны
|
||||
correct_answers: Math.ceil((response.data.pass_perc / 100) * response.data.question_count), // Минимальное количество правильных ответов для прохождения
|
||||
total_answers: response.data.question_count,
|
||||
correct_answers: Math.ceil((response.data.pass_perc / 100) * response.data.question_count),
|
||||
time_spent: `${response.data.time} мин`,
|
||||
questions: response.data.questions,
|
||||
user_answers: response.data.questions.map(q =>
|
||||
@@ -380,11 +377,6 @@ export default {
|
||||
}
|
||||
};
|
||||
|
||||
// Попытка пересдачи теста
|
||||
const retryTest = (id) => {
|
||||
router.push(`/test/testdetail/${id}?mode=retry`);
|
||||
};
|
||||
|
||||
return {
|
||||
activeTab,
|
||||
tabs,
|
||||
|
||||
Reference in new issue
Block a user