feat [P-227]: подсветка верных и неверных ответов в тренировке

This commit is contained in:
Denis Voinovich committed 2025-05-28 12:10:07 +03:00
1 parent 0d0e287eba
commit dd05c76646
1 file changed
+55 -4
@@ -16,9 +16,23 @@
<!-- Одиночный выбор -->
<v-radio-group v-if="!isMultipleChoice" v-model="answers[currentQuestion]">
<v-radio v-for="(option, index) in question.answers" :key="index" :value="option.name">
<v-radio
v-for="(option, index) in question.answers"
:key="index"
:value="option.name"
:color="isPracticeMode && answers[currentQuestion] ? (option.right_wrong ? 'success' : 'error') : undefined"
:class="{
'font-weight-bold': answers[currentQuestion] === option.name && isPracticeMode
}"
>
<template v-slot:label>
<div class="text-center">
<div
class="text-center"
:class="{
'text-success': isPracticeMode && answers[currentQuestion] && option.right_wrong,
'text-error': isPracticeMode && answers[currentQuestion] && !option.right_wrong
}"
>
<v-img
v-if="option.file"
:src="`http://127.0.0.1:8000${option.file}`"
@@ -39,10 +53,20 @@
:key="index"
v-model="answers[currentQuestion]"
:value="option.name"
style="margin-bottom: -25px"
:color="shouldShowMultipleChoiceFeedback ? (option.right_wrong ? 'success' : 'error') : undefined"
:class="{
'font-weight-bold': answers[currentQuestion]?.includes(option.name) && isPracticeMode && shouldShowMultipleChoiceFeedback,
'mb-n6': true
}"
>
<template v-slot:label>
<div class="text-center">
<div
class="text-center"
:class="{
'text-success': isPracticeMode && shouldShowMultipleChoiceFeedback && option.right_wrong,
'text-error': isPracticeMode && shouldShowMultipleChoiceFeedback && !option.right_wrong
}"
>
<v-img
v-if="option.file"
:src="`http://127.0.0.1:8000${option.file}`"
@@ -86,6 +110,7 @@
<script>
import { computed, watch } from 'vue';
import { useRoute } from 'vue-router';
export default {
props: {
@@ -96,10 +121,24 @@ export default {
answers: Array,
},
setup(props) {
const route = useRoute();
const isPracticeMode = computed(() => !route.query.mode || route.query.mode === 'practice');
const isMultipleChoice = computed(() => {
return props.question.answers.filter(answer => answer.right_wrong).length > 1;
});
const correctAnswersCount = computed(() => {
return props.question.answers.filter(answer => answer.right_wrong).length;
});
const shouldShowMultipleChoiceFeedback = computed(() => {
if (!isPracticeMode.value || !isMultipleChoice.value || !props.answers[props.currentQuestion]) {
return false;
}
return props.answers[props.currentQuestion].length === correctAnswersCount.value;
});
watch(
() => props.currentQuestion,
(newVal) => {
@@ -112,8 +151,20 @@ export default {
return {
isMultipleChoice,
isPracticeMode,
shouldShowMultipleChoiceFeedback
};
},
emits: ['change-question'],
};
</script>
<style scoped>
.text-success {
color: #4CAF50 !important;
}
.text-error {
color: #FF5252 !important;
}
</style>