fix [P-256]: фикс обновления теста
This commit is contained in:
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">
|
||||
<v-icon icon="mdi-refresh" color="teal-darken-2" class="mr-2" />
|
||||
<span class="text-body-1">
|
||||
<strong>Количество попыток:</strong> {{ data?.attemps_number }}
|
||||
<strong>Количество попыток:</strong> {{ remainingAttempts !== undefined ? remainingAttempts : data?.attemps_number }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@@ -50,12 +50,22 @@
|
||||
</v-card-text>
|
||||
<v-card-actions v-if="!isDialog" class="mx-2 my-4">
|
||||
<v-btn
|
||||
v-if="remainingAttempts === undefined || remainingAttempts > 0"
|
||||
color="btn_text"
|
||||
class="ml-auto px-9 text-white"
|
||||
@click="startTest"
|
||||
>
|
||||
{{ isExamMode ? 'Начать' : 'Тренироваться' }}
|
||||
</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>
|
||||
</v-col>
|
||||
@@ -75,6 +85,10 @@ export default {
|
||||
isDialog: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
remainingAttempts: {
|
||||
type: Number,
|
||||
default: undefined
|
||||
}
|
||||
},
|
||||
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
|
||||
@@ -65,7 +65,7 @@ import HeaderDetailTesting from '@/components/testing/HeaderDetailTesting.vue';
|
||||
import BodyDetailTesting from '@/components/testing/BodyDetailTesting.vue';
|
||||
import QuestionBlock from '@/components/testing/QuestionBlock.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';
|
||||
|
||||
export default {
|
||||
@@ -82,6 +82,7 @@ export default {
|
||||
const testingId = ref(null);
|
||||
const testResults = ref(null);
|
||||
const spentTime = ref(0);
|
||||
const remainingAttempts = ref(undefined);
|
||||
|
||||
const formatSpentTime = computed(() => {
|
||||
const minutes = Math.floor(spentTime.value / 60);
|
||||
@@ -90,10 +91,23 @@ export default {
|
||||
});
|
||||
|
||||
const getTestById = async (id) => {
|
||||
// Загружаем детали теста из API testdetail
|
||||
const resp = await axiosApiInstance.get(`/api/tests/testdetail/${id}`);
|
||||
data.value = resp.data;
|
||||
|
||||
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 userTestings = testingResp.data;
|
||||
if (userTestings?.length > 0) {
|
||||
@@ -133,6 +147,12 @@ export default {
|
||||
const startTest = async () => {
|
||||
await getTestById(testId);
|
||||
|
||||
// Проверяем, есть ли оставшиеся попытки
|
||||
if (remainingAttempts.value !== undefined && remainingAttempts.value <= 0) {
|
||||
console.log('Нет оставшихся попыток для прохождения теста');
|
||||
return; // Прерываем запуск теста если попыток не осталось
|
||||
}
|
||||
|
||||
testStarted.value = true;
|
||||
testFinished.value = false;
|
||||
|
||||
@@ -274,6 +294,7 @@ export default {
|
||||
answeredQuestions,
|
||||
testPassed,
|
||||
data,
|
||||
remainingAttempts,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
@@ -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 {
|
||||
axiosApiInstance,
|
||||
@@ -392,4 +404,5 @@ export {
|
||||
assignTestToUser,
|
||||
getTestToUser,
|
||||
deleteTestingRecord,
|
||||
getActiveTest,
|
||||
}
|
||||
Reference in new issue
Block a user