This commit is contained in:
Alex committed 2025-01-14 13:41:15 +03:00
1 parent a851885bcf
commit 29e11dedae
4 files changed
+40 -92

No files matched your search

+3 -4
View File
@@ -40,13 +40,12 @@ import { computed, ref } from 'vue'
export default { export default {
props: { props: {
endTime: { endTime: {
type: Date, type: String,
default: () => { return new Date.setFullYear() } default: () => { return new Date(props.endTime).setFullYear() }
} }
}, },
setup(props) { setup(props) {
const seconds = 1000 const seconds = 1000
const displayMinutes = ref(0); const displayMinutes = ref(0);
const displayHours = ref(0); const displayHours = ref(0);
@@ -73,7 +72,7 @@ export default {
function countDown() { function countDown() {
const timer = setInterval(() => { const timer = setInterval(() => {
const date = new Date() const date = new Date()
const distance = props.endTime.getTime() - date.getTime() const distance = new Date(props.endTime).getTime() - date.getTime()
if (distance < 0) { if (distance < 0) {
clearInterval(timer) clearInterval(timer)
+10 -9
View File
@@ -1,27 +1,27 @@
<template> <template>
<v-card> <v-card>
<v-card-text class="d-flex justify-space-between ga-3 text-h6"> {{ voteCard.title }} <v-card-text class="d-flex justify-space-between ga-3 text-h6"> {{ voteCard.name }}
<v-btn flat size="medium"> <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.subtitle }}</v-card-text> <v-card-text class="text-body-1">{{ voteCard.description }}</v-card-text>
<TimerUI :endTime="voteCard.dateend" /> <TimerUI :endTime="voteCard.dateend" />
<v-card-actions class="justify-space-between"> <v-card-actions class="justify-space-between">
<v-btn <v-btn
v-if="!voteCard.voted" v-if="!voteCard.is_passed"
color="teal-darken-4" color="teal-darken-4"
prepend-icon="mdi-vote-outline" prepend-icon="mdi-vote-outline"
variant="outlined" variant="outlined"
rounded="xl" rounded="xl"
size="medium" size="medium"
class="pa-2" class="pa-2"
@click="openVoteModal(voting)"> @click="$emit('openVoteModal', voteCard)">
Проголосовать Проголосовать
</v-btn> </v-btn>
<v-btn v-else color="teal-darken-4" disabled size="medium">Уже проголосовали</v-btn> <v-btn v-else color="teal-darken-4" disabled size="medium">Уже проголосовали</v-btn>
<v-btn color="error" @click="deleteVoting(voting.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>
</v-card-actions> </v-card-actions>
@@ -33,17 +33,18 @@ import TimerUI from '../secret/TimerUI.vue';
export default { export default {
components: { TimerUI }, components: { TimerUI },
emits: ['openVoteModal', 'openEditVoteModal', 'deleteVoting'],
props: { props: {
voteCard: { voteCard: {
type: Object, type: Object,
default: () => { default: () => {
return { return {
id: 0, id: 0,
title: "Допустим, здесь могла быть ваша реклама", name: "Допустим, здесь могла быть ваша реклама",
subtitle: "Но таких денег у вас нет, чтобы получить ее на нашем прекрасном голосовании", 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),
voted: false, is_passed: false,
} }
} }
} }
@@ -249,10 +249,11 @@
<script> <script>
import {computed, ref} from "vue"; import {computed, ref} from "vue";
import {createVote, getVotes} from "@/utils/axios-api"; import { createVote } from "@/utils/axios-api";
export default { export default {
setup() { emits: ['updating'],
setup(props, {emit}) {
const step = ref(0); const step = ref(0);
const isVoteCreated = ref(false); const isVoteCreated = ref(false);
const form = ref({ const form = ref({
@@ -317,13 +318,7 @@ export default {
const response = await createVote(form.value); const response = await createVote(form.value);
console.log("Голосование успешно создано:", response); console.log("Голосование успешно создано:", response);
isVoteCreated.value = true; isVoteCreated.value = true;
getVotes('active') emit('updating', 'active')
.then(data => {
console.log('Активные голосования:', data);
})
.catch(err => {
console.error('Ошибка:', err);
});
} catch (error) { } catch (error) {
console.error("Ошибка при создании голосования:", error); console.error("Ошибка при создании голосования:", error);
} }
+23 -70
View File
@@ -17,39 +17,9 @@
<v-tabs-window-item value="current"> <v-tabs-window-item value="current">
<v-container> <v-container>
<v-row> <v-row>
<v-col <v-col v-for="voting in sortedCurrentVotes" :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"/>
<!-- <v-card :class="{ 'voted-card': voting.voted }">
<v-card-title class="d-flex justify-space-between">{{ voting.title }}
<v-btn flat size="medium" @click="openEditVoteModal(voting)">
<v-icon color="orange-lighten-1">mdi-pencil</v-icon>
</v-btn>
</v-card-title>
<v-card-subtitle>
Окончание: {{ formatDate(voting.endDate) }}
</v-card-subtitle>
<v-card-text>
Осталось: {{ timeRemaining(voting.endDate) }}
</v-card-text>
<v-card-actions class="justify-space-between">
<v-btn
v-if="!voting.voted"
color="teal-darken-4"
size="medium"
@click="openVoteModal(voting)"
>
Проголосовать
</v-btn>
<v-btn v-else color="teal-darken-4" disabled size="medium">Проголосовали</v-btn>
<v-btn color="error" size="medium" @click="deleteVoting(voting.id)">
<v-icon>mdi-delete</v-icon>
</v-btn>
</v-card-actions>
</v-card> -->
</v-col> </v-col>
</v-row> </v-row>
</v-container> </v-container>
@@ -59,11 +29,7 @@
<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 sortedCompletedVotes" :key="voting.id" cols="12" lg="3" md="4">
v-for="voting in sortedCompletedVotes"
:key="voting.id"
cols="12" lg="3" md="4"
>
<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>
@@ -85,7 +51,7 @@
<!-- Конструктор --> <!-- Конструктор -->
<v-tabs-window-item value="constructor"> <v-tabs-window-item value="constructor">
<VoteConstructor/> <VoteConstructor @updating="updating" />
</v-tabs-window-item> </v-tabs-window-item>
</v-tabs-window> </v-tabs-window>
@@ -99,13 +65,8 @@
</v-btn> </v-btn>
</v-card-actions> </v-card-actions>
<v-card-text class="pt-0"> <v-card-text class="pt-0">
<CurrentVote <CurrentVote :description="votingData.description" :endDate="votingData.endDate"
:description="votingData.description" :questions="votingData.questions" :startDate="votingData.startDate" :title="votingData.title" />
: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>
@@ -116,7 +77,7 @@
<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> -->
<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>
@@ -141,36 +102,27 @@
</template> </template>
<script> <script>
import {computed, ref} from "vue"; import { computed, ref } 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 {votingData} from '@/test/testDataForVote' import { getVotes } from "@/utils/axios-api"
import { votingData } from "@/test/testDataForVote"
export default { export default {
components: {CurrentVote, VoteConstructor, VoteCardVue}, components: { CurrentVote, VoteConstructor, VoteCardVue },
setup() { setup() {
const currentTab = ref("current"); const currentTab = ref("current");
const votes = ref([ const votes = ref([])
{
id: 1, function updating(param) {
title: "Голосование 1", getVotes(param)
dateend: new Date(new Date().getTime() + 600000), // 10 минут .then(data => {
voted: false, votes.value = data.votes;
}, })
{ }
id: 2,
title: "Голосование 2", updating('active')
dateend: new Date(new Date().getTime() - 600000), // Уже завершено
voted: true,
},
{
id: 3,
title: "Голосование 3",
dateend: new Date(new Date().getTime() + 3600000), // 1 час
voted: true,
},
]);
const voteModal = ref(false); const voteModal = ref(false);
const editVoteModal = ref(false); const editVoteModal = ref(false);
@@ -255,6 +207,7 @@ export default {
editVoteModal, editVoteModal,
openEditVoteModal, openEditVoteModal,
closeEditVoteModal, closeEditVoteModal,
updating
}; };
}, },
}; };