Merge branch 'Alex' into develop

This commit is contained in:
Nukeap committed 2025-01-15 09:09:36 +03:00
commit f13c245827
3 files changed
+146 -142

No files matched your search

+45 -16
View File
@@ -1,32 +1,34 @@
<template> <template>
<v-row dense class="ma-1 "> <v-row dense>
<v-card variant="text" class="py-1"> <v-card variant="text"
<v-card-title class="text-body-1"> До окончания голосования осталось: </v-card-title> :disabled="disabledcard.disabled"
class="py-1">
<v-card-title class="text-body-1"> До {{ disabledcard.text }} голосования осталось: </v-card-title>
<v-row dense class="align-baseline justify-center"> <v-row dense class="align-baseline justify-center">
<v-col cols="auto" class="text-center"> <v-col cols="2" class="text-center">
<v-card class="bg-yellow-darken-4"> <v-card class="bg-yellow-darken-4">
<v-card-title>{{ displayDays }}</v-card-title> <div>{{ displayDays }}</div>
</v-card> </v-card>
<span class="text-caption">{{ declOfNum(displayDays, [' день', ' дня', ' дней']) }}</span> <span class="text-caption">{{ declOfNum(displayDays, [' день', ' дня', ' дней']) }}</span>
</v-col> </v-col>
<v-col cols="auto">:</v-col> <v-col cols="auto">:</v-col>
<v-col cols="auto" class="text-center"> <v-col cols="2" class="text-center">
<v-card class="bg-yellow-darken-4"> <v-card class="bg-yellow-darken-4">
<v-card-title>{{ displayHours }}</v-card-title> <div>{{ displayHours }}</div>
</v-card> </v-card>
<span class="text-caption">{{ declOfNum(displayHours, [' час', ' часа', ' часов']) }}</span> <span class="text-caption">{{ declOfNum(displayHours, [' час', ' часа', ' часов']) }}</span>
</v-col> </v-col>
<v-col cols="auto">:</v-col> <v-col cols="auto">:</v-col>
<v-col cols="auto" class="text-center"> <v-col cols="2" class="text-center">
<v-card class="bg-yellow-darken-4"> <v-card class="bg-yellow-darken-4">
<v-card-title>{{ displayMinutes }}</v-card-title> <div>{{ displayMinutes }}</div>
</v-card> </v-card>
<span class="text-caption">{{ declOfNum(displayMinutes, [' минута', ' минуты', ' минут']) }}</span> <span class="text-caption">{{ declOfNum(displayMinutes, [' минута', ' минуты', ' минут']) }}</span>
</v-col> </v-col>
<v-col cols="auto">:</v-col> <v-col cols="auto">:</v-col>
<v-col cols="auto" class="text-center"> <v-col cols="2" class="text-center">
<v-card class="bg-yellow-darken-4"> <v-card class="bg-yellow-darken-4">
<v-card-title>{{ displaySeconds }}</v-card-title> <div>{{ displaySeconds }}</div>
</v-card> </v-card>
<span class="text-caption">{{ declOfNum(displaySeconds, [' секунда', ' секунды', ' секунд']) }}</span> <span class="text-caption">{{ declOfNum(displaySeconds, [' секунда', ' секунды', ' секунд']) }}</span>
</v-col> </v-col>
@@ -39,9 +41,11 @@ import { computed, ref } from 'vue'
export default { export default {
props: { props: {
endTime: { voteTime: {
type: String, type: Object,
default: () => { return new Date(props.endTime).setFullYear() } default: () => { return {dateend:new Date().setFullYear(),
datestart:new Date().setFullYear()
}}
} }
}, },
@@ -68,14 +72,37 @@ export default {
const cases = [2, 0, 1, 1, 1, 2] const cases = [2, 0, 1, 1, 1, 2]
return titles[(value % 100 > 4 && value % 100 < 20) ? 2 : cases[(value % 10 < 5) ? value % 10 : 5]] return titles[(value % 100 > 4 && value % 100 < 20) ? 2 : cases[(value % 10 < 5) ? value % 10 : 5]]
} }
const disabledcard = ref({
text: 'окончания',
disabled: false
})
const dateendorStart = ()=>{
let param = 'dateend'
if (new Date().getTime()<new Date(props.voteTime.datestart).getTime()){
param='datestart'
disabledcard.value={text: 'начала',
disabled:true
}
}else{
disabledcard.value={text: 'окончания',
disabled:false
}
}
return param
}
function countDown() { function countDown() {
const timer = setInterval(() => { const timer = setInterval(() => {
const date = new Date() const date = new Date()
const distance = new Date(props.endTime).getTime() - date.getTime() // console.log(dateendorStart.value);
const distance = new Date(props.voteTime[dateendorStart()]).getTime() - date.getTime()
if (distance < 0) { if (distance <= 1) {
clearInterval(timer) clearInterval(timer)
setTimeout(()=>countDown(),1000)
return return
} }
@@ -100,6 +127,8 @@ export default {
displayDays, displayDays,
displaySeconds, displaySeconds,
declOfNum, declOfNum,
dateendorStart,
disabledcard
} }
} }
} }
+6 -7
View File
@@ -1,16 +1,16 @@
<template> <template>
<v-card> <v-card>
<v-card-text class="d-flex justify-space-between ga-3 text-h6"> {{ voteCard.name }} <v-card-text class=" d-flex justify-space-between ga-3 text-h6"> {{ voteCard.name }}
<v-btn flat size="medium" @click="$emit('openEditVoteModal', voteCard)"> <v-btn flat size="medium" @click="$emit('openEditVoteModal', voteCard)">
<v-icon color="orange-lighten-1">mdi-pencil</v-icon> <v-icon color="orange-lighten-1">mdi-pencil</v-icon>
</v-btn> </v-btn>
</v-card-text> </v-card-text>
<v-img cover :src="voteCard.pictures" /> <v-img cover :src="voteCard.pictures" />
<v-card-text class="text-body-1">{{ voteCard.description }}</v-card-text> <v-card-text class="">{{ voteCard.description }}</v-card-text>
<TimerUI :endTime="voteCard.dateend" /> <TimerUI :voteTime="{dateend:voteCard.dateend,datestart:voteCard.datestart}" />
<v-card-actions class="justify-space-between"> <v-card-actions class="justify-space-between">
<v-btn <v-btn
v-if="!voteCard.is_passed" :disabled="voteCard.is_passed || new Date(voteCard.datestart).getTime()>new Date().getTime()"
color="teal-darken-4" color="teal-darken-4"
prepend-icon="mdi-vote-outline" prepend-icon="mdi-vote-outline"
variant="outlined" variant="outlined"
@@ -18,9 +18,8 @@
size="medium" size="medium"
class="pa-2" class="pa-2"
@click="$emit('openVoteModal', voteCard)"> @click="$emit('openVoteModal', voteCard)">
Проголосовать {{!voteCard.is_passed?"Проголосовать":"Уже проголосовали"}}
</v-btn> </v-btn>
<v-btn v-else color="teal-darken-4" disabled size="medium">Уже проголосовали</v-btn>
<v-btn color="error" @click="$emit('deleteVoting', voteCard.id)" size="medium"> <v-btn color="error" @click="$emit('deleteVoting', voteCard.id)" size="medium">
<v-icon>mdi-delete</v-icon> <v-icon>mdi-delete</v-icon>
</v-btn> </v-btn>
@@ -44,7 +43,7 @@ export default {
description: "Но таких денег у вас нет, чтобы получить ее на нашем прекрасном голосовании", description: "Но таких денег у вас нет, чтобы получить ее на нашем прекрасном голосовании",
pictures: "https://cdn.vuetifyjs.com/images/parallax/material.jpg", pictures: "https://cdn.vuetifyjs.com/images/parallax/material.jpg",
dateend: new Date(new Date().getTime() + 600000), dateend: new Date(new Date().getTime() + 600000),
is_passed: false, is_passed: true,
} }
} }
} }
+95 -119
View File
@@ -2,33 +2,24 @@
<v-container> <v-container>
<v-toolbar color="transparent"> <v-toolbar color="transparent">
<v-toolbar-title>Голосования</v-toolbar-title> <v-toolbar-title>Голосования</v-toolbar-title>
<template v-slot:extension> <template v-slot:extension>
<v-tabs v-model="currentTab"> <v-tabs v-model="currentTab">
<v-tab value="current">Текущие голосования</v-tab> <v-tab :key="0" value="active">Текущие голосования</v-tab>
<v-tab value="completed">Завершенные голосования</v-tab> <v-tab :key="1" value="completed">Завершенные голосования</v-tab>
<v-tab value="constructor">Создать новое голосование</v-tab> <v-tab :key="2" value="constructor">Создать новое голосование</v-tab>
</v-tabs> </v-tabs>
</template> </template>
</v-toolbar> </v-toolbar>
<v-tabs-window v-model="currentTab"> <v-tabs-window v-model="currentTab">
<!-- Текущие голосования --> <!-- Текущие голосования -->
<v-tabs-window-item value="current"> <v-tabs-window-item value="active">
<v-container> <v-container>
<v-row> <v-row>
<v-col <v-col v-for="voting in votes" :key="voting.id" cols="12" lg="3" md="4">
v-for="voting in sortedCurrentVotes" <VoteCardVue :voteCard="voting" @openVoteModal="openVoteModal" @openEditVoteModal="openEditVoteModal"
:key="voting.id" @deleteVoting="deleteVoting" />
cols="12"
lg="3"
md="4"
>
<VoteCardVue
:voteCard="voting"
@openVoteModal="(voting) => openModal('vote', voting)"
@openEditVoteModal="(voting) => openModal('edit', voting)"
@deleteVoting="deleteVoting"
/>
</v-col> </v-col>
</v-row> </v-row>
</v-container> </v-container>
@@ -38,21 +29,14 @@
<v-tabs-window-item value="completed"> <v-tabs-window-item value="completed">
<v-container> <v-container>
<v-row> <v-row>
<v-col <v-col v-for="voting in votes" :key="voting.id" cols="12" lg="3" md="4">
v-for="voting in sortedCompletedVotes"
:key="voting.id"
cols="12"
lg="3"
md="4"
:class="{ 'voted-card': voting.voted }"
>
<v-card> <v-card>
<v-card-title>{{ voting.title }}</v-card-title> <v-card-title>{{ voting.title }}</v-card-title>
<v-card-subtitle> <v-card-subtitle>
Завершено: {{ formatDate(voting.endDate) }} Завершено: {{ formatDate(voting.endDate) }}
</v-card-subtitle> </v-card-subtitle>
<v-card-actions class="justify-space-between"> <v-card-actions class="justify-space-between">
<v-btn color="teal-darken-4" size="medium" @click="(voting) => openModal('results', voting)"> <v-btn color="teal-darken-4" size="medium" @click="openResultsModal(voting)">
Результаты Результаты
</v-btn> </v-btn>
<v-btn color="error" size="medium" @click="deleteVoting(voting.id)"> <v-btn color="error" size="medium" @click="deleteVoting(voting.id)">
@@ -71,41 +55,46 @@
</v-tabs-window-item> </v-tabs-window-item>
</v-tabs-window> </v-tabs-window>
<!-- Модальные окна --> <!-- Модальное окно для голосования -->
<v-dialog v-model="voteModal" max-width="1200px" @click:outside="closeModal"> <v-dialog v-model="voteModal" max-width="1200px">
<v-card> <v-card>
<v-card-actions> <v-card-actions>
<v-btn color="red-darken-1" size="medium" @click="closeModal"> <!--<v-btn color="teal-darken-4" @click="submitVote">Проголосовать</v-btn>-->
<v-btn color="red-darken-1" size="medium" @click="closeVoteModal">
<v-icon>mdi-close-thick</v-icon> <v-icon>mdi-close-thick</v-icon>
</v-btn> </v-btn>
</v-card-actions> </v-card-actions>
<v-card-text class="pt-0"> <v-card-text class="pt-0">
<CurrentVote :data="res" /> <CurrentVote :description="votingData.description" :endDate="votingData.endDate"
:questions="votingData.questions" :startDate="votingData.startDate" :title="votingData.title" />
</v-card-text> </v-card-text>
</v-card> </v-card>
</v-dialog> </v-dialog>
<v-dialog v-model="editVoteModal" max-width="1200px" @click:outside="closeModal"> <!-- Модальное окно для редактирования -->
<v-dialog v-model="editVoteModal" max-width="1200px">
<v-card> <v-card>
<v-card-title>Редактировать голосование: {{ selectedVoting?.title }}</v-card-title> <v-card-title>Голосование: {{ selectedVoting?.title }}</v-card-title>
<v-card-text> <v-card-text>
<!-- <p>Редактирование голосования...</p> -->
<VoteConstructor /> <VoteConstructor />
</v-card-text> </v-card-text>
<v-card-actions> <v-card-actions>
<v-btn color="teal-darken-4">Сохранить</v-btn> <v-btn color="teal-darken-4">Сохранить</v-btn>
<v-btn @click="closeModal">Закрыть</v-btn> <v-btn @click="closeEditVoteModal">Закрыть</v-btn>
</v-card-actions> </v-card-actions>
</v-card> </v-card>
</v-dialog> </v-dialog>
<v-dialog v-model="resultsModal" max-width="1200px" @click:outside="closeModal"> <!-- Модальное окно для результатов -->
<v-dialog v-model="resultsModal" max-width="1200px">
<v-card> <v-card>
<v-card-title>Результаты голосования: {{ selectedVoting?.title }}</v-card-title> <v-card-title>Результаты голосования: {{ selectedVoting?.title }}</v-card-title>
<v-card-text> <v-card-text>
<p>Здесь отображаются результаты голосования...</p> <p>Здесь отображаются результаты голосования...</p>
</v-card-text> </v-card-text>
<v-card-actions> <v-card-actions>
<v-btn @click="closeModal">Закрыть</v-btn> <v-btn @click="closeResultsModal">Закрыть</v-btn>
</v-card-actions> </v-card-actions>
</v-card> </v-card>
</v-dialog> </v-dialog>
@@ -113,124 +102,111 @@
</template> </template>
<script> <script>
import { ref, computed, watch } from "vue"; import { 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 { getVotes } from "@/utils/axios-api"
import { deleteVote, getVoteDetail, getVotes } from "@/utils/axios-api"; import { votingData } from "@/test/testDataForVote"
import { formatDate } from "@vueuse/shared";
export default { export default {
methods: { formatDate },
components: { CurrentVote, VoteConstructor, VoteCardVue }, components: { CurrentVote, VoteConstructor, VoteCardVue },
setup() { setup() {
const currentTab = ref("current"); const currentTab = ref("active");
const votes = ref([]); const votes = ref([])
const router = useRouter();
const route = useRoute();
const res = ref(null);
const updating = async (param) => { function updating(param) {
const data = await getVotes(param); getVotes(param)
votes.value = data; .then(data => {
}; console.log(data);
votes.value = data;
})
}
updating("active"); updating('active')
watch(
() => currentTab.value,
(newValue) => {
if (newValue !== 'constructor') {
console.log(newValue);
updating(newValue)
}
}
);
const voteModal = ref(false); const voteModal = ref(false);
const editVoteModal = ref(false); const editVoteModal = ref(false);
const resultsModal = ref(false); const resultsModal = ref(false);
const selectedVoting = ref(null); const selectedVoting = ref(null);
const sortedCurrentVotes = computed(() =>
votes.value
.filter((v) => new Date(v.dateend) > new Date())
.sort((a, b) => new Date(a.dateend) - new Date(b.dateend))
);
const sortedCompletedVotes = computed(() => const timeRemaining = (dateend) => {
votes.value const now = new Date();
.filter((v) => new Date(v.dateend) <= new Date()) const diff = new Date(dateend) - now;
.sort((a, b) => new Date(b.dateend) - new Date(a.dateend)) return diff > 0 ? `${Math.floor(diff / 60000)} минут` : "Завершено";
);
const loadVoteDetails = async (id) => {
try {
const data = await getVoteDetail(id);
res.value = data;
} catch (error) {
console.error("Ошибка при загрузке данных голосования:", error);
res.value = null;
}
}; };
const closeModal = () => { const formatDate = (date) => new Date(date).toLocaleString();
const openVoteModal = (voting) => {
selectedVoting.value = voting;
voteModal.value = true;
};
const closeVoteModal = () => {
voteModal.value = false; voteModal.value = false;
selectedVoting.value = null;
};
const openEditVoteModal = (voting) => {
selectedVoting.value = voting;
editVoteModal.value = true;
};
const closeEditVoteModal = () => {
editVoteModal.value = false; editVoteModal.value = false;
selectedVoting.value = null;
};
const submitVote = () => {
selectedVoting.value.voted = true;
closeVoteModal();
};
const openResultsModal = (voting) => {
selectedVoting.value = voting;
resultsModal.value = true;
};
const closeResultsModal = () => {
resultsModal.value = false; resultsModal.value = false;
selectedVoting.value = null; selectedVoting.value = null;
router.push({ name: "VoteHomePage" });
}; };
const openModal = async (type, voting) => { const deleteVoting = (id) => {
selectedVoting.value = voting; votes.value = votes.value.filter((v) => v.id !== id);
if (type === "vote") {
await loadVoteDetails(voting.id);
voteModal.value = true;
router.push({ name: "Voting", params: { id: voting.id } });
} else if (type === "edit") {
editVoteModal.value = true;
router.push({ name: "EditVote", params: { id: voting.id } });
} else if (type === "results") {
resultsModal.value = true;
router.push({ name: "VoteResults", params: { id: voting.id } });
}
}; };
const deleteVoting = async (id) => {
try {
await deleteVote(id);
votes.value = votes.value.filter((v) => v.id !== id);
} catch (error) {
console.error("Ошибка при удалении голосования:", error);
}
};
watch(
() => route,
async () => {
if (!voteModal.value && !editVoteModal.value && !resultsModal.value) {
const voting = votes.value.find((v) => v.id === route.params.id);
if (route.name === "Voting") {
await loadVoteDetails(route.params.id);
voteModal.value = true;
}
if (route.name === "EditVote") editVoteModal.value = true;
if (route.name === "VoteResults") resultsModal.value = true;
selectedVoting.value = voting || null;
}
},
{ immediate: true }
);
updating("active");
return { return {
currentTab, currentTab,
votes, votes,
sortedCurrentVotes,
sortedCompletedVotes,
voteModal, voteModal,
editVoteModal,
resultsModal, resultsModal,
selectedVoting, selectedVoting,
openModal, timeRemaining,
closeModal, formatDate,
openVoteModal,
closeVoteModal,
submitVote,
openResultsModal,
closeResultsModal,
deleteVoting, deleteVoting,
editVoteModal,
openEditVoteModal,
closeEditVoteModal,
updating, updating,
res, votingData
}; };
}, },
}; };