fix [P-227]: убрали даты из конструктора тестов
This commit is contained in:
1 parent
02e7f625a8
commit
47a264202d
4 files changed
+9
-429
No files matched your search
BIN
Binary file not shown.
@@ -1,420 +0,0 @@
|
|||||||
<template>
|
|
||||||
<v-row class="pt-2 mx-1 flex-column fill-height flex-grow-0">
|
|
||||||
<CreatedTest v-if="isTestCreated">
|
|
||||||
<v-btn class="mt-4" color="teal-darken-4" @click="resetForm">Создать ещё</v-btn>
|
|
||||||
</CreatedTest>
|
|
||||||
<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>
|
|
||||||
<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>
|
|
||||||
<v-stepper-item :complete="step > 1" step="2">Создание теста</v-stepper-item>
|
|
||||||
<v-divider></v-divider>
|
|
||||||
<v-stepper-item :complete="step > 2" step="3">Подтверждение</v-stepper-item>
|
|
||||||
</v-stepper-header>
|
|
||||||
|
|
||||||
<v-stepper-window class="fill-height">
|
|
||||||
<!-- Основная информация -->
|
|
||||||
<v-stepper-window-item class="fill-height" step="1">
|
|
||||||
<v-card class="fill-height d-flex flex-column" flat>
|
|
||||||
<v-card-title>Основная информация:</v-card-title>
|
|
||||||
<v-card-text>
|
|
||||||
<v-text-field
|
|
||||||
v-model="form.name"
|
|
||||||
:rules="[rules.required]"
|
|
||||||
label="Название теста"
|
|
||||||
required
|
|
||||||
></v-text-field>
|
|
||||||
<v-textarea
|
|
||||||
v-model="form.description"
|
|
||||||
:rules="[rules.required]"
|
|
||||||
label="Описание теста"
|
|
||||||
required
|
|
||||||
auto-grow
|
|
||||||
></v-textarea>
|
|
||||||
<div class="d-flex">
|
|
||||||
<v-text-field
|
|
||||||
v-model="form.pass_perc"
|
|
||||||
:rules="[rules.required, rules.percent]"
|
|
||||||
label="Минимальный % правильных ответов"
|
|
||||||
type="number"
|
|
||||||
min="0"
|
|
||||||
max="100"
|
|
||||||
required
|
|
||||||
class="mr-2"
|
|
||||||
></v-text-field>
|
|
||||||
<v-text-field
|
|
||||||
v-model="form.time"
|
|
||||||
:rules="[rules.required, rules.positive]"
|
|
||||||
label="Время на прохождение (мин)"
|
|
||||||
type="number"
|
|
||||||
min="1"
|
|
||||||
required
|
|
||||||
class="ml-2"
|
|
||||||
></v-text-field>
|
|
||||||
</div>
|
|
||||||
<div class="d-flex">
|
|
||||||
<v-text-field
|
|
||||||
v-model="form.question_count"
|
|
||||||
:rules="[rules.required, rules.positive]"
|
|
||||||
label="Количество вопросов"
|
|
||||||
type="number"
|
|
||||||
min="1"
|
|
||||||
required
|
|
||||||
class="mr-2"
|
|
||||||
></v-text-field>
|
|
||||||
<v-text-field
|
|
||||||
v-model="form.attemps_number"
|
|
||||||
:rules="[rules.required, rules.positive]"
|
|
||||||
label="Количество попыток"
|
|
||||||
type="number"
|
|
||||||
min="1"
|
|
||||||
required
|
|
||||||
class="ml-2"
|
|
||||||
></v-text-field>
|
|
||||||
</div>
|
|
||||||
<div class="d-flex">
|
|
||||||
<DateSelect v-model="form.datestart" label="Дата начала" class="mr-2" />
|
|
||||||
<DateSelect v-model="form.dateend" label="Дата окончания" class="ml-2" />
|
|
||||||
</div>
|
|
||||||
<v-file-input
|
|
||||||
v-model="form.image"
|
|
||||||
label="Логотип теста"
|
|
||||||
prepend-icon="mdi-camera"
|
|
||||||
accept="image/*"
|
|
||||||
></v-file-input>
|
|
||||||
</v-card-text>
|
|
||||||
<v-card-actions>
|
|
||||||
<v-btn color="teal-darken-4" size="medium" @click="step = 2">Далее</v-btn>
|
|
||||||
</v-card-actions>
|
|
||||||
</v-card>
|
|
||||||
</v-stepper-window-item>
|
|
||||||
|
|
||||||
<!-- Создание теста -->
|
|
||||||
<v-stepper-window-item class="fill-height" step="2">
|
|
||||||
<v-card class="fill-height d-flex flex-column" flat>
|
|
||||||
<v-card-title>Создание вопросов:</v-card-title>
|
|
||||||
<v-card-text style="max-height: 62vh; overflow-y: auto">
|
|
||||||
<div v-for="(question, index) in form.questions" :key="index" class="mb-6 pa-2 border rounded">
|
|
||||||
<v-row>
|
|
||||||
<v-col cols="12">
|
|
||||||
<div class="d-flex justify-space-between align-center">
|
|
||||||
<div class="text-h6">Вопрос {{ index + 1 }}</div>
|
|
||||||
<v-btn icon="mdi-delete" color="red-darken-2" variant="text" @click="removeQuestion(index)"></v-btn>
|
|
||||||
</div>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="12">
|
|
||||||
<v-textarea
|
|
||||||
v-model="question.text"
|
|
||||||
:rules="[rules.required]"
|
|
||||||
label="Текст вопроса"
|
|
||||||
required
|
|
||||||
auto-grow
|
|
||||||
></v-textarea>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="12">
|
|
||||||
<v-file-input
|
|
||||||
v-model="question.image"
|
|
||||||
label="Изображение к вопросу"
|
|
||||||
prepend-icon="mdi-camera"
|
|
||||||
accept="image/*"
|
|
||||||
></v-file-input>
|
|
||||||
</v-col>
|
|
||||||
<v-col cols="12">
|
|
||||||
<div class="text-subtitle-1 mb-2">Варианты ответов:</div>
|
|
||||||
<div v-for="(answer, aIndex) in question.answers" :key="aIndex" class="mb-2">
|
|
||||||
<div class="d-flex align-center">
|
|
||||||
<v-text-field
|
|
||||||
v-model="answer.text"
|
|
||||||
:rules="[rules.required]"
|
|
||||||
label="Ответ"
|
|
||||||
required
|
|
||||||
class="flex-grow-1 mr-2"
|
|
||||||
></v-text-field>
|
|
||||||
<v-checkbox
|
|
||||||
v-model="answer.right_wrong"
|
|
||||||
label="Правильный"
|
|
||||||
class="ml-2"
|
|
||||||
></v-checkbox>
|
|
||||||
<v-btn icon="mdi-delete" color="red" variant="text" @click="removeAnswer(index, aIndex)"></v-btn>
|
|
||||||
</div>
|
|
||||||
<v-file-input
|
|
||||||
v-model="answer.image"
|
|
||||||
label="Изображение к ответу"
|
|
||||||
prepend-icon="mdi-camera"
|
|
||||||
accept="image/*"
|
|
||||||
class="mb-3"
|
|
||||||
></v-file-input>
|
|
||||||
</div>
|
|
||||||
<v-btn
|
|
||||||
color="indigo-lighten-2"
|
|
||||||
size="small"
|
|
||||||
prepend-icon="mdi-plus"
|
|
||||||
@click="addAnswer(index)"
|
|
||||||
>
|
|
||||||
Добавить ответ
|
|
||||||
</v-btn>
|
|
||||||
</v-col>
|
|
||||||
</v-row>
|
|
||||||
</div>
|
|
||||||
<div class="d-flex justify-center">
|
|
||||||
<v-btn
|
|
||||||
color="teal-lighten-2"
|
|
||||||
size="medium"
|
|
||||||
prepend-icon="mdi-plus"
|
|
||||||
@click="addQuestion"
|
|
||||||
class="mt-4"
|
|
||||||
>
|
|
||||||
Добавить вопрос
|
|
||||||
</v-btn>
|
|
||||||
</div>
|
|
||||||
</v-card-text>
|
|
||||||
<v-card-actions>
|
|
||||||
<v-btn color="teal-darken-4" size="medium" @click="step = 1">Назад</v-btn>
|
|
||||||
<v-btn color="teal-darken-4" size="medium" @click="step = 3">Далее</v-btn>
|
|
||||||
</v-card-actions>
|
|
||||||
</v-card>
|
|
||||||
</v-stepper-window-item>
|
|
||||||
|
|
||||||
<!-- Подтверждение -->
|
|
||||||
<v-stepper-window-item class="fill-height" step="3">
|
|
||||||
<v-card class="fill-height d-flex flex-column" flat>
|
|
||||||
<v-card-title>Подтверждение создания теста</v-card-title>
|
|
||||||
<v-card-text style="max-height: 62vh; overflow-y: auto">
|
|
||||||
<v-alert v-if="errorMessage" class="mb-4" type="error">
|
|
||||||
{{ errorMessage }}
|
|
||||||
</v-alert>
|
|
||||||
<p><strong>Название:</strong> {{ form.name }}</p>
|
|
||||||
<p><strong>Описание:</strong> {{ form.description }}</p>
|
|
||||||
<p><strong>Период проведения:</strong> {{ formatDate(form.datestart) }} - {{ formatDate(form.dateend) }}</p>
|
|
||||||
<p><strong>Время на прохождение:</strong> {{ form.time }} мин.</p>
|
|
||||||
<p><strong>Кол-во вопросов:</strong> {{ form.question_count }}</p>
|
|
||||||
<p><strong>Мин. процент правильных ответов:</strong> {{ form.pass_perc }}%</p>
|
|
||||||
<p><strong>Кол-во попыток:</strong> {{ form.attemps_number }}</p>
|
|
||||||
<p><strong class="px-2">Вопросы:</strong></p>
|
|
||||||
|
|
||||||
<v-card
|
|
||||||
v-for="(question, index) in form.questions"
|
|
||||||
:key="index"
|
|
||||||
class="mb-4 pa-3"
|
|
||||||
>
|
|
||||||
<p><strong>Вопрос {{ index + 1 }}:</strong> {{ question.text }}</p>
|
|
||||||
<div v-for="(answer, aIndex) in question.answers" :key="aIndex" class="pl-3 mt-2">
|
|
||||||
<div class="d-flex align-center">
|
|
||||||
<v-icon :color="answer.right_wrong ? 'green' : 'red'">
|
|
||||||
{{ answer.right_wrong ? 'mdi-check-circle' : 'mdi-close-circle' }}
|
|
||||||
</v-icon>
|
|
||||||
<span class="ml-2">{{ answer.text }}</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</v-card>
|
|
||||||
</v-card-text>
|
|
||||||
<v-card-actions>
|
|
||||||
<v-btn color="teal-darken-4" size="medium" @click="step = 2">Назад</v-btn>
|
|
||||||
<v-btn
|
|
||||||
color="teal-darken-4"
|
|
||||||
size="medium"
|
|
||||||
:loading="loading"
|
|
||||||
:disabled="loading || hasValidationError"
|
|
||||||
@click="saveTest"
|
|
||||||
>
|
|
||||||
Сохранить тест
|
|
||||||
</v-btn>
|
|
||||||
</v-card-actions>
|
|
||||||
</v-card>
|
|
||||||
</v-stepper-window-item>
|
|
||||||
</v-stepper-window>
|
|
||||||
</v-stepper>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
</v-row>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
import { computed, ref, watch } from 'vue';
|
|
||||||
import { createTest } from '@/utils/axios-api';
|
|
||||||
import DateSelect from '@/components/UI/date-select.vue';
|
|
||||||
import CreatedTest from '@/components/testing/ConstructorTest/CreatedTest.vue';
|
|
||||||
|
|
||||||
export default {
|
|
||||||
components: { DateSelect, CreatedTest },
|
|
||||||
emits: ['updating'],
|
|
||||||
setup(props, { emit }) {
|
|
||||||
const step = ref(1);
|
|
||||||
const isTestCreated = ref(false);
|
|
||||||
const loading = ref(false);
|
|
||||||
const form = ref({
|
|
||||||
name: '',
|
|
||||||
description: '',
|
|
||||||
datestart: new Date(),
|
|
||||||
dateend: new Date(new Date().setDate(new Date().getDate() + 14)),
|
|
||||||
image: null,
|
|
||||||
pass_perc: '70',
|
|
||||||
time: '30',
|
|
||||||
question_count: '10',
|
|
||||||
attemps_number: '3',
|
|
||||||
questions: []
|
|
||||||
});
|
|
||||||
|
|
||||||
const rules = {
|
|
||||||
required: (value) => !!value || 'Это поле обязательно для заполнения',
|
|
||||||
positive: (value) => parseInt(value) > 0 || 'Должно быть положительное число',
|
|
||||||
percent: (value) => (parseInt(value) >= 0 && parseInt(value) <= 100) || 'Должно быть от 0 до 100'
|
|
||||||
};
|
|
||||||
|
|
||||||
const errorMessage = ref('');
|
|
||||||
|
|
||||||
const formatDate = (date) => {
|
|
||||||
if (!date) return '';
|
|
||||||
const d = new Date(date);
|
|
||||||
return `${d.getDate().toString().padStart(2, '0')}.${(d.getMonth() + 1).toString().padStart(2, '0')}.${d.getFullYear()}`;
|
|
||||||
};
|
|
||||||
|
|
||||||
const addQuestion = () => {
|
|
||||||
form.value.questions.push({
|
|
||||||
text: '',
|
|
||||||
image: null,
|
|
||||||
answers: [
|
|
||||||
{ text: '', image: null, right_wrong: false },
|
|
||||||
{ text: '', image: null, right_wrong: false }
|
|
||||||
]
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const removeQuestion = (index) => {
|
|
||||||
form.value.questions.splice(index, 1);
|
|
||||||
};
|
|
||||||
|
|
||||||
const addAnswer = (questionIndex) => {
|
|
||||||
if (form.value.questions[questionIndex]) {
|
|
||||||
form.value.questions[questionIndex].answers.push({ text: '', image: null, right_wrong: false });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const removeAnswer = (questionIndex, answerIndex) => {
|
|
||||||
form.value.questions[questionIndex].answers.splice(answerIndex, 1);
|
|
||||||
};
|
|
||||||
|
|
||||||
const validateForm = () => {
|
|
||||||
// Check basic fields
|
|
||||||
if (!form.value.name || !form.value.description) {
|
|
||||||
errorMessage.value = 'Заполните основную информацию о тесте';
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check that there are questions
|
|
||||||
if (form.value.questions.length === 0) {
|
|
||||||
errorMessage.value = 'Добавьте хотя бы один вопрос';
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check that each question has text
|
|
||||||
const emptyQuestions = form.value.questions.filter(q => !q.text.trim());
|
|
||||||
if (emptyQuestions.length > 0) {
|
|
||||||
errorMessage.value = 'Все вопросы должны иметь текст';
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check that each question has at least one answer
|
|
||||||
const questionsWithoutAnswers = form.value.questions.filter(q => q.answers.length === 0);
|
|
||||||
if (questionsWithoutAnswers.length > 0) {
|
|
||||||
errorMessage.value = 'Каждый вопрос должен иметь хотя бы один ответ';
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check that each question has at least one correct answer
|
|
||||||
const questionsWithoutCorrectAnswers = form.value.questions.filter(q =>
|
|
||||||
!q.answers.some(a => a.right_wrong)
|
|
||||||
);
|
|
||||||
if (questionsWithoutCorrectAnswers.length > 0) {
|
|
||||||
errorMessage.value = 'Каждый вопрос должен иметь хотя бы один правильный ответ';
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check that all answers have text
|
|
||||||
const hasEmptyAnswers = form.value.questions.some(q =>
|
|
||||||
q.answers.some(a => !a.text.trim())
|
|
||||||
);
|
|
||||||
if (hasEmptyAnswers) {
|
|
||||||
errorMessage.value = 'Все ответы должны иметь текст';
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// All validations passed
|
|
||||||
errorMessage.value = '';
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
||||||
const hasValidationError = computed(() => {
|
|
||||||
return !validateForm();
|
|
||||||
});
|
|
||||||
|
|
||||||
const saveTest = async () => {
|
|
||||||
if (!validateForm()) return;
|
|
||||||
|
|
||||||
try {
|
|
||||||
loading.value = true;
|
|
||||||
|
|
||||||
// Use the createTest function from API
|
|
||||||
await createTest(form.value);
|
|
||||||
|
|
||||||
console.log('Test created successfully');
|
|
||||||
isTestCreated.value = true;
|
|
||||||
emit('updating');
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Ошибка при создании теста:', error);
|
|
||||||
errorMessage.value = `Ошибка при создании теста: ${error.response?.data?.message || error.message}`;
|
|
||||||
} finally {
|
|
||||||
loading.value = false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const resetForm = () => {
|
|
||||||
form.value = {
|
|
||||||
name: '',
|
|
||||||
description: '',
|
|
||||||
datestart: new Date(),
|
|
||||||
dateend: new Date(new Date().setDate(new Date().getDate() + 14)),
|
|
||||||
image: null,
|
|
||||||
pass_perc: '70',
|
|
||||||
time: '30',
|
|
||||||
question_count: '10',
|
|
||||||
attemps_number: '3',
|
|
||||||
questions: []
|
|
||||||
};
|
|
||||||
step.value = 1;
|
|
||||||
isTestCreated.value = false;
|
|
||||||
errorMessage.value = '';
|
|
||||||
};
|
|
||||||
|
|
||||||
// Initialize with one question
|
|
||||||
addQuestion();
|
|
||||||
|
|
||||||
return {
|
|
||||||
step,
|
|
||||||
form,
|
|
||||||
rules,
|
|
||||||
isTestCreated,
|
|
||||||
errorMessage,
|
|
||||||
loading,
|
|
||||||
hasValidationError,
|
|
||||||
addQuestion,
|
|
||||||
removeQuestion,
|
|
||||||
addAnswer,
|
|
||||||
removeAnswer,
|
|
||||||
saveTest,
|
|
||||||
resetForm,
|
|
||||||
formatDate
|
|
||||||
};
|
|
||||||
},
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
.border {
|
|
||||||
border: 1px solid rgba(0, 0, 0, 0.12);
|
|
||||||
border-radius: 4px;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -17,8 +17,8 @@
|
|||||||
variant="outlined"
|
variant="outlined"
|
||||||
></v-textarea>
|
></v-textarea>
|
||||||
</div>
|
</div>
|
||||||
<div class="text-overline text-grey">Дата и время:</div>
|
<div v-if="!isTest" class="text-overline text-grey">Дата и время:</div>
|
||||||
<div class="d-flex justify-space-around">
|
<div v-if="!isTest" class="d-flex justify-space-around">
|
||||||
<div class="d-flex ga-3 align-center">
|
<div class="d-flex ga-3 align-center">
|
||||||
<h6 class="text-subtitle-1 pt-2">начало:</h6>
|
<h6 class="text-subtitle-1 pt-2">начало:</h6>
|
||||||
<date-select :datedefault="form.startDate" @returndate="returnstart" />
|
<date-select :datedefault="form.startDate" @returndate="returnstart" />
|
||||||
|
|||||||
@@ -164,10 +164,10 @@
|
|||||||
<strong class="px-2">Описание:</strong> {{ form.description }}
|
<strong class="px-2">Описание:</strong> {{ form.description }}
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<strong class="px-2">Дата начала:</strong>
|
<strong v-if="!isTest" class="px-2">Дата начала:</strong>
|
||||||
{{ form.startDate.toLocaleDateString() }}
|
{{ !isTest ? form.startDate.toLocaleDateString() : '' }}
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p v-if="!isTest">
|
||||||
<strong class="px-2">Дата окончания:</strong>
|
<strong class="px-2">Дата окончания:</strong>
|
||||||
{{ form.endDate.toLocaleDateString() }}
|
{{ form.endDate.toLocaleDateString() }}
|
||||||
</p>
|
</p>
|
||||||
@@ -319,8 +319,8 @@ export default {
|
|||||||
const form = ref({
|
const form = ref({
|
||||||
title: '',
|
title: '',
|
||||||
description: '',
|
description: '',
|
||||||
startDate: new Date(),
|
startDate: props.isTest ? null : new Date(),
|
||||||
endDate: new Date(new Date().setDate(new Date().getDate() + 14)),
|
endDate: props.isTest ? null : new Date(new Date().setDate(new Date().getDate() + 14)),
|
||||||
questions: [],
|
questions: [],
|
||||||
createnews: false,
|
createnews: false,
|
||||||
appoint: false
|
appoint: false
|
||||||
@@ -497,8 +497,8 @@ export default {
|
|||||||
form.value = {
|
form.value = {
|
||||||
title: '',
|
title: '',
|
||||||
description: '',
|
description: '',
|
||||||
startDate: new Date(),
|
startDate: props.isTest ? null : new Date(),
|
||||||
endDate: new Date(new Date().setDate(new Date().getDate() + 14)),
|
endDate: props.isTest ? null : new Date(new Date().setDate(new Date().getDate() + 14)),
|
||||||
questions: [],
|
questions: [],
|
||||||
createnews: false,
|
createnews: false,
|
||||||
appoint: false
|
appoint: false
|
||||||
|
|||||||
Reference in new issue
Block a user