refactor [P-36]: страница конкретного теста

This commit is contained in:
Denzel committed 2025-02-19 12:10:30 +03:00
1 parent aed9a39a2f
commit a33f64835f
4 files changed
+40 -36

No files matched your search

+1 -1
View File
@@ -4,4 +4,4 @@ module.exports = {
node: true,
},
extends: ['plugin:vue/vue3-essential', 'eslint:recommended', 'plugin:storybook/recommended'],
}
};
@@ -58,14 +58,11 @@ import QuestionBlock from '@/components/testing/QuestionBlock.vue';
import TestResults from '@/components/testing/TestResults.vue';
import { axiosApiInstance } from '@/utils/axios-api';
import { useRoute } from 'vue-router';
import { useAccountStore } from '../../store/AccountStore';
// import fernet from 'fernet';
export default {
components: { BodyDetailTesting, HeaderDetailTesting, QuestionBlock, TestResults },
setup() {
const route = useRoute();
const accountStore = useAccountStore();
const testId = route.params.id;
const testStarted = ref(false);
const testFinished = ref(false);
@@ -77,38 +74,9 @@ export default {
const getTestById = async (id) => {
const resp = await axiosApiInstance.get(`/api/tests/testdetail/${id}`);
data.value = resp.data;
console.log(data.value);
// console.log(data.value);
};
// const userLogin = accountStore.user;
// const encryptedData =
// 'gAAAAABntEv1Gi_kxhY4EJTyxFetzeiNaE5uu4w43lzljCw9_2xJzLkFM7Gj08cS5eZ0ULw_s_eLAI_Jxf2nVYh_fK4Z5EAhVA==';
//
// async function decryptData(encryptedData, userLogin) {
// const encoder = new TextEncoder();
// const userKeyBuffer = await crypto.subtle.digest('SHA-256', encoder.encode(userLogin));
//
// // Конвертация ArrayBuffer в Base64
// const userKeyArray = Array.from(new Uint8Array(userKeyBuffer));
// const base64Key = btoa(String.fromCharCode(...userKeyArray));
//
// // Создаём секретный ключ
// const secret = new fernet.Secret(base64Key);
//
// // Расшифровываем данные
// const token = new fernet.Token({
// secret: secret,
// token: encryptedData,
// ttl: 0,
// });
//
// return token.decode();
// }
//
// decryptData(encryptedData, userLogin)
// .then((decrypted) => console.log('Расшифрованное значение:', decrypted))
// .catch((err) => console.error('Ошибка расшифровки:', err));
const formattedTime = computed(() => {
if (!data.value?.time) return '00:00';
@@ -148,7 +116,7 @@ export default {
const answers = ref([]);
watch(data?.questions, (newData) => {
watch(data.value?.questions, (newData) => {
if (newData && Array.isArray(newData.questions)) {
answers.value = newData.questions.map(() => null);
}
@@ -1,3 +1,4 @@
/* eslint-disable vue/no-mutating-props */
<template>
<v-card class="mt-4 w-75 mx-auto d-flex flex-lg-column" style="min-height: 350px">
<v-card-title class="text-h6 font-weight-bold">
@@ -10,7 +11,9 @@
:src="`http://127.0.0.1:8000${question.file}`"
class="w-50 mx-auto"
/>
<v-radio-group v-model="answers[currentQuestion]">
<!-- Одиночный выбор -->
<v-radio-group v-if="!isMultipleChoice" v-model="answers[currentQuestion]">
<v-radio
v-for="(option, index) in question.answers"
:key="index"
@@ -18,6 +21,17 @@
:value="option.name"
/>
</v-radio-group>
<!-- Множественный выбор -->
<div v-else>
<v-checkbox
v-for="(option, index) in question.answers"
:key="index"
v-model="answers[currentQuestion]"
:label="option.name"
:value="option.name"
/>
</div>
</v-card-text>
<v-card-actions class="d-flex">
<v-btn
@@ -48,6 +62,8 @@
</template>
<script>
import { computed, watch } from 'vue';
export default {
props: {
question: Object,
@@ -56,6 +72,25 @@ export default {
finishTest: Function,
answers: Array,
},
setup(props) {
// Определяем, является ли вопрос с множественным выбором
const isMultipleChoice = computed(() => props.question.settings?.multiply === 'true');
// Следим за изменением текущего вопроса и создаем пустой массив, если множественный выбор
watch(
() => props.currentQuestion,
(newVal) => {
if (isMultipleChoice.value && !Array.isArray(props.answers[newVal])) {
props.answers[newVal] = [];
}
},
{ immediate: true }, // Устанавливаем сразу при инициализации
);
return {
isMultipleChoice,
};
},
emits: ['change-question'],
};
</script>