fix [P-276]: изменения

This commit is contained in:
Denis Voinovich committed 2025-06-24 14:28:26 +03:00
1 parent 892bf1b1d7
commit a462620999
6 files changed
+149 -70

No files matched your search

@@ -23,6 +23,7 @@
:answers="answers"
:finishTest="openFinishDialog"
@change-question="changeQuestion"
@answer-changed="onAnswerChanged"
/>
<!-- Результаты теста -->
@@ -36,6 +37,7 @@
:formattedTime="formatSpentTime"
:questions="data?.questions"
:userAnswers="answers"
:remainingAttempts="remainingAttempts"
@restart="startTest"
/>
@@ -157,7 +159,11 @@ export default {
testStarted.value = true;
testFinished.value = false;
answers.value = Array(data.value.questions.length).fill(null);
// Правильно инициализируем ответы в зависимости от типа вопроса
answers.value = data.value.questions.map((question) => {
const correctAnswersCount = question.answers.filter(answer => answer.right_wrong).length;
return correctAnswersCount > 1 ? [] : null;
});
const initialTime = data.value.time * 60;
data.value = { ...data.value, time: initialTime };
@@ -169,7 +175,7 @@ export default {
timer = setInterval(() => {
if (data.value?.time > 0) {
data.value = { ...data.value, time: data.value.time - 1 };
data.value.time = data.value.time - 1; // Обновляем только время, а не весь объект
spentTime.value += 1;
} else {
finishTest();
@@ -231,7 +237,12 @@ export default {
() => data.value?.questions,
(newQuestions) => {
if (newQuestions && Array.isArray(newQuestions)) {
answers.value = newQuestions.map(() => null);
if (!answers.value || answers.value.length === 0) {
answers.value = newQuestions.map((question) => {
const correctAnswersCount = question.answers.filter(answer => answer.right_wrong).length;
return correctAnswersCount > 1 ? [] : null;
});
}
}
},
{ deep: true }
@@ -260,7 +271,11 @@ export default {
);
const answeredQuestions = computed(
() => answers.value.filter((answer) => answer !== null).length,
() => answers.value.filter((answer) => {
if (answer === null || answer === undefined) return false;
if (Array.isArray(answer)) return answer.length > 0;
return true;
}).length,
);
const testPassed = computed(() => testResults.value?.is_passed ?? false);
@@ -271,6 +286,13 @@ export default {
}
};
const onAnswerChanged = (questionIndex, value) => {
const newAnswers = [...answers.value];
newAnswers[questionIndex] = value;
answers.value = newAnswers;
};
const openFinishDialog = () => {
showFinishDialog.value = true;
};
@@ -293,6 +315,7 @@ export default {
answers,
currentQuestion,
changeQuestion,
onAnswerChanged,
showFinishDialog,
openFinishDialog,
correctAnswers,
@@ -17,7 +17,7 @@
<!-- Одиночный выбор -->
<v-radio-group
v-if="!isMultipleChoice"
v-model="answers[currentQuestion]"
v-model="currentAnswer"
>
<v-radio
v-for="(option, index) in question.answers"
@@ -48,7 +48,7 @@
<v-checkbox
v-for="(option, index) in question.answers"
:key="index"
v-model="answers[currentQuestion]"
v-model="currentAnswer"
:value="option.name"
class="mb-n6"
>
@@ -97,7 +97,7 @@
</template>
<script>
import { computed, watch } from 'vue';
import { computed } from 'vue';
import { useRoute } from 'vue-router';
import { baseURL } from '@/utils/axios-api';
@@ -109,7 +109,7 @@ export default {
finishTest: Function,
answers: Array,
},
setup(props) {
setup(props, { emit }) {
const route = useRoute();
const isPracticeMode = computed(
() => !route.query.mode || route.query.mode === "practice",
@@ -121,23 +121,24 @@ export default {
);
});
watch(
() => props.currentQuestion,
(newVal) => {
if (isMultipleChoice.value && !Array.isArray(props.answers[newVal])) {
props.answers[newVal] = [];
}
const currentAnswer = computed({
get() {
const answer = props.answers[props.currentQuestion];
return answer;
},
{ immediate: true },
);
set(value) {
emit('answer-changed', props.currentQuestion, value);
}
});
return {
isMultipleChoice,
isPracticeMode,
baseURL
baseURL,
currentAnswer
};
},
emits: ["change-question"],
emits: ["change-question", "answer-changed"],
};
</script>
@@ -168,10 +169,10 @@ export default {
color: rgb(var(--v-theme-text_carous));
}
.v-radio-group :deep(.v-radio:hover),
/* .v-radio-group :deep(.v-radio:hover),
.v-checkbox:hover {
transform: translateX(4px);
}
} */
.v-btn {
text-transform: none;
+103 -48
View File
@@ -17,23 +17,6 @@
</div>
<v-row class="mt-2">
<v-col cols="12" sm="4">
<v-card
class="pa-4 text-center result-card"
:class="{ 'cursor-pointer': isPracticeMode }"
elevation="2"
:color="testPassed ? 'success-light' : 'error-light'"
@click="isPracticeMode && (showAnswersDialog = true)"
>
<v-icon size="36" :color="testPassed ? 'success' : 'error'" class="mb-2">
mdi-checkbox-marked-circle
</v-icon>
<p class="text-h5 mb-1">{{ correctAnswers }}/{{ totalQuestions }}</p>
<div class="text-body-2">
{{ isPracticeMode ? 'Правильных ответов (нажмите чтобы увидеть детали)' : 'Правильных ответов' }}
</div>
</v-card>
</v-col>
<v-col cols="12" sm="4">
<v-card class="pa-4 text-center result-card" elevation="2">
@@ -43,6 +26,24 @@
</v-card>
</v-col>
<v-col cols="12" sm="4">
<v-card
class="pa-4 text-center result-card"
:class="{ 'cursor-pointer': !fromCompletedTab }"
elevation="2"
:color="testPassed ? 'success-light' : 'error-light'"
@click="!fromCompletedTab && (showAnswersDialog = true)"
>
<v-icon size="36" :color="testPassed ? 'success' : 'error'" class="mb-2">
mdi-checkbox-marked-circle
</v-icon>
<p class="text-h5 mb-1">{{ correctAnswers }}/{{ totalQuestions }}</p>
<div class="text-body-2">
{{ !fromCompletedTab ? 'Правильных ответов (нажмите чтобы увидеть детали)' : 'Правильных ответов' }}
</div>
</v-card>
</v-col>
<v-col cols="12" sm="4">
<v-card class="pa-4 text-center result-card" elevation="2">
<v-icon size="36" color="primary" class="mb-2">mdi-clock-outline</v-icon>
@@ -52,11 +53,11 @@
</v-col>
</v-row>
<!-- Модальное окно с правильными ответами (только для тренировочного режима) -->
<v-dialog v-if="isPracticeMode" v-model="showAnswersDialog" max-width="600">
<!-- Модальное окно с правильными ответами -->
<v-dialog v-model="showAnswersDialog" max-width="600">
<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">
<span>Правильные ответы</span>
<span>{{ isPracticeMode ? 'Правильные ответы' : 'Результаты по вопросам' }}</span>
<v-spacer></v-spacer>
<v-btn icon="mdi-close" variant="text" @click="showAnswersDialog = false" color="white"></v-btn>
</v-card-title>
@@ -78,33 +79,46 @@
</div>
</v-expansion-panel-title>
<v-expansion-panel-text>
<p class="mb-2 font-weight-bold">{{ question.name }}</p>
<v-divider class="mb-2"></v-divider>
<div v-for="answer in question.answers" :key="answer.id" class="mb-2 d-flex align-center">
<v-icon
:color="getAnswerColor(index, answer)"
size="small"
class="mr-2"
>
{{ getAnswerIcon(index, answer) }}
</v-icon>
<span :class="{ 'font-weight-bold': isAnswerCorrect(index, answer) }">
{{ answer.name }}
</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">
<p class="mb-4 font-weight-bold">{{ question.name }}</p>
<!-- Показываем варианты ответов только в тренировочном режиме -->
<div v-if="isPracticeMode">
<v-divider class="mb-2"></v-divider>
<div class="text-caption">
{{ isQuestionCorrect(index) ? 'Правильно ✓' : 'Неправильно ✗' }}
<div v-for="answer in question.answers" :key="answer.id" class="mb-2 d-flex align-center">
<v-icon
:color="getAnswerColor(index, answer)"
size="small"
class="mr-2"
>
{{ getAnswerIcon(index, answer) }}
</v-icon>
<span :class="{ 'font-weight-bold': isAnswerCorrect(index, answer) }">
{{ answer.name }}
</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>
<!-- В режиме экзамена показываем только статус ответа -->
<div v-if="hasUserAnswer(index)">
<v-divider v-if="isPracticeMode" class="mb-2"></v-divider>
<div class="text-body-2 font-weight-medium d-flex align-center">
<v-icon
:color="isQuestionCorrect(index) ? 'success' : 'error'"
class="mr-2"
size="small"
>
{{ isQuestionCorrect(index) ? 'mdi-check-circle' : 'mdi-close-circle' }}
</v-icon>
{{ isQuestionCorrect(index) ? 'Правильно' : 'Неправильно' }}
</div>
</div>
</v-expansion-panel-text>
@@ -114,9 +128,10 @@
</v-card>
</v-dialog>
<!-- Кнопка "Попробовать ещё раз" для тренировочного режима -->
<div v-if="isPracticeMode && !fromCompletedTab" class="d-flex justify-center mt-6">
<!-- Кнопка "Попробовать ещё раз" или информационное сообщение -->
<div class="d-flex justify-center mt-6">
<v-btn
v-if="canRetry"
color="teal-darken-1"
@click="$emit('restart')"
class="px-6"
@@ -125,6 +140,16 @@
<v-icon start>mdi-refresh</v-icon>
Попробовать ещё раз
</v-btn>
<v-alert
v-else-if="getRetryMessage"
type="info"
variant="tonal"
class="text-center"
:icon="testPassed ? 'mdi-check-circle' : 'mdi-information'"
>
{{ getRetryMessage }}
</v-alert>
</div>
</v-card>
</template>
@@ -157,6 +182,10 @@ export default {
fromCompletedTab: {
type: Boolean,
default: false
},
remainingAttempts: {
type: Number,
default: undefined
}
},
setup(props) {
@@ -164,6 +193,29 @@ export default {
const showAnswersDialog = ref(false);
const isPracticeMode = computed(() => !route.query.mode || route.query.mode === 'practice');
const isExamMode = computed(() => route.query.mode === 'exam');
const canRetry = computed(() => {
if (props.fromCompletedTab) return false;
if (isPracticeMode.value) return true;
if (isExamMode.value) {
// В режиме экзамена можно повторить только если есть попытки и тест не пройден
return props.remainingAttempts > 0 && !props.testPassed;
}
return true;
});
const getRetryMessage = computed(() => {
if (isExamMode.value && props.remainingAttempts !== undefined) {
if (props.testPassed) {
return 'Тест успешно пройден. Повторное прохождение недоступно.';
}
if (props.remainingAttempts <= 0) {
return 'Нет оставшихся попыток для прохождения теста.';
}
}
return null;
});
const getQuestionStatusColor = (questionIndex) => {
if (!props.questions[questionIndex]?.answers) return 'grey';
@@ -301,6 +353,9 @@ export default {
return {
showAnswersDialog,
isPracticeMode,
isExamMode,
canRetry,
getRetryMessage,
isQuestionCorrect,
hasUserAnswer,
showUserAnswer,