изменения в редакторе для голосования

This commit is contained in:
Denzel committed 2025-01-15 15:09:18 +03:00
1 parent c35882b0af
commit a5d22094f7
2 files changed
+155 -151

No files matched your search

+155 -135
View File
@@ -25,58 +25,54 @@
<v-card-text> <v-card-text>
<v-text-field <v-text-field
v-model="form.title" v-model="form.title"
:rules="[rules.required]"
label="Название голосования" label="Название голосования"
outlined outlined
:rules="[rules.required]"
></v-text-field> ></v-text-field>
<v-textarea <v-textarea
v-model="form.description" v-model="form.description"
:rules="[rules.required]"
label="Описание" label="Описание"
outlined outlined
:rules="[rules.required]"
></v-textarea> ></v-textarea>
<v-text-field <div class="d-flex ga-xl-16">
:placeholder="`${form.startDate.toLocaleDateString()} ${form.startDate.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}`" <div>
:value="`${form.startDate.toLocaleDateString()} ${form.startDate.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}`"
color="teal-darken-4"
label="Дата и время начала"
persistentPlaceholder
readonly
>
<v-menu activator="parent">
<v-date-picker <v-date-picker
v-model="form.startDate" v-model="form.startDate"
color="teal-darken-4" color="teal-darken-4"
hideHeader hide-weekdays
hideWeekdays title="дата начала"
/> />
</v-menu> <v-select
<v-btn flat icon style="background-color: transparent"> v-model="selectedTimeStart"
<v-icon>mdi-calendar-clock</v-icon> :items="timeOptions"
</v-btn> dense
</v-text-field> label="Время начала"
outlined
prepend-icon="mdi-calendar-clock"
/>
</div>
<div>
<v-date-picker
v-model="form.endDate"
color="teal-darken-4"
hide-weekdays
title="дата окончания"
/>
<v-select
v-model="selectedTimeEnd"
:items="timeOptions"
dense
label="Время окончания"
outlined
prepend-icon="mdi-calendar-clock"
/>
</div>
</div>
<v-text-field <pre>начало {{ form.startDate }}</pre>
:placeholder="`${form.endDate.toLocaleDateString()} ${form.endDate.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}`" <pre>окончание {{ form.endDate }}</pre>
:value="`${form.endDate.toLocaleDateString()} ${form.endDate.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}`"
color="teal-darken-4"
label="Дата и время окончания"
persistentPlaceholder
readonly
>
<v-menu activator="parent">
<v-date-picker
v-model="form.endDate"
color="teal-darken-4"
hideHeader
hideWeekdays
/>
</v-menu>
<v-btn flat icon style="background-color: transparent">
<v-icon>mdi-calendar-clock</v-icon>
</v-btn>
</v-text-field>
</v-card-text> </v-card-text>
<v-card-actions> <v-card-actions>
@@ -95,92 +91,92 @@
<v-text-field <v-text-field
v-model="question.text" v-model="question.text"
:label="'Вопрос ' + (index + 1)" :label="'Вопрос ' + (index + 1)"
outlined
:rules="[rules.required]" :rules="[rules.required]"
outlined
></v-text-field> ></v-text-field>
<v-btn color="error" icon @click="removeQuestion(index)"> <v-btn color="error" icon @click="removeQuestion(index)">
<v-icon>mdi-delete</v-icon> <v-icon>mdi-delete</v-icon>
</v-btn> </v-btn>
</div> </div>
<v-file-input <v-file-input
v-model="question.image" v-model="question.image"
accept="image/*" accept="image/*"
label="Картинка для вопроса" label="Картинка для вопроса"
outlined outlined
></v-file-input> ></v-file-input>
<v-select <v-select
v-model="question.type" v-model="question.type"
:items="questionTypes" :items="questionTypes"
label="Тип ответа" label="Тип ответа"
outlined outlined
></v-select> ></v-select>
<v-switch <v-switch
v-model="question.multiChoice" v-model="question.multiChoice"
color="teal-darken-4"
:label="`Множественный выбор: ${question.multiChoice ? 'да' : 'нет'}`"
:false-value="false" :false-value="false"
:label="`Множественный выбор: ${question.multiChoice ? 'да' : 'нет'}`"
:true-value="true" :true-value="true"
color="teal-darken-4"
hide-details hide-details
></v-switch> ></v-switch>
<v-card-text> <v-card-text>
<div v-if="question.type === 'Ввести вручную'"> <div v-if="question.type === 'Ввести вручную'">
<div <div
v-for="(answer, index) in question.answers" v-for="(answer, index) in question.answers"
:key="index" :key="index"
class="d-flex align-start mb-4" class="d-flex align-start mb-4"
> >
<v-text-field <v-text-field
v-model="answer.text" v-model="answer.text"
:label="'Ответ ' + (index + 1)" :label="'Ответ ' + (index + 1)"
class="mr-4" :rules="[rules.required]"
outlined class="mr-4"
:rules="[rules.required]" outlined
></v-text-field> ></v-text-field>
<v-file-input <v-file-input
v-model="answer.image" v-model="answer.image"
accept="image/*" accept="image/*"
dense dense
hide-details hide-details
label="Картинка" label="Картинка"
outlined outlined
></v-file-input> ></v-file-input>
<v-btn color="error" icon @click="removeAnswer(index)"> <v-btn color="error" icon @click="removeAnswer(index)">
<v-icon>mdi-delete</v-icon> <v-icon>mdi-delete</v-icon>
</v-btn> </v-btn>
</div> </div>
<v-btn color="teal-darken-4" @click="addAnswer">Добавить ответ</v-btn> <v-btn color="teal-darken-4" @click="addAnswer">Добавить ответ</v-btn>
</div> </div>
<div v-else> <div v-else>
<v-autocomplete <v-autocomplete
v-model="currentQuestion.selectedEmployees" v-model="currentQuestion.selectedEmployees"
:items="groupedEmployees" :items="groupedEmployees"
item-title="fio" item-title="fio"
item-value="id" item-value="id"
label="Выберите сотрудников" label="Выберите сотрудников"
multiple multiple
outlined outlined
></v-autocomplete> ></v-autocomplete>
<div <div
v-for="(person, index) in currentQuestion.selectedEmployees" v-for="(person, index) in currentQuestion.selectedEmployees"
:key="person.id" :key="person.id"
class="d-flex align-center mb-4" class="d-flex align-center mb-4"
> >
<v-chip>{{ findEmployeeById(person).fio }}</v-chip> <v-chip>{{ findEmployeeById(person).fio }}</v-chip>
<v-file-input <v-file-input
v-model="currentQuestion.selectedEmployeeImages[person]" v-model="currentQuestion.selectedEmployeeImages[person]"
accept="image/*" accept="image/*"
class="ml-4" class="ml-4"
dense dense
hide-details hide-details
label="Картинка" label="Картинка"
outlined outlined
></v-file-input> ></v-file-input>
<v-btn color="error" icon @click="removeEmployee(index)"> <v-btn color="error" icon @click="removeEmployee(index)">
<v-icon>mdi-delete</v-icon> <v-icon>mdi-delete</v-icon>
</v-btn> </v-btn>
</div> </div>
</div> </div>
</v-card-text> </v-card-text>
</div> </div>
<v-btn color="teal-darken-4" @click="addQuestion">Добавить вопрос</v-btn> <v-btn color="teal-darken-4" @click="addQuestion">Добавить вопрос</v-btn>
</v-card-text> </v-card-text>
@@ -216,8 +212,8 @@
<p><strong>Выбранные сотрудники:</strong></p> <p><strong>Выбранные сотрудники:</strong></p>
<ul> <ul>
<li <li
v-for="employeeId in question.selectedEmployees" v-for="employeeId in question.selectedEmployees"
:key="employeeId" :key="employeeId"
> >
{{ findEmployeeById(employeeId).fio }} {{ findEmployeeById(employeeId).fio }}
</li> </li>
@@ -230,7 +226,7 @@
<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-btn color="teal-darken-4" size="medium" @click="saveVoting">Сохранить</v-btn> <v-btn color="teal-darken-4" size="medium" @click="saveVoting">Сохранить</v-btn>
</v-card-actions> </v-card-actions>
<v-alert v-if="errorMessage" type="error" class="mb-4"> <v-alert v-if="errorMessage" class="mb-4" type="error">
{{ errorMessage }} {{ errorMessage }}
</v-alert> </v-alert>
</v-card> </v-card>
@@ -243,8 +239,8 @@
</template> </template>
<script> <script>
import {computed, ref} from "vue"; import {computed, ref, watch} from "vue";
import { createVote } from "@/utils/axios-api"; import {createVote} from "@/utils/axios-api";
export default { export default {
emits: ['updating'], emits: ['updating'],
@@ -272,11 +268,11 @@ export default {
]; ];
const currentQuestion = computed(() => const currentQuestion = computed(() =>
form.value.questions[currentQuestionIndex.value] || null form.value.questions[currentQuestionIndex.value] || null
); );
const findEmployeeById = (id) => const findEmployeeById = (id) =>
groupedEmployees.find((employee) => employee.id === id) || {}; groupedEmployees.find((employee) => employee.id === id) || {};
const removeEmployee = (index) => { const removeEmployee = (index) => {
currentQuestion.value.selectedEmployees.splice(index, 1); currentQuestion.value.selectedEmployees.splice(index, 1);
@@ -342,6 +338,42 @@ export default {
isVoteCreated.value = false; isVoteCreated.value = false;
}; };
const timeOptions = Array.from({length: 48}, (_, i) => {
const hours = String(Math.floor(i / 2)).padStart(2, "0");
const minutes = i % 2 === 0 ? "00" : "30";
return `${hours}:${minutes}`;
});
const selectedTimeStart = ref(
`${form.value.startDate.getHours().toString().padStart(2, "0")}:${form.value.startDate
.getMinutes()
.toString()
.padStart(2, "0")}`
);
const selectedTimeEnd = ref(
`${form.value.endDate.getHours().toString().padStart(2, "0")}:${form.value.endDate
.getMinutes()
.toString()
.padStart(2, "0")}`
);
watch(selectedTimeStart, () => {
updateStartDate()
})
watch(selectedTimeEnd, () => {
updateEndDate()
})
const updateStartDate = () => {
const [hours, minutes] = selectedTimeStart.value.split(":").map(Number);
form.value.startDate.setHours(hours, minutes);
};
const updateEndDate = () => {
const [hours, minutes] = selectedTimeStart.value.split(":").map(Number);
form.value.endDate.setHours(hours, minutes);
};
return { return {
step, step,
form, form,
@@ -359,29 +391,17 @@ export default {
isVoteCreated, isVoteCreated,
resetForm, resetForm,
rules, rules,
errorMessage errorMessage,
timeOptions,
selectedTimeStart,
selectedTimeEnd
}; };
}, },
}; };
</script> </script>
<style> <style>
.t-datetime-picker { .v-input--horizontal .v-input__prepend {
.v-tabs-slider-wrapper { margin-inline-end: 4px;
top: 0;
}
.v-picker__title {
height: 90px;
}
.v-time-picker-title__time * {
font-size: 60px;
height: 60px;
}
.v-picker__body {
height: 290px;
}
.v-tabs-items {
height: 380px;
}
} }
</style> </style>
-16
View File
@@ -93,22 +93,6 @@ async function getVotes(status) {
} }
} }
// getVotes('completed')
// .then(data => {
// console.log('Завершённые голосования:', data);
// })
// .catch(err => {
// console.error('Ошибка:', err);
// });
// getVotes('active')
// .then(data => {
// console.log('Активные голосования:', data);
// })
// .catch(err => {
// console.error('Ошибка:', err);
// });
async function createVote(voteData, files) { async function createVote(voteData, files) {
try { try {
const formData = new FormData(); const formData = new FormData();