feat [P-227]: конструктор адаптирован под тесты
This commit is contained in:
1 parent
50e66d8956
commit
c68af12398
10 files changed
+720
-26
No files matched your search
@@ -0,0 +1,14 @@
|
|||||||
|
<template>
|
||||||
|
<v-card class="mx-auto my-auto pa-5 text-center" max-width="600">
|
||||||
|
<v-icon color="teal-darken-1" size="x-large" class="mb-5">mdi-check-circle</v-icon>
|
||||||
|
<h1 class="text-h4 mb-4">Тест успешно создан</h1>
|
||||||
|
<p class="text-body-1 mb-4">Тест добавлен в каталог и готов к назначению сотрудникам</p>
|
||||||
|
<slot></slot>
|
||||||
|
</v-card>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
name: "CreatedTest"
|
||||||
|
};
|
||||||
|
</script>
|
||||||
@@ -0,0 +1,420 @@
|
|||||||
|
<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>
|
||||||
@@ -6,15 +6,15 @@
|
|||||||
:key="aIndex"
|
:key="aIndex"
|
||||||
class="d-flex align-start mb-4"
|
class="d-flex align-start mb-4"
|
||||||
>
|
>
|
||||||
<!-- Показываем иконку для переключения статуса только если роут содержит "test" -->
|
<!-- Показываем иконку для переключения статуса только в режиме теста -->
|
||||||
<v-btn
|
<v-btn
|
||||||
v-if="isTestRoute"
|
v-if="isTest"
|
||||||
class="ml-2"
|
class="ml-2"
|
||||||
icon
|
icon
|
||||||
size="small"
|
size="small"
|
||||||
@click="toggleCorrect(answer)"
|
@click="toggleCorrect(answer)"
|
||||||
>
|
>
|
||||||
<v-icon color="green" v-if="answer.correct" large>mdi-check</v-icon>
|
<v-icon color="green" v-if="answer.right_wrong" large>mdi-check</v-icon>
|
||||||
<v-icon color="red" v-else large>mdi-close</v-icon>
|
<v-icon color="red" v-else large>mdi-close</v-icon>
|
||||||
</v-btn>
|
</v-btn>
|
||||||
|
|
||||||
@@ -76,22 +76,29 @@ export default {
|
|||||||
removeAnswer: {
|
removeAnswer: {
|
||||||
type: Function,
|
type: Function,
|
||||||
required: true,
|
required: true,
|
||||||
|
},
|
||||||
|
isTest: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
setup() {
|
setup(props) {
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
|
|
||||||
|
// Поддерживаем оба способа определения: через роут или через явный проп
|
||||||
const isTestRoute = computed(() => {
|
const isTestRoute = computed(() => {
|
||||||
return route.path && String(route.path).includes('test');
|
return route.path && String(route.path).includes('test');
|
||||||
});
|
});
|
||||||
|
|
||||||
const toggleCorrect = (answer) => {
|
const toggleCorrect = (answer) => {
|
||||||
answer.correct = !answer.correct;
|
// Используем right_wrong для тестов (совместимо с бэкендом)
|
||||||
|
answer.right_wrong = !answer.right_wrong;
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
isTestRoute,
|
isTestRoute,
|
||||||
toggleCorrect,
|
toggleCorrect,
|
||||||
|
isTest: props.isTest
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,11 +3,19 @@
|
|||||||
<v-spacer></v-spacer>
|
<v-spacer></v-spacer>
|
||||||
<div class>
|
<div class>
|
||||||
<v-icon color="success" size="48">mdi-check-circle</v-icon>
|
<v-icon color="success" size="48">mdi-check-circle</v-icon>
|
||||||
<h2 class="mt-4">Голосование создано!</h2>
|
<h2 class="mt-4">{{ title || 'Голосование создано!' }}</h2>
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
</div>
|
</div>
|
||||||
<v-spacer></v-spacer>
|
<v-spacer></v-spacer>
|
||||||
</v-card>
|
</v-card>
|
||||||
</template>
|
</template>
|
||||||
<script setup lang="ts">
|
<script>
|
||||||
|
export default {
|
||||||
|
props: {
|
||||||
|
title: {
|
||||||
|
type: String,
|
||||||
|
default: ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<v-card class="fill-height d-flex flex-column" flat>
|
<v-card class="fill-height d-flex flex-column" flat>
|
||||||
<v-card-title>Основная информация</v-card-title>
|
<v-card-title>{{ isTest ? 'Основная информация о тесте' : 'Основная информация' }}</v-card-title>
|
||||||
<v-card-text class="d-flex flex-column overflow-auto">
|
<v-card-text class="d-flex flex-column overflow-auto">
|
||||||
<v-text-field
|
<v-text-field
|
||||||
v-model="localForm.title"
|
v-model="localForm.title"
|
||||||
@@ -104,6 +104,10 @@ export default {
|
|||||||
required: (value) => !!value || 'Это поле обязательно для заполнения',
|
required: (value) => !!value || 'Это поле обязательно для заполнения',
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
|
isTest: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
}
|
||||||
},
|
},
|
||||||
emits: ['update:form'],
|
emits: ['update:form'],
|
||||||
setup(props, { emit }) {
|
setup(props, { emit }) {
|
||||||
@@ -186,7 +190,8 @@ export default {
|
|||||||
selectedTimeStart,
|
selectedTimeStart,
|
||||||
selectedTimeEnd,
|
selectedTimeEnd,
|
||||||
timeOptions,
|
timeOptions,
|
||||||
isTestRoute
|
isTestRoute,
|
||||||
|
isTest: props.isTest
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
:removeQuestion="removeQuestion"
|
:removeQuestion="removeQuestion"
|
||||||
:rules="rules"
|
:rules="rules"
|
||||||
:spravURL="spravURL"
|
:spravURL="spravURL"
|
||||||
|
:isTest="isTest"
|
||||||
@update:question="form.questions[index] = $event"
|
@update:question="form.questions[index] = $event"
|
||||||
/>
|
/>
|
||||||
</transition-group>
|
</transition-group>
|
||||||
@@ -67,6 +68,10 @@ export default {
|
|||||||
onlyDepdict: {
|
onlyDepdict: {
|
||||||
type: Array,
|
type: Array,
|
||||||
},
|
},
|
||||||
|
isTest: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
},
|
},
|
||||||
emits: ['update:form'],
|
emits: ['update:form'],
|
||||||
setup(props, { emit }) {
|
setup(props, { emit }) {
|
||||||
@@ -121,6 +126,7 @@ export default {
|
|||||||
removeAnswer,
|
removeAnswer,
|
||||||
checkremote,
|
checkremote,
|
||||||
spravURL,
|
spravURL,
|
||||||
|
isTest: props.isTest
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
<!-- Ответы или выбор сотрудников в зависимости от типа ответа -->
|
<!-- Ответы или выбор сотрудников в зависимости от типа ответа -->
|
||||||
<v-card-text class="px-0">
|
<v-card-text class="px-0">
|
||||||
<!-- Для типа "free" – ручной ввод ответов -->
|
<!-- Для типа "free" – ручной ввод ответов -->
|
||||||
<AnswerList v-if="question.settings.choice === 'free'" :rules="rules" :question="question" :remove-answer="removeAnswer" :add-answer="addAnswer" />
|
<AnswerList v-if="question.settings.choice === 'free'" :rules="rules" :question="question" :remove-answer="removeAnswer" :add-answer="addAnswer" :is-test="isTest" />
|
||||||
|
|
||||||
<!-- Для типа "employee" – выбор сотрудников -->
|
<!-- Для типа "employee" – выбор сотрудников -->
|
||||||
<div v-else>
|
<div v-else>
|
||||||
@@ -168,6 +168,10 @@ export default {
|
|||||||
type: Array,
|
type: Array,
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
|
isTest: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
onlyDepdict: {
|
onlyDepdict: {
|
||||||
type: Array,
|
type: Array,
|
||||||
default: () => [],
|
default: () => [],
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
<template>
|
<template>
|
||||||
<v-row class="pt-2 mx-1 flex-column fill-height flex-grow-0">
|
<v-row class="pt-2 mx-1 flex-column fill-height flex-grow-0">
|
||||||
<CreatedVote v-if="isVoteCreated">
|
<CreatedVote v-if="isVoteCreated" :title="isTest ? 'Тест успешно создан' : 'Голосование успешно создано'">
|
||||||
<v-btn class="mt-4" color="teal-darken-4" @click="resetForm">Создать ещё</v-btn>
|
<v-btn class="mt-4" color="teal-darken-4" @click="resetForm">
|
||||||
|
{{ isTest ? 'Создать ещё один тест' : 'Создать ещё одно голосование' }}
|
||||||
|
</v-btn>
|
||||||
</CreatedVote>
|
</CreatedVote>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<div class="v-col flex-grow-1 flex-shrink-0">
|
<div class="v-col flex-grow-1 flex-shrink-0">
|
||||||
@@ -9,7 +11,7 @@
|
|||||||
<v-stepper-header class="flex-grow-0 flex-shrink-1">
|
<v-stepper-header class="flex-grow-0 flex-shrink-1">
|
||||||
<v-stepper-item :complete="step > 0" step="1">Основная информация</v-stepper-item>
|
<v-stepper-item :complete="step > 0" step="1">Основная информация</v-stepper-item>
|
||||||
<v-divider></v-divider>
|
<v-divider></v-divider>
|
||||||
<v-stepper-item :complete="step > 1" step="2">Создание опроса</v-stepper-item>
|
<v-stepper-item :complete="step > 1" step="2">{{ isTest ? 'Создание теста' : 'Создание опроса' }}</v-stepper-item>
|
||||||
<v-divider></v-divider>
|
<v-divider></v-divider>
|
||||||
<v-stepper-item :complete="step > 2" step="3">Подтверждение</v-stepper-item>
|
<v-stepper-item :complete="step > 2" step="3">Подтверждение</v-stepper-item>
|
||||||
</v-stepper-header>
|
</v-stepper-header>
|
||||||
@@ -17,7 +19,52 @@
|
|||||||
<v-stepper-window class="fill-height">
|
<v-stepper-window class="fill-height">
|
||||||
<!-- Основная информация -->
|
<!-- Основная информация -->
|
||||||
<v-stepper-window-item class="fill-height" step="1">
|
<v-stepper-window-item class="fill-height" step="1">
|
||||||
<MainInfo v-model:form="form" :rules="rules">
|
<MainInfo v-model:form="form" :rules="rules" :isTest="isTest">
|
||||||
|
<template v-if="isTest">
|
||||||
|
<v-card-text>
|
||||||
|
<div class="d-flex">
|
||||||
|
<v-text-field
|
||||||
|
v-model="testSettings.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="testSettings.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="testSettings.question_count"
|
||||||
|
:rules="[rules.required, rules.positive]"
|
||||||
|
label="Количество вопросов"
|
||||||
|
type="number"
|
||||||
|
min="1"
|
||||||
|
required
|
||||||
|
class="mr-2"
|
||||||
|
></v-text-field>
|
||||||
|
<v-text-field
|
||||||
|
v-model="testSettings.attemps_number"
|
||||||
|
:rules="[rules.required, rules.positive]"
|
||||||
|
label="Количество попыток"
|
||||||
|
type="number"
|
||||||
|
min="1"
|
||||||
|
required
|
||||||
|
class="ml-2"
|
||||||
|
></v-text-field>
|
||||||
|
</div>
|
||||||
|
</v-card-text>
|
||||||
|
</template>
|
||||||
<v-card-actions>
|
<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 = 1">Далее</v-btn>
|
||||||
</v-card-actions>
|
</v-card-actions>
|
||||||
@@ -27,7 +74,7 @@
|
|||||||
<!-- Создание опроса -->
|
<!-- Создание опроса -->
|
||||||
<v-stepper-window-item class="fill-height" step="2">
|
<v-stepper-window-item class="fill-height" step="2">
|
||||||
<v-card class="fill-height d-flex flex-column" flat>
|
<v-card class="fill-height d-flex flex-column" flat>
|
||||||
<v-card-title>Создание опроса:</v-card-title>
|
<v-card-title>{{ isTest ? 'Создание теста:' : 'Создание опроса:' }}</v-card-title>
|
||||||
<v-card-text style="max-height: 62vh; overflow-y: auto">
|
<v-card-text style="max-height: 62vh; overflow-y: auto">
|
||||||
<NewQuestion
|
<NewQuestion
|
||||||
:form="form"
|
:form="form"
|
||||||
@@ -40,13 +87,13 @@
|
|||||||
:onEmployeesChange="onEmployeesChange"
|
:onEmployeesChange="onEmployeesChange"
|
||||||
:findEmployeeById="findEmployeeById"
|
:findEmployeeById="findEmployeeById"
|
||||||
:onlyDepdict="onlyDepdict"
|
:onlyDepdict="onlyDepdict"
|
||||||
|
:isTest="isTest"
|
||||||
/>
|
/>
|
||||||
<v-divider class="ma-2 pa-1"></v-divider>
|
<v-divider class="ma-2 pa-1"></v-divider>
|
||||||
<div class="d-flex justify-center">
|
<div class="d-flex justify-center">
|
||||||
<v-btn color="orange-darken-4" size="small" @click="addQuestion"
|
<v-btn color="orange-darken-4" size="small" @click="addQuestion"
|
||||||
>Добавить вопрос
|
>Добавить вопрос
|
||||||
</v-btn
|
</v-btn>
|
||||||
>
|
|
||||||
</div>
|
</div>
|
||||||
</v-card-text>
|
</v-card-text>
|
||||||
<v-card-actions>
|
<v-card-actions>
|
||||||
@@ -159,7 +206,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { computed, ref, watch } from 'vue';
|
import { computed, ref, watch } from 'vue';
|
||||||
import { createVote, getEmployees } from '@/utils/axios-api';
|
import { createVote, getEmployees, createTest } from '@/utils/axios-api';
|
||||||
import DateSelect from '@/components/UI/date-select.vue';
|
import DateSelect from '@/components/UI/date-select.vue';
|
||||||
import MainInfo from '@/components/vote/ConstructorVote/MainInfo.vue';
|
import MainInfo from '@/components/vote/ConstructorVote/MainInfo.vue';
|
||||||
import CreatedVote from '@/components/vote/ConstructorVote/CreatedVote.vue';
|
import CreatedVote from '@/components/vote/ConstructorVote/CreatedVote.vue';
|
||||||
@@ -167,6 +214,12 @@ import NewQuestion from '@/components/vote/ConstructorVote/NewQuestion.vue';
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: { NewQuestion, CreatedVote, MainInfo, DateSelect },
|
components: { NewQuestion, CreatedVote, MainInfo, DateSelect },
|
||||||
|
props: {
|
||||||
|
isTest: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
}
|
||||||
|
},
|
||||||
emits: ['updating'],
|
emits: ['updating'],
|
||||||
setup(props, { emit }) {
|
setup(props, { emit }) {
|
||||||
const step = ref(0);
|
const step = ref(0);
|
||||||
@@ -181,8 +234,17 @@ export default {
|
|||||||
appoint: false
|
appoint: false
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const testSettings = ref({
|
||||||
|
pass_perc: '70',
|
||||||
|
time: '30',
|
||||||
|
question_count: '10',
|
||||||
|
attemps_number: '3',
|
||||||
|
});
|
||||||
|
|
||||||
const rules = {
|
const rules = {
|
||||||
required: (value) => !!value || 'Это поле обязательно для заполнения',
|
required: (value) => !!value || 'Это поле обязательно для заполнения',
|
||||||
|
positive: (value) => parseInt(value) > 0 || 'Должно быть положительное число',
|
||||||
|
percent: (value) => (parseInt(value) >= 0 && parseInt(value) <= 100) || 'Должно быть от 0 до 100'
|
||||||
};
|
};
|
||||||
|
|
||||||
const currentQuestionIndex = ref(0);
|
const currentQuestionIndex = ref(0);
|
||||||
@@ -228,11 +290,17 @@ export default {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const addQuestion = () => {
|
const addQuestion = () => {
|
||||||
|
// Для тестов добавляем начальные ответы с right_wrong полем
|
||||||
|
const initialAnswers = props.isTest ? [
|
||||||
|
{ text: '', image: null, right_wrong: false },
|
||||||
|
{ text: '', image: null, right_wrong: false }
|
||||||
|
] : [];
|
||||||
|
|
||||||
form.value.questions.push({
|
form.value.questions.push({
|
||||||
text: '',
|
text: '',
|
||||||
settings: { choice: 'free', multiChoice: 1, onlyDep: null },
|
settings: { choice: 'free', multiChoice: 1, onlyDep: null },
|
||||||
image: null,
|
image: null,
|
||||||
answers: [],
|
answers: initialAnswers,
|
||||||
selectedEmployees: [],
|
selectedEmployees: [],
|
||||||
});
|
});
|
||||||
currentQuestionIndex.value = form.value.questions.length - 1;
|
currentQuestionIndex.value = form.value.questions.length - 1;
|
||||||
@@ -247,7 +315,11 @@ export default {
|
|||||||
|
|
||||||
const addAnswer = (index) => {
|
const addAnswer = (index) => {
|
||||||
if (currentQuestion.value) {
|
if (currentQuestion.value) {
|
||||||
form.value.questions[index].answers.push({ text: '', image: null });
|
form.value.questions[index].answers.push({
|
||||||
|
text: '',
|
||||||
|
image: null,
|
||||||
|
right_wrong: props.isTest ? false : undefined // Добавляем поле right_wrong только для тестов
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -282,11 +354,40 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await createVote(form.value);
|
if (props.isTest) {
|
||||||
|
// Подготавливаем данные для теста
|
||||||
|
const testData = {
|
||||||
|
name: form.value.title,
|
||||||
|
description: form.value.description,
|
||||||
|
datestart: form.value.startDate,
|
||||||
|
dateend: form.value.endDate,
|
||||||
|
image: null,
|
||||||
|
pass_perc: Number(testSettings.value.pass_perc),
|
||||||
|
time: Number(testSettings.value.time),
|
||||||
|
question_count: Number(testSettings.value.question_count),
|
||||||
|
attemps_number: Number(testSettings.value.attemps_number),
|
||||||
|
questions: form.value.questions.map(q => ({
|
||||||
|
text: q.text,
|
||||||
|
image: q.image,
|
||||||
|
settings: q.settings || {},
|
||||||
|
answers: q.answers.map(a => ({
|
||||||
|
text: a.text,
|
||||||
|
image: a.image,
|
||||||
|
right_wrong: a.right_wrong || false
|
||||||
|
}))
|
||||||
|
}))
|
||||||
|
};
|
||||||
|
await createTest(testData);
|
||||||
|
} else {
|
||||||
|
// Стандартное создание голосования
|
||||||
|
await createVote(form.value);
|
||||||
|
}
|
||||||
|
|
||||||
isVoteCreated.value = true;
|
isVoteCreated.value = true;
|
||||||
emit('updating', 'active');
|
emit('updating', 'active');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return new Error(error)
|
console.error("Ошибка при создании:", error);
|
||||||
|
errorMessage.value = `Ошибка при создании: ${error.message || error}`;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -297,6 +398,14 @@ export default {
|
|||||||
startDate: new Date(),
|
startDate: new Date(),
|
||||||
endDate: new Date(new Date().setDate(new Date().getDate() + 14)),
|
endDate: new Date(new Date().setDate(new Date().getDate() + 14)),
|
||||||
questions: [],
|
questions: [],
|
||||||
|
createnews: false,
|
||||||
|
appoint: false
|
||||||
|
};
|
||||||
|
testSettings.value = {
|
||||||
|
pass_perc: '70',
|
||||||
|
time: '30',
|
||||||
|
question_count: '10',
|
||||||
|
attemps_number: '3',
|
||||||
};
|
};
|
||||||
step.value = 0;
|
step.value = 0;
|
||||||
isVoteCreated.value = false;
|
isVoteCreated.value = false;
|
||||||
@@ -354,6 +463,11 @@ export default {
|
|||||||
|
|
||||||
const quests = computed(() => form.value.questions.map((question) => question.text.length > 0));
|
const quests = computed(() => form.value.questions.map((question) => question.text.length > 0));
|
||||||
|
|
||||||
|
// Добавляем начальный вопрос при монтировании компонента, если мы в режиме теста
|
||||||
|
if (props.isTest && form.value.questions.length === 0) {
|
||||||
|
addQuestion();
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
quests,
|
quests,
|
||||||
onlyDepdict,
|
onlyDepdict,
|
||||||
@@ -374,6 +488,8 @@ export default {
|
|||||||
allEmployees,
|
allEmployees,
|
||||||
handleSelectAll,
|
handleSelectAll,
|
||||||
isAllSelected,
|
isAllSelected,
|
||||||
|
testSettings,
|
||||||
|
isTest: props.isTest
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -199,6 +199,84 @@ async function getVoteResult(id) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function createTest(testData) {
|
||||||
|
try {
|
||||||
|
const formData = new FormData();
|
||||||
|
|
||||||
|
if (testData.image) {
|
||||||
|
formData.append('image', testData.image);
|
||||||
|
}
|
||||||
|
|
||||||
|
testData.questions.forEach((question, qIndex) => {
|
||||||
|
if (question.image) {
|
||||||
|
formData.append('questionsfiles', question.image);
|
||||||
|
const { name, size, lastModified } = question.image;
|
||||||
|
question.image = { name, size, lastModified };
|
||||||
|
}
|
||||||
|
|
||||||
|
question.answers.forEach((answer, aIndex) => {
|
||||||
|
if (answer.image) {
|
||||||
|
formData.append('answersfiles', answer.image);
|
||||||
|
const { name, size, lastModified } = answer.image;
|
||||||
|
answer.image = { name, size, lastModified };
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
formData.append('name', testData.name);
|
||||||
|
formData.append('description', testData.description);
|
||||||
|
formData.append('datestart', new Date(testData.datestart).toISOString());
|
||||||
|
formData.append('dateend', new Date(testData.dateend).toISOString());
|
||||||
|
formData.append('pass_perc', testData.pass_perc);
|
||||||
|
formData.append('time', testData.time);
|
||||||
|
formData.append('question_count', testData.question_count);
|
||||||
|
formData.append('attemps_number', testData.attemps_number);
|
||||||
|
formData.append('questions', JSON.stringify(testData.questions));
|
||||||
|
|
||||||
|
const response = await axiosApiInstance.post('/api/tests/testcreate/', formData, {
|
||||||
|
headers: { 'Content-Type': 'multipart/form-data' },
|
||||||
|
});
|
||||||
|
|
||||||
|
return response.data;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Ошибка создания теста:', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function assignTest(testId, employeeIds) {
|
||||||
|
try {
|
||||||
|
const response = await axiosApiInstance.post('/api/tests/assigntest/', {
|
||||||
|
testId,
|
||||||
|
employeeIds
|
||||||
|
});
|
||||||
|
return response.data;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Ошибка назначения теста:', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getTestDetail(id) {
|
||||||
|
try {
|
||||||
|
const response = await axiosApiInstance.get(`/api/tests/testdetail/${id}/`);
|
||||||
|
return response.data;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Ошибка получения деталей теста:", error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deleteTest(id) {
|
||||||
|
try {
|
||||||
|
await axiosApiInstance.delete(`/api/tests/testdetail/${id}/`);
|
||||||
|
console.log("Тест успешно удален");
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Ошибка удаления теста:", error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export {
|
export {
|
||||||
axiosApiInstance,
|
axiosApiInstance,
|
||||||
@@ -215,4 +293,8 @@ export {
|
|||||||
deleteVote,
|
deleteVote,
|
||||||
getEmployees,
|
getEmployees,
|
||||||
getVoteResult,
|
getVoteResult,
|
||||||
|
createTest,
|
||||||
|
assignTest,
|
||||||
|
getTestDetail,
|
||||||
|
deleteTest,
|
||||||
}
|
}
|
||||||
@@ -64,7 +64,7 @@
|
|||||||
|
|
||||||
<!-- Конструктор -->
|
<!-- Конструктор -->
|
||||||
<v-window-item>
|
<v-window-item>
|
||||||
<VoteConstructor />
|
<VoteConstructor @updating="getTestById" :isTest="true" />
|
||||||
</v-window-item>
|
</v-window-item>
|
||||||
</v-window>
|
</v-window>
|
||||||
|
|
||||||
@@ -76,7 +76,7 @@
|
|||||||
<v-card-actions>
|
<v-card-actions>
|
||||||
<v-spacer />
|
<v-spacer />
|
||||||
<v-btn color="grey" @click="deleteDialog = false">Отмена</v-btn>
|
<v-btn color="grey" @click="deleteDialog = false">Отмена</v-btn>
|
||||||
<v-btn color="red-darken-4" >Удалить</v-btn>
|
<v-btn color="red-darken-4" @click="deleteTest">Удалить</v-btn>
|
||||||
</v-card-actions>
|
</v-card-actions>
|
||||||
</v-card>
|
</v-card>
|
||||||
</v-dialog>
|
</v-dialog>
|
||||||
@@ -89,7 +89,7 @@
|
|||||||
<v-card-actions>
|
<v-card-actions>
|
||||||
<v-spacer />
|
<v-spacer />
|
||||||
<v-btn color="grey" @click="addDialog = false">Отмена</v-btn>
|
<v-btn color="grey" @click="addDialog = false">Отмена</v-btn>
|
||||||
<v-btn color="orange-darken-2" >Добавить</v-btn>
|
<v-btn color="orange-darken-2" @click="assignTestToEmployee">Добавить</v-btn>
|
||||||
</v-card-actions>
|
</v-card-actions>
|
||||||
</v-card>
|
</v-card>
|
||||||
</v-dialog>
|
</v-dialog>
|
||||||
@@ -98,7 +98,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import CatalogTest from '@/components/testing/CatalogTest.vue';
|
import CatalogTest from '@/components/testing/CatalogTest.vue';
|
||||||
import { axiosApiInstance, getEmployees, spravURL } from '@/utils/axios-api';
|
import { axiosApiInstance, getEmployees, spravURL, deleteTest as apiDeleteTest, assignTest } from '@/utils/axios-api';
|
||||||
import { computed, ref, watch } from 'vue';
|
import { computed, ref, watch } from 'vue';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
import VoteConstructor from '@/components/vote/VoteConstructor.vue';
|
import VoteConstructor from '@/components/vote/VoteConstructor.vue';
|
||||||
@@ -169,6 +169,35 @@ export default {
|
|||||||
addDialog.value = true;
|
addDialog.value = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const deleteTest = async () => {
|
||||||
|
try {
|
||||||
|
await apiDeleteTest(selectedTestId.value);
|
||||||
|
deleteDialog.value = false;
|
||||||
|
getTestById();
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Ошибка при удалении теста:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const assignTestToEmployee = async () => {
|
||||||
|
try {
|
||||||
|
const selectedEmployees = document.querySelectorAll('input[name="employee"]:checked');
|
||||||
|
const employeeIds = Array.from(selectedEmployees).map(el => el.value);
|
||||||
|
|
||||||
|
if (employeeIds.length === 0) {
|
||||||
|
alert('Выберите хотя бы одного сотрудника');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await assignTest(selectedTestId.value, employeeIds);
|
||||||
|
|
||||||
|
addDialog.value = false;
|
||||||
|
getTestById();
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Ошибка при назначении теста:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
activeTab,
|
activeTab,
|
||||||
tabs,
|
tabs,
|
||||||
@@ -179,6 +208,9 @@ export default {
|
|||||||
addDialog,
|
addDialog,
|
||||||
openDeleteDialog,
|
openDeleteDialog,
|
||||||
openAddDialog,
|
openAddDialog,
|
||||||
|
deleteTest,
|
||||||
|
assignTestToEmployee,
|
||||||
|
getTestById
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user