fix [P-256]: фикс обновления теста

This commit is contained in:
Denis Voinovich committed 2025-06-04 14:56:02 +03:00
1 parent 59ee774aeb
commit 68487575e5
3 files changed
+51 -3

No files matched your search

@@ -36,7 +36,7 @@
<div class="d-flex align-center mb-3"> <div class="d-flex align-center mb-3">
<v-icon icon="mdi-refresh" color="teal-darken-2" class="mr-2" /> <v-icon icon="mdi-refresh" color="teal-darken-2" class="mr-2" />
<span class="text-body-1"> <span class="text-body-1">
<strong>Количество попыток:</strong> {{ data?.attemps_number }} <strong>Количество попыток:</strong> {{ remainingAttempts !== undefined ? remainingAttempts : data?.attemps_number }}
</span> </span>
</div> </div>
@@ -50,12 +50,22 @@
</v-card-text> </v-card-text>
<v-card-actions v-if="!isDialog" class="mx-2 my-4"> <v-card-actions v-if="!isDialog" class="mx-2 my-4">
<v-btn <v-btn
v-if="remainingAttempts === undefined || remainingAttempts > 0"
color="btn_text" color="btn_text"
class="ml-auto px-9 text-white" class="ml-auto px-9 text-white"
@click="startTest" @click="startTest"
> >
{{ isExamMode ? 'Начать' : 'Тренироваться' }} {{ isExamMode ? 'Начать' : 'Тренироваться' }}
</v-btn> </v-btn>
<v-alert
v-else
type="warning"
class="ml-auto my-2 w-100"
border="start"
density="compact"
>
Все попытки израсходованы
</v-alert>
</v-card-actions> </v-card-actions>
</v-card> </v-card>
</v-col> </v-col>
@@ -75,6 +85,10 @@ export default {
isDialog: { isDialog: {
type: Boolean, type: Boolean,
default: false default: false
},
remainingAttempts: {
type: Number,
default: undefined
} }
}, },
setup(props) { setup(props) {
@@ -12,7 +12,7 @@
/> />
<!-- Блок информации о тесте --> <!-- Блок информации о тесте -->
<BodyDetailTesting v-if="!testStarted && !testFinished" :data="data" :startTest="startTest" /> <BodyDetailTesting v-if="!testStarted && !testFinished" :data="data" :startTest="startTest" :remainingAttempts="remainingAttempts" />
<!-- Вопросы теста --> <!-- Вопросы теста -->
<QuestionBlock <QuestionBlock
@@ -65,7 +65,7 @@ import HeaderDetailTesting from '@/components/testing/HeaderDetailTesting.vue';
import BodyDetailTesting from '@/components/testing/BodyDetailTesting.vue'; import BodyDetailTesting from '@/components/testing/BodyDetailTesting.vue';
import QuestionBlock from '@/components/testing/QuestionBlock.vue'; import QuestionBlock from '@/components/testing/QuestionBlock.vue';
import TestResults from '@/components/testing/TestResults.vue'; import TestResults from '@/components/testing/TestResults.vue';
import { axiosApiInstance } from '@/utils/axios-api'; import { axiosApiInstance, getActiveTest } from '@/utils/axios-api';
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
export default { export default {
@@ -82,6 +82,7 @@ export default {
const testingId = ref(null); const testingId = ref(null);
const testResults = ref(null); const testResults = ref(null);
const spentTime = ref(0); const spentTime = ref(0);
const remainingAttempts = ref(undefined);
const formatSpentTime = computed(() => { const formatSpentTime = computed(() => {
const minutes = Math.floor(spentTime.value / 60); const minutes = Math.floor(spentTime.value / 60);
@@ -90,10 +91,23 @@ export default {
}); });
const getTestById = async (id) => { const getTestById = async (id) => {
// Загружаем детали теста из API testdetail
const resp = await axiosApiInstance.get(`/api/tests/testdetail/${id}`); const resp = await axiosApiInstance.get(`/api/tests/testdetail/${id}`);
data.value = resp.data; data.value = resp.data;
try { try {
// Проверяем оставшиеся попытки из API gettests со статусом active
const activeTest = await getActiveTest(id);
// Если нашли тест в активных, проверяем количество попыток
if (activeTest) {
remainingAttempts.value = activeTest.attemps_number;
} else {
// Если тест не найден в активных, устанавливаем 0 попыток
remainingAttempts.value = 0;
}
// Получаем данные о назначениях теста
const testingResp = await axiosApiInstance.get(`/api/tests/testingview/?test_id=${id}`); const testingResp = await axiosApiInstance.get(`/api/tests/testingview/?test_id=${id}`);
const userTestings = testingResp.data; const userTestings = testingResp.data;
if (userTestings?.length > 0) { if (userTestings?.length > 0) {
@@ -133,6 +147,12 @@ export default {
const startTest = async () => { const startTest = async () => {
await getTestById(testId); await getTestById(testId);
// Проверяем, есть ли оставшиеся попытки
if (remainingAttempts.value !== undefined && remainingAttempts.value <= 0) {
console.log('Нет оставшихся попыток для прохождения теста');
return; // Прерываем запуск теста если попыток не осталось
}
testStarted.value = true; testStarted.value = true;
testFinished.value = false; testFinished.value = false;
@@ -274,6 +294,7 @@ export default {
answeredQuestions, answeredQuestions,
testPassed, testPassed,
data, data,
remainingAttempts,
}; };
}, },
}; };
+13
View File
@@ -368,6 +368,18 @@ async function deleteTestingRecord(testingId) {
} }
} }
async function getActiveTest(id) {
try {
const response = await axiosApiInstance.get(`/api/tests/gettests/?status=active`);
const activeTests = response.data;
const activeTest = activeTests.find(test => test.id === Number(id));
return activeTest || null;
} catch (error) {
console.error("Ошибка получения активного теста:", error);
throw error;
}
}
export { export {
axiosApiInstance, axiosApiInstance,
@@ -392,4 +404,5 @@ export {
assignTestToUser, assignTestToUser,
getTestToUser, getTestToUser,
deleteTestingRecord, deleteTestingRecord,
getActiveTest,
} }