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