fix [P-227]: результаты тестирования для завершенных тестов
This commit is contained in:
1 parent
a78a21edf9
commit
d456952d6c
2 files changed
+188
-26
No files matched your search
@@ -20,16 +20,17 @@
|
|||||||
<v-col cols="12" sm="4">
|
<v-col cols="12" sm="4">
|
||||||
<v-card
|
<v-card
|
||||||
class="pa-4 text-center result-card"
|
class="pa-4 text-center result-card"
|
||||||
|
:class="{ 'cursor-pointer': isPracticeMode }"
|
||||||
elevation="2"
|
elevation="2"
|
||||||
:color="testPassed ? 'success-light' : 'error-light'"
|
:color="testPassed ? 'success-light' : 'error-light'"
|
||||||
|
@click="isPracticeMode && (showAnswersDialog = true)"
|
||||||
>
|
>
|
||||||
<v-icon size="36" :color="testPassed ? 'success' : 'error'" class="mb-2">
|
<v-icon size="36" :color="testPassed ? 'success' : 'error'" class="mb-2">
|
||||||
mdi-checkbox-marked-circle
|
mdi-checkbox-marked-circle
|
||||||
</v-icon>
|
</v-icon>
|
||||||
<p class="text-h5 mb-1">{{ correctAnswers }}/{{ totalQuestions }}</p>
|
<p class="text-h5 mb-1">{{ correctAnswers }}/{{ totalQuestions }}</p>
|
||||||
<div class="text-body-2">
|
<div class="text-body-2">
|
||||||
Правильных ответов
|
{{ isPracticeMode ? 'Правильных ответов (нажмите чтобы увидеть детали)' : 'Правильных ответов' }}
|
||||||
<v-icon v-if="isPracticeMode" small color="primary">mdi-information</v-icon>
|
|
||||||
</div>
|
</div>
|
||||||
</v-card>
|
</v-card>
|
||||||
</v-col>
|
</v-col>
|
||||||
@@ -51,7 +52,7 @@
|
|||||||
</v-col>
|
</v-col>
|
||||||
</v-row>
|
</v-row>
|
||||||
|
|
||||||
<!-- Модальное окно с правильными ответами отображается только в режиме тренировки -->
|
<!-- Модальное окно с правильными ответами (только для тренировочного режима) -->
|
||||||
<v-dialog v-if="isPracticeMode" v-model="showAnswersDialog" max-width="600">
|
<v-dialog v-if="isPracticeMode" v-model="showAnswersDialog" max-width="600">
|
||||||
<v-card>
|
<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">
|
<v-card-title class="d-flex align-center text-h6 font-weight-bold px-4 py-3 bg-teal-darken-4 text-white">
|
||||||
@@ -68,10 +69,10 @@
|
|||||||
<v-expansion-panel-title>
|
<v-expansion-panel-title>
|
||||||
<div class="d-flex align-center">
|
<div class="d-flex align-center">
|
||||||
<v-icon
|
<v-icon
|
||||||
:color="isQuestionCorrect(index) ? 'success' : 'error'"
|
:color="getQuestionStatusColor(index)"
|
||||||
class="mr-2"
|
class="mr-2"
|
||||||
>
|
>
|
||||||
{{ isQuestionCorrect(index) ? 'mdi-check-circle' : 'mdi-close-circle' }}
|
{{ getQuestionStatusIcon(index) }}
|
||||||
</v-icon>
|
</v-icon>
|
||||||
<span>Вопрос {{ index + 1 }}</span>
|
<span>Вопрос {{ index + 1 }}</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -79,18 +80,32 @@
|
|||||||
<v-expansion-panel-text>
|
<v-expansion-panel-text>
|
||||||
<p class="mb-2 font-weight-bold">{{ question.name }}</p>
|
<p class="mb-2 font-weight-bold">{{ question.name }}</p>
|
||||||
<v-divider class="mb-2"></v-divider>
|
<v-divider class="mb-2"></v-divider>
|
||||||
<div v-for="answer in question.answers" :key="answer.id" class="mb-1">
|
<div v-for="answer in question.answers" :key="answer.id" class="mb-2 d-flex align-center">
|
||||||
<v-icon
|
<v-icon
|
||||||
:color="answer.right_wrong ? 'success' : ''"
|
:color="getAnswerColor(index, answer)"
|
||||||
size="small"
|
size="small"
|
||||||
class="mr-1"
|
class="mr-2"
|
||||||
>
|
>
|
||||||
{{ answer.right_wrong ? 'mdi-check' : 'mdi-minus' }}
|
{{ getAnswerIcon(index, answer) }}
|
||||||
</v-icon>
|
</v-icon>
|
||||||
<span :class="{ 'font-weight-bold': answer.right_wrong }">
|
<span :class="{ 'font-weight-bold': isAnswerCorrect(index, answer) }">
|
||||||
{{ answer.name }}
|
{{ answer.name }}
|
||||||
</span>
|
</span>
|
||||||
<span v-if="answer.right_wrong" class="text-success">(правильный ответ)</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>
|
</div>
|
||||||
</v-expansion-panel-text>
|
</v-expansion-panel-text>
|
||||||
</v-expansion-panel>
|
</v-expansion-panel>
|
||||||
@@ -98,6 +113,19 @@
|
|||||||
</v-card-text>
|
</v-card-text>
|
||||||
</v-card>
|
</v-card>
|
||||||
</v-dialog>
|
</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>
|
</v-card>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -125,6 +153,10 @@ export default {
|
|||||||
userAnswers: {
|
userAnswers: {
|
||||||
type: Array,
|
type: Array,
|
||||||
required: true
|
required: true
|
||||||
|
},
|
||||||
|
fromCompletedTab: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
setup(props) {
|
setup(props) {
|
||||||
@@ -133,25 +165,132 @@ export default {
|
|||||||
|
|
||||||
const isPracticeMode = computed(() => !route.query.mode || route.query.mode === 'practice');
|
const isPracticeMode = computed(() => !route.query.mode || route.query.mode === 'practice');
|
||||||
|
|
||||||
const isQuestionCorrect = (questionIndex) => {
|
const getQuestionStatusColor = (questionIndex) => {
|
||||||
const question = props.questions[questionIndex];
|
if (!props.questions[questionIndex]?.answers) return 'grey';
|
||||||
const userAnswer = props.userAnswers[questionIndex];
|
|
||||||
|
|
||||||
|
if (props.fromCompletedTab) {
|
||||||
|
return 'grey';
|
||||||
|
}
|
||||||
|
|
||||||
|
const hasCorrectAnswers = props.questions[questionIndex].answers.some(a => a.right_wrong === true);
|
||||||
|
return hasCorrectAnswers ? 'success' : 'grey';
|
||||||
|
};
|
||||||
|
|
||||||
|
const getQuestionStatusIcon = (questionIndex) => {
|
||||||
|
if (!props.questions[questionIndex]?.answers) return 'mdi-circle-outline';
|
||||||
|
|
||||||
|
if (props.fromCompletedTab) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
const hasCorrectAnswers = props.questions[questionIndex].answers.some(a => a.right_wrong === true);
|
||||||
|
return hasCorrectAnswers ? 'mdi-check-circle' : 'mdi-circle-outline';
|
||||||
|
};
|
||||||
|
|
||||||
|
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 (!userAnswer) return false;
|
||||||
|
|
||||||
if (Array.isArray(userAnswer)) {
|
if (Array.isArray(userAnswer)) {
|
||||||
const correctAnswers = question.answers.filter(a => a.right_wrong).map(a => a.name);
|
return userAnswer.includes(answerName);
|
||||||
return userAnswer.length === correctAnswers.length &&
|
}
|
||||||
userAnswer.every(answer => correctAnswers.includes(answer));
|
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 question.answers.find(a => a.name === userAnswer)?.right_wrong || false;
|
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 {
|
return {
|
||||||
showAnswersDialog,
|
showAnswersDialog,
|
||||||
isPracticeMode,
|
isPracticeMode,
|
||||||
isQuestionCorrect
|
isQuestionCorrect,
|
||||||
|
hasUserAnswer,
|
||||||
|
showUserAnswer,
|
||||||
|
isAnswerCorrect,
|
||||||
|
getAnswerColor,
|
||||||
|
getAnswerIcon,
|
||||||
|
getQuestionStatusColor,
|
||||||
|
getQuestionStatusIcon
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -175,6 +175,7 @@
|
|||||||
:formattedTime="testResults.time_spent"
|
:formattedTime="testResults.time_spent"
|
||||||
:questions="testResults.questions"
|
:questions="testResults.questions"
|
||||||
:userAnswers="testResults.user_answers"
|
:userAnswers="testResults.user_answers"
|
||||||
|
:fromCompletedTab="testResults.fromCompletedTab"
|
||||||
/>
|
/>
|
||||||
</v-card-text>
|
</v-card-text>
|
||||||
</v-card>
|
</v-card>
|
||||||
@@ -387,14 +388,36 @@ export default {
|
|||||||
axiosApiInstance.get(`/api/tests/testresultview/?id=${id}`)
|
axiosApiInstance.get(`/api/tests/testresultview/?id=${id}`)
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const questions = (testDetailResponse.data.questions || []).map(q => ({
|
||||||
|
...q,
|
||||||
|
answers: (q.answers || []).map(a => ({
|
||||||
|
...a,
|
||||||
|
isUserAnswer: false
|
||||||
|
}))
|
||||||
|
}));
|
||||||
|
|
||||||
|
const userAnswers = questions.map(question => {
|
||||||
|
const userAnswer = resultResponse.data.user_answers?.[question.id];
|
||||||
|
if (!userAnswer) return null;
|
||||||
|
|
||||||
|
question.answers.forEach(answer => {
|
||||||
|
answer.isUserAnswer = Array.isArray(userAnswer)
|
||||||
|
? userAnswer.includes(answer.name)
|
||||||
|
: userAnswer === answer.name;
|
||||||
|
});
|
||||||
|
|
||||||
|
return userAnswer;
|
||||||
|
});
|
||||||
|
|
||||||
testResults.value = {
|
testResults.value = {
|
||||||
passed: resultResponse.data.is_passed,
|
passed: resultResponse.data.is_passed || false,
|
||||||
total_questions: testDetailResponse.data.question_count,
|
total_questions: testDetailResponse.data.question_count || 0,
|
||||||
total_answers: resultResponse.data.answered_questions_total,
|
total_answers: resultResponse.data.answered_questions_total || 0,
|
||||||
correct_answers: resultResponse.data.score,
|
correct_answers: resultResponse.data.score || 0,
|
||||||
time_spent: `${testDetailResponse.data.time} мин`,
|
time_spent: `${testDetailResponse.data.time || 0} мин`,
|
||||||
questions: [],
|
questions: questions,
|
||||||
userAnswers: []
|
userAnswers: userAnswers,
|
||||||
|
fromCompletedTab: activeTab.value === 1
|
||||||
};
|
};
|
||||||
|
|
||||||
showResultsDialog.value = true;
|
showResultsDialog.value = true;
|
||||||
|
|||||||
Reference in new issue
Block a user