refactor [P-36]: страница конкретного теста
This commit is contained in:
1 parent
aed9a39a2f
commit
a33f64835f
4 files changed
+40
-36
No files matched your search
@@ -13,6 +13,7 @@ export default [
|
|||||||
{
|
{
|
||||||
rules: {
|
rules: {
|
||||||
'no-console': 'error',
|
'no-console': 'error',
|
||||||
|
'vue/no-mutating-props': 'off',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@@ -4,4 +4,4 @@ module.exports = {
|
|||||||
node: true,
|
node: true,
|
||||||
},
|
},
|
||||||
extends: ['plugin:vue/vue3-essential', 'eslint:recommended', 'plugin:storybook/recommended'],
|
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 TestResults from '@/components/testing/TestResults.vue';
|
||||||
import { axiosApiInstance } from '@/utils/axios-api';
|
import { axiosApiInstance } from '@/utils/axios-api';
|
||||||
import { useRoute } from 'vue-router';
|
import { useRoute } from 'vue-router';
|
||||||
import { useAccountStore } from '../../store/AccountStore';
|
|
||||||
// import fernet from 'fernet';
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: { BodyDetailTesting, HeaderDetailTesting, QuestionBlock, TestResults },
|
components: { BodyDetailTesting, HeaderDetailTesting, QuestionBlock, TestResults },
|
||||||
setup() {
|
setup() {
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const accountStore = useAccountStore();
|
|
||||||
const testId = route.params.id;
|
const testId = route.params.id;
|
||||||
const testStarted = ref(false);
|
const testStarted = ref(false);
|
||||||
const testFinished = ref(false);
|
const testFinished = ref(false);
|
||||||
@@ -77,38 +74,9 @@ export default {
|
|||||||
const getTestById = async (id) => {
|
const getTestById = async (id) => {
|
||||||
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;
|
||||||
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(() => {
|
const formattedTime = computed(() => {
|
||||||
if (!data.value?.time) return '00:00';
|
if (!data.value?.time) return '00:00';
|
||||||
|
|
||||||
@@ -148,7 +116,7 @@ export default {
|
|||||||
|
|
||||||
const answers = ref([]);
|
const answers = ref([]);
|
||||||
|
|
||||||
watch(data?.questions, (newData) => {
|
watch(data.value?.questions, (newData) => {
|
||||||
if (newData && Array.isArray(newData.questions)) {
|
if (newData && Array.isArray(newData.questions)) {
|
||||||
answers.value = newData.questions.map(() => null);
|
answers.value = newData.questions.map(() => null);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
/* eslint-disable vue/no-mutating-props */
|
||||||
<template>
|
<template>
|
||||||
<v-card class="mt-4 w-75 mx-auto d-flex flex-lg-column" style="min-height: 350px">
|
<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">
|
<v-card-title class="text-h6 font-weight-bold">
|
||||||
@@ -10,7 +11,9 @@
|
|||||||
:src="`http://127.0.0.1:8000${question.file}`"
|
:src="`http://127.0.0.1:8000${question.file}`"
|
||||||
class="w-50 mx-auto"
|
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-radio
|
||||||
v-for="(option, index) in question.answers"
|
v-for="(option, index) in question.answers"
|
||||||
:key="index"
|
:key="index"
|
||||||
@@ -18,6 +21,17 @@
|
|||||||
:value="option.name"
|
:value="option.name"
|
||||||
/>
|
/>
|
||||||
</v-radio-group>
|
</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-text>
|
||||||
<v-card-actions class="d-flex">
|
<v-card-actions class="d-flex">
|
||||||
<v-btn
|
<v-btn
|
||||||
@@ -48,6 +62,8 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { computed, watch } from 'vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
question: Object,
|
question: Object,
|
||||||
@@ -56,6 +72,25 @@ export default {
|
|||||||
finishTest: Function,
|
finishTest: Function,
|
||||||
answers: Array,
|
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'],
|
emits: ['change-question'],
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
Reference in new issue
Block a user