Merge branch 'develop' into Vit

This commit is contained in:
Nukeap committed 2025-01-21 11:25:32 +03:00
commit d1796bd1d8
6 files changed
+216 -194

No files matched your search

+6 -7
View File
@@ -3,9 +3,9 @@
<v-card variant="text"
:disabled="disabledcard.disabled"
class="py-2 mx-auto">
<v-card-title class="text-body-1">
До {{ disabledcard.text }} голосования осталось:
<v-card-title class="text-body-1">
До {{ disabledcard.text }} голосования осталось:
</v-card-title>
<v-row no-gutters class="align-baseline">
<v-col class="text-center">
@@ -60,7 +60,7 @@ export default {
const displayDays = ref(0);
const displaySeconds = ref(0);
const isFinished = ref(false);
const minutes = computed(() => seconds * 60);
const hours = computed(() => minutes.value * 60);
@@ -104,7 +104,6 @@ export default {
if (distance <= 1) {
clearInterval(timer)
setTimeout(()=>countDown(),1000)
return
}
@@ -118,7 +117,7 @@ export default {
displayMinutes.value = minutesOf < 10 ? "0" + minutesOf : minutesOf
displaySeconds.value = secondsOf < 10 ? "0" + secondsOf : secondsOf
}, 1000)
})
}
countDown()
@@ -131,7 +130,7 @@ export default {
declOfNum,
dateendorStart,
disabledcard,
};
}
}
@@ -15,7 +15,6 @@
</v-btn>
</v-col>
</v-col>
</v-row>
</v-col>
<div class="d-flex flex-column flex-fill ">
@@ -31,7 +30,6 @@
</v-stepper-item>
</template>
</v-stepper-header>
<v-stepper-window class="d-flex flex-column flex-fill">
<v-stepper-window-item v-for="(question, index) in data.questions" :key="question.numb"
:step="question.numb"
@@ -47,9 +45,14 @@
</div>
<div class="v-col-6" style="max-height:50vh">
<v-list v-model:selected="result[question.id]" density="compact" select-strategy="leaf" slim style="max-height: 100%; overflow-y: auto;">
<v-list-item v-for="answer in question.answers" :key="answer.id" :value="answer.id"
density="compact">
{{ answer.name }}
<v-list-item
v-for="answer in question.answers"
:key="answer.id"
:value="answer.id"
:disabled="result[question.id].length >= question.settings.multiChoice && !result[question.id].includes(answer.id)"
density="compact"
>
{{ answer.employee?.fio || answer.name }}
<template v-slot:prepend="{ isSelected }">
<v-list-item-action start>
<v-checkbox-btn :model-value="isSelected"></v-checkbox-btn>
@@ -60,13 +63,10 @@
</template>
</v-list-item>
</v-list>
</div>
</v-row>
</div>
<!-- Действия -->
<v-card-actions class="">
</v-card-actions>
</v-stepper-window-item>
</v-stepper-window>
+13 -10
View File
@@ -4,14 +4,15 @@
<v-tooltip bottom>
<template v-slot:activator="{ props }">
<span
v-bind="props"
style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;"
v-bind="props">
{{ voteCard.name }}
</span>
</template>
<span>{{ voteCard.name }}</span>
</v-tooltip>
<v-btn v-if="user.id === voteCard.author || user.is_superuser" flat size="medium" @click="$emit('openEditVoteModal', voteCard)">
<v-btn v-if="user.id === voteCard.author || user.is_superuser" flat size="medium"
@click="$emit('openEditVoteModal', voteCard)">
<v-icon color="orange-lighten-1">mdi-pencil</v-icon>
</v-btn>
</v-card-text>
@@ -33,17 +34,20 @@
<v-tooltip bottom>
<template v-slot:activator="{ props }">
<span
v-bind="props"
style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;"
v-bind="props">
{{ voteCard.description }}
</span>
</template>
<span>{{ voteCard.description }}</span>
</v-tooltip>
</v-card-text>
<Timer v-if ="!isFinished" :voteTime="{ dateend: voteCard.dateend, datestart: voteCard.datestart }"
<Timer v-if="!isFinished" :voteTime="{ dateend: voteCard.dateend, datestart: voteCard.datestart }"
@changeBtn="(time) => timeChange = time"/>
<div class="font-weight-bold text-center" v-else> Завершено: {{ new Date(voteCard.dateend).toLocaleDateString() }}</div>
<div v-else class="font-weight-bold text-center"> Завершено: {{
new Date(voteCard.dateend).toLocaleDateString()
}}
</div>
<v-card-actions class="justify-space-between mt-4 pb-2">
<template v-if="!isFinished">
<v-btn :disabled="voteCard.is_passed || timeChange" color="teal-darken-4" prepend-icon="mdi-vote-outline"
@@ -60,7 +64,6 @@
<v-btn v-if="user.id === voteCard.author || user.is_superuser" color="error" size="medium" @click="youSure=true">
<v-icon>mdi-delete</v-icon>
<v-dialog v-model="youSure" width="500">
<v-card class="flex" max-width="450">
<v-btn
class="align-self-end ma-2 text-red"
@@ -103,8 +106,8 @@ export default {
components: {Timer},
emits: ['openVoteModal', 'openEditVoteModal', 'deleteVoting', 'openResultModal'],
props: {
isFinished:{
type:Boolean,
isFinished: {
type: Boolean,
default: false
},
voteCard: {
+66 -46
View File
@@ -1,67 +1,87 @@
<template>
<v-container>
<v-tabs v-model="activeTab" class="mb-4">
<v-tab v-for="(question, questionIndex) in questions" :key="questionIndex">
Опрос {{ question.numb }}: {{ question.name || 'Без названия' }}
</v-tab>
</v-tabs>
<v-row>
<v-col cols="12">
<v-card class="mb-4" outlined>
<v-card-title>Победитель: {{ winner.name }}</v-card-title>
<v-card-subtitle>
Количество голосов: {{ winner.votes }}
</v-card-subtitle>
</v-card>
</v-col>
</v-row>
<v-tabs-window v-model="activeTab">
<v-tabs-window-item v-for="(question, questionIndex) in questions" :key="questionIndex">
<v-row>
<!-- Победитель -->
<v-col cols="12">
<v-card-title class="d-flex ga-2 align-center">
<h4 class="text-teal-darken-4">Победитель:</h4>
<h3>{{ getWinner(question).employee?.fio || getWinner(question).name }} 🏆</h3>
</v-card-title>
<v-card-subtitle>
Количество голосов: {{ getWinner(question)?.count || 0 }}
</v-card-subtitle>
</v-col>
<v-row>
<v-col cols="12">
<v-card class="mb-4" outlined>
<v-card-title>Все результаты</v-card-title>
<v-card-text>
<v-list>
<v-list-item v-for="(option, index) in sortedResults" :key="index">
<p>
<strong>{{ option.name }}</strong>: {{ option.votes }} голосов
</p>
</v-list-item>
</v-list>
</v-card-text>
</v-card>
</v-col>
</v-row>
<!-- Топ 10 -->
<v-col cols="12">
<v-card class="mb-4">
<v-card-title class="text-teal-darken-3">Топ 10</v-card-title>
<v-card-text>
<v-list style="max-height: 40vh; overflow-y: auto;">
<v-list-item
v-for="(answer, answerIndex) in getTopResults(question)"
:key="answerIndex"
>
<p>
<strong>{{ answer.employee ? answer.employee.fio : answer.name }}</strong>: {{ answer.count }} голосов
<template v-if="answer.employee">
<br />
<small>Отдел: {{ answer.employee ? answer.employee.department : '' }}</small>
<br />
<small>Должность: {{ answer.employee ? answer.employee.post : '' }}</small>
</template>
</p>
</v-list-item>
</v-list>
</v-card-text>
</v-card>
</v-col>
</v-row>
</v-tabs-window-item>
</v-tabs-window>
</v-container>
</template>
<script>
import { computed } from 'vue';
import { computed, ref } from 'vue';
export default {
name: 'VoteResult',
props: {
results: {
type: Array,
data: {
type: Object,
required: true,
default: () => []
}
},
},
setup(props) {
const winner = computed(() => {
return props.results.reduce((max, option) => (option.votes > max.votes ? option : max), { name: '', votes: 0 });
});
const activeTab = ref(0);
const questions = computed(() => props.data.questions || []);
const sortedResults = computed(() => {
return [...props.results].sort((a, b) => b.votes - a.votes);
});
const getWinner = (question) => {
return question.answers.reduce(
(max, answer) => (answer.count > max.count ? answer : max),
{count: 0, employee: {fio: '', department: '', post: ''}, name: ''}
);
};
const getTopResults = (question) => {
return [...question.answers].sort((a, b) => b.count - a.count).slice(0, 10);
};
return {
winner,
sortedResults
activeTab,
questions,
getWinner,
getTopResults,
};
}
},
};
</script>
<style scoped>
h1 {
margin-bottom: 20px;
}
</style>
+12 -1
View File
@@ -186,6 +186,16 @@ async function getEmployees() {
}
}
async function getVoteResult(id) {
try {
const response = await axiosApiInstance.get(`/api/vote/getresults/?id=${id}`);
return response.data;
} catch (error) {
console.error("Ошибка получения результата голосования:", error);
throw error;
}
}
export {
axiosApiInstance,
@@ -200,5 +210,6 @@ export {
updateVote,
patchVote,
deleteVote,
getEmployees
getEmployees,
getVoteResult
}
+110 -121
View File
@@ -1,127 +1,112 @@
<template>
<v-container fluid class="pt-2 d-flex flex-column">
<v-container class="pt-2 d-flex flex-column" fluid>
<v-row class="flex-column">
<v-col cols="auto">
<v-tabs
align="center"
v-model="currentTab">
<v-tab
v-for="x in tabs" :key="x.value" :value="x.value">{{ x.text }}</v-tab>
</v-tabs>
</v-col>
<v-col class="overflow-auto pa-0">
<v-window v-model="currentTab" class=" h-100" >
<!-- Текущие голосования -->
<!-- <v-tabs-window v-model="currentTab"> -->
<!-- Текущие голосования -->
<v-tabs-window-item v-for="x in ['active','completed']" :value="x" class="h-100 overflow-auto">
<v-row class="mx-2">
<v-col
v-for="voting in sortedVotes"
:key="voting.id"
cols="12"
lg="3"
md="4"
>
<VoteCardVue
:isFinished="currentTab=='active'"
:voteCard="voting"
@openVoteModal="(voting) => openModal('vote', voting)"
@openEditVoteModal="(voting) => openModal('edit', voting)"
@openResultModal="(voting) => openModal('results', voting)"
@deleteVoting="deleteVoting"
/>
</v-col>
</v-row>
</v-tabs-window-item>
<v-tabs
v-model="currentTab"
align="center">
<v-tab v-for="x in tabs" :key="x.value" :value="x.value">{{ x.text }}</v-tab>
</v-tabs>
</v-col>
<v-col class="overflow-auto pa-0">
<v-window v-model="currentTab" class=" h-100">
<!-- Текущие голосования -->
<v-tabs-window-item v-for="x in ['active','completed']" :value="x" class="h-100 overflow-auto">
<v-row class="mx-2">
<v-col
v-for="voting in sortedVotes"
:key="voting.id"
cols="12"
lg="3"
md="4"
>
<VoteCardVue
:isFinished="currentTab==='active'"
:voteCard="voting"
@deleteVoting="deleteVoting"
@openEditVoteModal="(voting) => openModal('edit', voting)"
@openResultModal="(voting) => openModal('results', voting)"
@openVoteModal="(voting) => openModal('vote', voting)"
/>
</v-col>
</v-row>
</v-tabs-window-item>
<!-- Завершенные голосования -->
<!-- Конструктор -->
<v-tabs-window-item class="h-100 overflow-auto bg-yellow" value="constructor">
<VoteConstructor @updating="updating"/>
</v-tabs-window-item>
<!-- Конструктор -->
<v-tabs-window-item class="h-100 overflow-auto" value="constructor">
<VoteConstructor @updating="updating"/>
</v-tabs-window-item>
<!-- </v-tabs-window> -->
</v-window>
<!-- Модальные окна -->
<v-dialog v-model="voteModal" @click:outside="closeModal">
<!-- Конструктор -->
<v-tabs-window-item value="constructor" class="h-100 overflow-auto">
<VoteConstructor @updating="updating" />
</v-tabs-window-item>
<!-- </v-tabs-window> -->
</v-window>
<!-- Модальные окна -->
<v-dialog v-model="voteModal" @click:outside="closeModal">
<CurrentVote :data="res" @closer="closeModal"/>
</v-dialog>
</v-dialog>
<v-dialog v-model="editVoteModal" max-width="1200px" @click:outside="closeModal">
<v-card>
<v-card-title>Редактировать голосование: {{ selectedVoting?.title }}</v-card-title>
<v-card-text>
<VoteConstructor />
</v-card-text>
<v-card-actions>
<v-btn color="teal-darken-4">Сохранить</v-btn>
<v-btn @click="closeModal">Закрыть</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
<v-dialog v-model="editVoteModal" max-width="1200px" @click:outside="closeModal">
<v-card>
<v-card-title>Редактировать голосование: {{ selectedVoting?.title }}</v-card-title>
<v-card-text>
<VoteConstructor/>
</v-card-text>
<v-card-actions>
<v-btn color="teal-darken-4">Сохранить</v-btn>
<v-btn @click="closeModal">Закрыть</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
<v-dialog v-model="resultsModal" max-width="1200px" @click:outside="closeModal">
<v-card>
<v-card-title>Результаты голосования: {{ selectedVoting?.title }}</v-card-title>
<v-card-text>
<VoteResult :results="testResults"/>
</v-card-text>
<v-card-actions>
<v-btn @click="closeModal">Закрыть</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</v-col>
</v-row>
<v-dialog v-model="resultsModal" max-width="1200px" @click:outside="closeModal">
<v-card>
<v-card-title>Результаты голосования: {{ selectedVoting?.title }}</v-card-title>
<VoteResult :data="result"/>
<v-card-actions>
<v-btn @click="closeModal">Закрыть</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</v-col>
</v-row>
</v-container>
</template>
<script>
import { ref, computed, watch } from "vue";
import {computed, ref, watch} from "vue";
import VoteConstructor from "@/components/vote/VoteConstructor.vue";
import CurrentVote from "@/components/vote/CurrentVote.vue";
import VoteCardVue from "@/components/vote/VoteCard.vue";
import { useRoute, useRouter } from "vue-router";
import {useRoute, useRouter} from "vue-router";
import VoteResult from "@/components/vote/VoteResult.vue";
import { deleteVote, getVoteDetail, getVotes } from "@/utils/axios-api";
import { formatDate } from "@vueuse/shared";
import {deleteVote, getVoteDetail, getVoteResult, getVotes} from "@/utils/axios-api";
import {formatDate} from "@vueuse/shared";
export default {
methods: { formatDate },
components: { CurrentVote, VoteConstructor, VoteCardVue, VoteResult },
methods: {formatDate},
components: {CurrentVote, VoteConstructor, VoteCardVue, VoteResult},
setup() {
const tabs=[
{value:"active", text:'Текущие голосования'},
{value:"completed", text:'Завершенные голосования'},
{value:"constructor", text:'Создать новое голосование'},
]
const testResults = [
{name: 'Дональд Трамп', votes: 99},
{name: 'Иван Иванов', votes: 30},
{name: 'Аркадий Упукник', votes: 95},
];
const tabs = [
{value: "active", text: 'Текущие голосования'},
{value: "completed", text: 'Завершенные голосования'},
{value: "constructor", text: 'Создать новое голосование'},
]
const currentTab = ref("active");
const votes = ref([]);
const router = useRouter();
const route = useRoute();
const res = ref(null);
const result = ref(null);
const updating = async (param) => {
const data = await getVotes(param);
@@ -135,13 +120,9 @@ export default {
const resultsModal = ref(false);
const selectedVoting = ref(null);
const sortedVotes = computed(() =>{
return currentTab.value=='active'?votes.value.sort((a, b) => new Date(a.dateend) - new Date(b.dateend)):votes.value.sort((a, b) => new Date(b.dateend) - new Date(a.dateend))
}
);
const sortedVotes = computed(() => currentTab.value === 'active' ? votes.value.sort((a, b) =>
new Date(a.dateend) - new Date(b.dateend)) :
votes.value.sort((a, b) => new Date(b.dateend) - new Date(a.dateend)));
const loadVoteDetails = async (id) => {
try {
@@ -153,28 +134,37 @@ export default {
}
};
const loadVoteResult = async (id) => {
try {
const data = await getVoteResult(id);
result.value = data;
} catch (error) {
console.error("Ошибка при загрузке данных голосования:", error);
res.value = null;
}
};
const closeModal = () => {
voteModal.value = false;
editVoteModal.value = false;
resultsModal.value = false;
selectedVoting.value = null;
router.push({ name: "VoteHomePage" });
updating("active");
router.push({name: "VoteHomePage"});
};
const openModal = async (type, voting) => {
selectedVoting.value = voting;
if (type === "vote") {
await loadVoteDetails(voting.id);
voteModal.value = true;
router.push({ name: "Voting", params: { id: voting.id } });
router.push({name: "Voting", params: {id: voting.id}});
} else if (type === "edit") {
editVoteModal.value = true;
router.push({ name: "EditVote", params: { id: voting.id } });
router.push({name: "EditVote", params: {id: voting.id}});
} else if (type === "results") {
await loadVoteResult(voting.id);
resultsModal.value = true;
router.push({ name: "VoteResults", params: { id: voting.id } });
router.push({name: "VoteResults", params: {id: voting.id}});
}
};
@@ -186,12 +176,8 @@ export default {
console.error("Ошибка при удалении голосования:", error);
}
};
watch(currentTab,
async () =>{
votes.value=[]
await updating(currentTab.value)}
)
watch(currentTab, async () => await updating(currentTab.value))
watch(
() => route,
@@ -203,11 +189,14 @@ export default {
voteModal.value = true;
}
if (route.name === "EditVote") editVoteModal.value = true;
if (route.name === "VoteResults") resultsModal.value = true;
if (route.name === "VoteResults") {
await loadVoteResult(route.params.id)
resultsModal.value = true;
}
selectedVoting.value = voting || null;
}
},
{ immediate: true }
{immediate: true}
);
updating("active");
@@ -216,7 +205,6 @@ export default {
currentTab,
votes,
sortedVotes,
testResults,
voteModal,
editVoteModal,
resultsModal,
@@ -226,7 +214,8 @@ export default {
deleteVoting,
updating,
res,
tabs
tabs,
result
};
},
};