Merge branch 'dev-denzel' into develop

This commit is contained in:
Nukeap committed 2025-01-21 09:26:10 +03:00
commit 84382c9495
5 files changed
+139 -127

No files matched your search

+1 -2
View File
@@ -104,7 +104,6 @@ export default {
if (distance <= 1) { if (distance <= 1) {
clearInterval(timer) clearInterval(timer)
setTimeout(()=>countDown(),1000) setTimeout(()=>countDown(),1000)
return return
} }
@@ -118,7 +117,7 @@ export default {
displayMinutes.value = minutesOf < 10 ? "0" + minutesOf : minutesOf displayMinutes.value = minutesOf < 10 ? "0" + minutesOf : minutesOf
displaySeconds.value = secondsOf < 10 ? "0" + secondsOf : secondsOf displaySeconds.value = secondsOf < 10 ? "0" + secondsOf : secondsOf
}, 1000) })
} }
countDown() countDown()
@@ -60,7 +60,6 @@
<v-btn v-if="user.id === voteCard.author || user.is_superuser" color="error" size="medium" @click="youSure=true"> <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-icon>mdi-delete</v-icon>
<v-dialog v-model="youSure" width="500"> <v-dialog v-model="youSure" width="500">
<v-card class="flex" max-width="450"> <v-card class="flex" max-width="450">
<v-btn <v-btn
class="align-self-end ma-2 text-red" class="align-self-end ma-2 text-red"
+27 -15
View File
@@ -1,12 +1,11 @@
<template> <template>
<v-container> <v-container>
<v-row> <v-row>
<v-col cols="12"> <v-col cols="12">
<v-card class="mb-4" outlined> <v-card class="mb-4" outlined>
<v-card-title>Победитель: {{ winner.name }}</v-card-title> <v-card-title>Победитель: {{ winner?.employee.fio || 'Нет данных' }}</v-card-title>
<v-card-subtitle> <v-card-subtitle>
Количество голосов: {{ winner.votes }} Количество голосов: {{ winner?.count || 0 }}
</v-card-subtitle> </v-card-subtitle>
</v-card> </v-card>
</v-col> </v-col>
@@ -15,12 +14,16 @@
<v-row> <v-row>
<v-col cols="12"> <v-col cols="12">
<v-card class="mb-4" outlined> <v-card class="mb-4" outlined>
<v-card-title>Все результаты</v-card-title> <v-card-title>Топ 5</v-card-title>
<v-card-text> <v-card-text>
<v-list> <v-list>
<v-list-item v-for="(option, index) in sortedResults" :key="index"> <v-list-item v-for="(answer, index) in topResults" :key="index">
<p> <p>
<strong>{{ option.name }}</strong>: {{ option.votes }} голосов <strong>{{ answer.employee.fio }}</strong>: {{ answer.count }} голосов
<br />
<small>Отдел: {{ answer.employee.department }}</small>
<br />
<small>Должность: {{ answer.employee.post }}</small>
</p> </p>
</v-list-item> </v-list-item>
</v-list> </v-list>
@@ -37,26 +40,35 @@ import { computed } from 'vue';
export default { export default {
name: 'VoteResult', name: 'VoteResult',
props: { props: {
results: { data: {
type: Array, type: Object,
required: true, required: true,
default: () => [] },
}
}, },
setup(props) { setup(props) {
// Получаем список ответов
const answers = computed(() => props.data.questions[0]?.answers || []);
// Находим победителя
const winner = computed(() => { const winner = computed(() => {
return props.results.reduce((max, option) => (option.votes > max.votes ? option : max), { name: '', votes: 0 }); return answers.value.reduce(
(max, answer) => (answer.count > max.count ? answer : max),
{count: 0, employee: {fio: '', department: '', post: ''}}
);
}); });
const sortedResults = computed(() => { // Сортируем результаты и выбираем топ-5
return [...props.results].sort((a, b) => b.votes - a.votes); const topResults = computed(() => {
return [...answers.value]
.sort((a, b) => b.count - a.count)
.slice(0, 5); // Берем первые 5 элементов
}); });
return { return {
winner, winner,
sortedResults topResults,
}; };
} },
}; };
</script> </script>
+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 { export {
axiosApiInstance, axiosApiInstance,
@@ -200,5 +210,6 @@ export {
updateVote, updateVote,
patchVote, patchVote,
deleteVote, deleteVote,
getEmployees getEmployees,
getVoteResult
} }
+99 -108
View File
@@ -1,44 +1,42 @@
<template> <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-row class="flex-column">
<v-col cols="auto"> <v-col cols="auto">
<v-tabs <v-tabs
align="center" v-model="currentTab"
v-model="currentTab"> align="center">
<v-tab <v-tab v-for="x in tabs" :key="x.value" :value="x.value">{{ x.text }}</v-tab>
</v-tabs>
v-for="x in tabs" :key="x.value" :value="x.value">{{ x.text }}</v-tab> </v-col>
<v-col class="overflow-auto pa-0">
</v-tabs> <v-window v-model="currentTab" class=" h-100">
</v-col> <!-- Текущие голосования -->
<v-col class="overflow-auto pa-0"> <v-tabs-window-item v-for="x in ['active','completed']" :value="x" class="h-100 overflow-auto">
<v-window v-model="currentTab" class=" h-100" > <v-row class="mx-2">
<!-- Текущие голосования --> <v-col
<!-- <v-tabs-window v-model="currentTab"> --> v-for="voting in sortedVotes"
<!-- Текущие голосования --> :key="voting.id"
<v-tabs-window-item v-for="x in ['active','completed']" :value="x" class="h-100 overflow-auto"> cols="12"
<v-row class="mx-2"> lg="3"
<v-col md="4"
v-for="voting in sortedVotes" >
:key="voting.id" <VoteCardVue
cols="12" :isFinished="currentTab==='active'"
lg="3" :voteCard="voting"
md="4" @deleteVoting="deleteVoting"
> @openEditVoteModal="(voting) => openModal('edit', voting)"
<VoteCardVue @openResultModal="(voting) => openModal('results', voting)"
:isFinished="currentTab=='active'" @openVoteModal="(voting) => openModal('vote', voting)"
:voteCard="voting" />
@openVoteModal="(voting) => openModal('vote', voting)" </v-col>
@openEditVoteModal="(voting) => openModal('edit', voting)" </v-row>
@openResultModal="(voting) => openModal('results', voting)" </v-tabs-window-item>
@deleteVoting="deleteVoting"
/>
</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-window>
<!-- Конструктор --> <!-- Конструктор -->
<v-tabs-window-item value="constructor" class=""> <v-tabs-window-item value="constructor" class="">
@@ -53,75 +51,64 @@
<CurrentVote :data="res" @closer="closeModal"/> <CurrentVote :data="res" @closer="closeModal"/>
</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-dialog v-model="resultsModal" max-width="1200px" @click:outside="closeModal">
<v-card>
<v-dialog v-model="editVoteModal" max-width="1200px" @click:outside="closeModal"> <v-card-title>Результаты голосования: {{ selectedVoting?.title }}</v-card-title>
<v-card> <v-card-text>
<v-card-title>Редактировать голосование: {{ selectedVoting?.title }}</v-card-title> <VoteResult :data="result"/>
<v-card-text> </v-card-text>
<VoteConstructor /> <v-card-actions>
</v-card-text> <v-btn @click="closeModal">Закрыть</v-btn>
<v-card-actions> </v-card-actions>
<v-btn color="teal-darken-4">Сохранить</v-btn> </v-card>
<v-btn @click="closeModal">Закрыть</v-btn> </v-dialog>
</v-card-actions> </v-col>
</v-card> </v-row>
</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-container> </v-container>
</template> </template>
<script> <script>
import { ref, computed, watch } from "vue"; import {computed, ref, watch} from "vue";
import VoteConstructor from "@/components/vote/VoteConstructor.vue"; import VoteConstructor from "@/components/vote/VoteConstructor.vue";
import CurrentVote from "@/components/vote/CurrentVote.vue"; import CurrentVote from "@/components/vote/CurrentVote.vue";
import VoteCardVue from "@/components/vote/VoteCard.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 VoteResult from "@/components/vote/VoteResult.vue";
import { deleteVote, getVoteDetail, getVotes } from "@/utils/axios-api"; import {deleteVote, getVoteDetail, getVoteResult, getVotes} from "@/utils/axios-api";
import { formatDate } from "@vueuse/shared"; import {formatDate} from "@vueuse/shared";
export default { export default {
methods: { formatDate }, methods: {formatDate},
components: { CurrentVote, VoteConstructor, VoteCardVue, VoteResult }, components: {CurrentVote, VoteConstructor, VoteCardVue, VoteResult},
setup() { setup() {
const tabs=[ const tabs = [
{value:"active", text:'Текущие голосования'}, {value: "active", text: 'Текущие голосования'},
{value:"completed", text:'Завершенные голосования'}, {value: "completed", text: 'Завершенные голосования'},
{value:"constructor", text:'Создать новое голосование'}, {value: "constructor", text: 'Создать новое голосование'},
]
]
const testResults = [
{name: 'Дональд Трамп', votes: 99},
{name: 'Иван Иванов', votes: 30},
{name: 'Аркадий Упукник', votes: 95},
];
const currentTab = ref("active"); const currentTab = ref("active");
const votes = ref([]); const votes = ref([]);
const router = useRouter(); const router = useRouter();
const route = useRoute(); const route = useRoute();
const res = ref(null); const res = ref(null);
const result = ref(null);
const updating = async (param) => { const updating = async (param) => {
const data = await getVotes(param); const data = await getVotes(param);
@@ -135,13 +122,9 @@ export default {
const resultsModal = ref(false); const resultsModal = ref(false);
const selectedVoting = ref(null); const selectedVoting = ref(null);
const sortedVotes = computed(() =>{ const sortedVotes = computed(() => currentTab.value === 'active' ? votes.value.sort((a, b) =>
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)) 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) => { const loadVoteDetails = async (id) => {
try { try {
@@ -153,28 +136,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 = () => { const closeModal = () => {
voteModal.value = false; voteModal.value = false;
editVoteModal.value = false; editVoteModal.value = false;
resultsModal.value = false; resultsModal.value = false;
selectedVoting.value = null; selectedVoting.value = null;
router.push({ name: "VoteHomePage" }); router.push({name: "VoteHomePage"});
updating("active");
}; };
const openModal = async (type, voting) => { const openModal = async (type, voting) => {
selectedVoting.value = voting; selectedVoting.value = voting;
if (type === "vote") { if (type === "vote") {
await loadVoteDetails(voting.id); await loadVoteDetails(voting.id);
voteModal.value = true; voteModal.value = true;
router.push({ name: "Voting", params: { id: voting.id } }); router.push({name: "Voting", params: {id: voting.id}});
} else if (type === "edit") { } else if (type === "edit") {
editVoteModal.value = true; editVoteModal.value = true;
router.push({ name: "EditVote", params: { id: voting.id } }); router.push({name: "EditVote", params: {id: voting.id}});
} else if (type === "results") { } else if (type === "results") {
await loadVoteResult(voting.id);
resultsModal.value = true; resultsModal.value = true;
router.push({ name: "VoteResults", params: { id: voting.id } }); router.push({name: "VoteResults", params: {id: voting.id}});
} }
}; };
@@ -186,12 +178,8 @@ export default {
console.error("Ошибка при удалении голосования:", error); console.error("Ошибка при удалении голосования:", error);
} }
}; };
watch(currentTab,
async () =>{
votes.value=[] watch(currentTab,async () => await updating(currentTab.value))
await updating(currentTab.value)}
)
watch( watch(
() => route, () => route,
@@ -203,11 +191,14 @@ export default {
voteModal.value = true; voteModal.value = true;
} }
if (route.name === "EditVote") editVoteModal.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; selectedVoting.value = voting || null;
} }
}, },
{ immediate: true } {immediate: true}
); );
updating("active"); updating("active");
@@ -216,7 +207,6 @@ export default {
currentTab, currentTab,
votes, votes,
sortedVotes, sortedVotes,
testResults,
voteModal, voteModal,
editVoteModal, editVoteModal,
resultsModal, resultsModal,
@@ -226,7 +216,8 @@ export default {
deleteVoting, deleteVoting,
updating, updating,
res, res,
tabs tabs,
result
}; };
}, },
}; };