feat [P-227]: картинка для теста
This commit is contained in:
1 parent
c68af12398
commit
765ebc481b
5 files changed
+198
-17
No files matched your search
@@ -35,7 +35,15 @@
|
||||
hide-details
|
||||
label="Картинка"
|
||||
variant="outlined"
|
||||
@update:model-value="() => previewAnswerImage(answer, aIndex)"
|
||||
></v-file-input>
|
||||
|
||||
<!-- Превью изображения ответа, если оно загружено -->
|
||||
<div v-if="answer.imagePreview" class="ml-2">
|
||||
<v-avatar size="32">
|
||||
<v-img :src="answer.imagePreview" alt="Превью"></v-img>
|
||||
</v-avatar>
|
||||
</div>
|
||||
|
||||
<v-btn
|
||||
class="ms-1"
|
||||
@@ -94,10 +102,32 @@ export default {
|
||||
// Используем right_wrong для тестов (совместимо с бэкендом)
|
||||
answer.right_wrong = !answer.right_wrong;
|
||||
};
|
||||
|
||||
// Функция для предпросмотра изображения ответа
|
||||
const previewAnswerImage = (answer, index) => {
|
||||
if (answer.image) {
|
||||
const reader = new FileReader();
|
||||
reader.onload = (e) => {
|
||||
// Vue не всегда реактивно отслеживает новые свойства,
|
||||
// поэтому используем явную установку свойства
|
||||
if (!answer.hasOwnProperty('imagePreview')) {
|
||||
answer.imagePreview = e.target.result;
|
||||
} else {
|
||||
answer.imagePreview = e.target.result;
|
||||
}
|
||||
};
|
||||
reader.readAsDataURL(answer.image);
|
||||
} else {
|
||||
if (answer.hasOwnProperty('imagePreview')) {
|
||||
answer.imagePreview = null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
isTestRoute,
|
||||
toggleCorrect,
|
||||
previewAnswerImage,
|
||||
isTest: props.isTest
|
||||
};
|
||||
}
|
||||
|
||||
@@ -4,13 +4,24 @@
|
||||
<QuestionHeader :question="question" :rules="rules" :index="index" :removeQuestion="removeQuestion" />
|
||||
|
||||
<!-- Загрузка изображения для вопроса -->
|
||||
<v-file-input
|
||||
v-model="question.image"
|
||||
accept="image/*"
|
||||
density="comfortable"
|
||||
label="Картинка для вопроса"
|
||||
variant="outlined"
|
||||
></v-file-input>
|
||||
<div class="d-flex align-center">
|
||||
<v-file-input
|
||||
v-model="question.image"
|
||||
accept="image/*"
|
||||
density="comfortable"
|
||||
label="Картинка для вопроса"
|
||||
variant="outlined"
|
||||
class="flex-grow-1"
|
||||
@update:model-value="previewQuestionImage"
|
||||
></v-file-input>
|
||||
|
||||
<!-- Превью изображения вопроса, если оно загружено -->
|
||||
<div v-if="questionImagePreview" class="ml-3">
|
||||
<v-avatar size="40" class="ml-2">
|
||||
<v-img :src="questionImagePreview" alt="Превью вопроса"></v-img>
|
||||
</v-avatar>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<v-divider></v-divider>
|
||||
|
||||
@@ -145,7 +156,7 @@
|
||||
import QuestionHeader from '@/components/vote/ConstructorVote/QuestionHeader.vue';
|
||||
import QuestionSettings from '@/components/vote/ConstructorVote/QuestionSettings.vue';
|
||||
import AnswerList from '@/components/vote/ConstructorVote/AnswerList.vue';
|
||||
import { computed } from 'vue';
|
||||
import { computed, ref } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
|
||||
export default {
|
||||
@@ -212,11 +223,25 @@ export default {
|
||||
emits: ['update:question'],
|
||||
setup(props, { emit }) {
|
||||
const route = useRoute();
|
||||
const questionImagePreview = ref(null);
|
||||
|
||||
const resetAnswers = () => {
|
||||
props.question.answers = [];
|
||||
emit('update:question', props.question);
|
||||
};
|
||||
|
||||
// Функция предпросмотра изображения вопроса
|
||||
const previewQuestionImage = () => {
|
||||
if (props.question.image) {
|
||||
const reader = new FileReader();
|
||||
reader.onload = (e) => {
|
||||
questionImagePreview.value = e.target.result;
|
||||
};
|
||||
reader.readAsDataURL(props.question.image);
|
||||
} else {
|
||||
questionImagePreview.value = null;
|
||||
}
|
||||
};
|
||||
|
||||
const addAnswer = () => {
|
||||
props.question.answers.push({ text: '', image: null });
|
||||
@@ -263,7 +288,9 @@ export default {
|
||||
toggleSelectAll,
|
||||
removeEmployeeAnswer,
|
||||
onEmployeesChange,
|
||||
isTestRoute
|
||||
isTestRoute,
|
||||
questionImagePreview,
|
||||
previewQuestionImage
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
@@ -6,8 +6,7 @@
|
||||
</v-btn>
|
||||
</CreatedVote>
|
||||
<template v-else>
|
||||
<div class="v-col flex-grow-1 flex-shrink-0">
|
||||
<v-stepper v-model="step" class="d-flex flex-column fill-height" editable>
|
||||
<div class="v-col flex-grow-1" ><v-stepper v-model="step" class="d-flex flex-column fill-height" editable>
|
||||
<v-stepper-header class="flex-grow-0 flex-shrink-1">
|
||||
<v-stepper-item :complete="step > 0" step="1">Основная информация</v-stepper-item>
|
||||
<v-divider></v-divider>
|
||||
@@ -63,6 +62,38 @@
|
||||
class="ml-2"
|
||||
></v-text-field>
|
||||
</div>
|
||||
|
||||
<!-- Загрузка основного изображения теста -->
|
||||
<div class="mt-4">
|
||||
<v-file-input
|
||||
v-model="testImage"
|
||||
accept="image/*"
|
||||
density="comfortable"
|
||||
label="Изображение теста"
|
||||
variant="outlined"
|
||||
prepend-icon="mdi-image"
|
||||
placeholder="Выберите изображение для теста"
|
||||
hint="Логотип или изображение для теста"
|
||||
:show-size="true"
|
||||
@update:model-value="previewImage"
|
||||
></v-file-input>
|
||||
|
||||
<!-- Превью изображения -->
|
||||
<div v-if="imagePreview" class="d-flex justify-center mt-3">
|
||||
<v-img
|
||||
:src="imagePreview"
|
||||
max-height="200"
|
||||
max-width="300"
|
||||
contain
|
||||
>
|
||||
<template v-slot:placeholder>
|
||||
<v-row class="fill-height ma-0" align="center" justify="center">
|
||||
<v-progress-circular indeterminate color="grey-lighten-5"></v-progress-circular>
|
||||
</v-row>
|
||||
</template>
|
||||
</v-img>
|
||||
</div>
|
||||
</div>
|
||||
</v-card-text>
|
||||
</template>
|
||||
<v-card-actions>
|
||||
@@ -141,6 +172,29 @@
|
||||
<strong class="px-2">Дата окончания:</strong>
|
||||
{{ form.endDate.toLocaleDateString() }}
|
||||
</p>
|
||||
<!-- Показываем информацию о тесте, если это тест -->
|
||||
<template v-if="isTest">
|
||||
<p><strong class="px-2">Минимальный процент для сдачи:</strong> {{ testSettings.pass_perc }}%</p>
|
||||
<p><strong class="px-2">Время прохождения (мин):</strong> {{ testSettings.time }}</p>
|
||||
<p><strong class="px-2">Количество вопросов:</strong> {{ testSettings.question_count }}</p>
|
||||
<p><strong class="px-2">Количество попыток:</strong> {{ testSettings.attemps_number }}</p>
|
||||
|
||||
<!-- Превью изображения теста на странице подтверждения -->
|
||||
<div class="mt-2 mb-4">
|
||||
<p><strong class="px-2">Изображение теста:</strong></p>
|
||||
<div v-if="imagePreview" class="d-flex justify-center mt-2">
|
||||
<v-img
|
||||
:src="imagePreview"
|
||||
max-height="150"
|
||||
max-width="250"
|
||||
contain
|
||||
class="border rounded"
|
||||
></v-img>
|
||||
</div>
|
||||
<p v-else class="text-grey text-center mt-2">Не выбрано</p>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<p><strong class="px-2">Вопросы:</strong></p>
|
||||
|
||||
<v-card
|
||||
@@ -154,13 +208,44 @@
|
||||
question.type
|
||||
}})
|
||||
</p>
|
||||
<!-- Показываем превью изображения вопроса, если оно есть -->
|
||||
<div v-if="question.image" class="mt-2 mb-2">
|
||||
<img
|
||||
v-if="typeof question.image === 'object' && question.image !== null"
|
||||
:src="getImagePreviewUrl(question.image)"
|
||||
alt="Изображение вопроса"
|
||||
style="max-width: 150px; max-height: 100px; object-fit: contain;"
|
||||
class="ml-3 border-thin"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div v-if="question.settings.choice === 'free' && question.answers.length">
|
||||
<p><strong>Варианты ответов:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li v-for="(answer, answerIndex) in question.answers" :key="answerIndex">
|
||||
{{ answer.text }}
|
||||
<li v-for="(answer, answerIndex) in question.answers" :key="answerIndex" class="mb-2">
|
||||
<div class="d-flex align-center">
|
||||
<span>{{ answer.text }}</span>
|
||||
<!-- Для тестов показываем правильность ответа -->
|
||||
<v-icon
|
||||
v-if="isTest"
|
||||
:color="answer.right_wrong ? 'green' : 'red'"
|
||||
class="ml-2"
|
||||
small
|
||||
>
|
||||
{{ answer.right_wrong ? 'mdi-check-circle' : 'mdi-close-circle' }}
|
||||
</v-icon>
|
||||
<!-- Показываем превью изображения ответа, если оно есть -->
|
||||
<div v-if="answer.image" class="ml-2">
|
||||
<img
|
||||
v-if="typeof answer.image === 'object' && answer.image !== null"
|
||||
:src="getImagePreviewUrl(answer.image)"
|
||||
alt="Изображение ответа"
|
||||
style="max-width: 100px; max-height: 60px; object-fit: contain;"
|
||||
class="ml-1 border-thin"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
@@ -240,6 +325,9 @@ export default {
|
||||
question_count: '10',
|
||||
attemps_number: '3',
|
||||
});
|
||||
|
||||
const testImage = ref(null); // Для хранения основного изображения теста
|
||||
const imagePreview = ref(null); // Для превью изображения
|
||||
|
||||
const rules = {
|
||||
required: (value) => !!value || 'Это поле обязательно для заполнения',
|
||||
@@ -361,7 +449,7 @@ export default {
|
||||
description: form.value.description,
|
||||
datestart: form.value.startDate,
|
||||
dateend: form.value.endDate,
|
||||
image: null,
|
||||
image: testImage.value, // Используем загруженное изображение теста
|
||||
pass_perc: Number(testSettings.value.pass_perc),
|
||||
time: Number(testSettings.value.time),
|
||||
question_count: Number(testSettings.value.question_count),
|
||||
@@ -391,6 +479,19 @@ export default {
|
||||
}
|
||||
};
|
||||
|
||||
// Функция для предпросмотра загруженного изображения
|
||||
const previewImage = () => {
|
||||
if (testImage.value) {
|
||||
const reader = new FileReader();
|
||||
reader.onload = (e) => {
|
||||
imagePreview.value = e.target.result;
|
||||
};
|
||||
reader.readAsDataURL(testImage.value);
|
||||
} else {
|
||||
imagePreview.value = null;
|
||||
}
|
||||
};
|
||||
|
||||
const resetForm = () => {
|
||||
form.value = {
|
||||
title: '',
|
||||
@@ -407,6 +508,8 @@ export default {
|
||||
question_count: '10',
|
||||
attemps_number: '3',
|
||||
};
|
||||
testImage.value = null;
|
||||
imagePreview.value = null;
|
||||
step.value = 0;
|
||||
isVoteCreated.value = false;
|
||||
};
|
||||
@@ -463,10 +566,27 @@ export default {
|
||||
|
||||
const quests = computed(() => form.value.questions.map((question) => question.text.length > 0));
|
||||
|
||||
// Функция для получения URL превью изображения для объектов File
|
||||
const getImagePreviewUrl = (file) => {
|
||||
if (file instanceof File) {
|
||||
// Если у нас уже есть кэшированный URL для этого файла, вернем его
|
||||
if (!file._cachedUrl) {
|
||||
file._cachedUrl = URL.createObjectURL(file);
|
||||
}
|
||||
return file._cachedUrl;
|
||||
}
|
||||
return '';
|
||||
};
|
||||
|
||||
// Добавляем начальный вопрос при монтировании компонента, если мы в режиме теста
|
||||
if (props.isTest && form.value.questions.length === 0) {
|
||||
addQuestion();
|
||||
}
|
||||
|
||||
// Автоматически обновляем превью при смене testImage
|
||||
watch(testImage, () => {
|
||||
previewImage();
|
||||
});
|
||||
|
||||
return {
|
||||
quests,
|
||||
@@ -489,6 +609,10 @@ export default {
|
||||
handleSelectAll,
|
||||
isAllSelected,
|
||||
testSettings,
|
||||
testImage,
|
||||
imagePreview,
|
||||
previewImage,
|
||||
getImagePreviewUrl,
|
||||
isTest: props.isTest
|
||||
};
|
||||
},
|
||||
|
||||
@@ -203,6 +203,7 @@ async function createTest(testData) {
|
||||
try {
|
||||
const formData = new FormData();
|
||||
|
||||
// Добавляем основное изображение теста, если есть
|
||||
if (testData.image) {
|
||||
formData.append('image', testData.image);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user