Merge branch 'dev-denzel' into сja

This commit is contained in:
Cja committed 2025-01-15 16:12:18 +03:00
commit ec24d51b65
8 files changed
+209 -145

No files matched your search

+2
View File
@@ -2,3 +2,5 @@ from django.contrib import admin
from .models import * from .models import *
admin.site.register(Vote) admin.site.register(Vote)
admin.site.register(Question)
admin.site.register(Answer)
@@ -1,32 +1,34 @@
<template> <template>
<v-row dense class="ma-1 "> <v-row class="px-2">
<v-card variant="text" class="py-1"> <v-card variant="text"
<v-card-title class="text-body-1"> До окончания голосования осталось: </v-card-title> :disabled="disabledcard.disabled"
<v-row dense class="align-baseline justify-center"> class="py-2 mx-auto">
<v-col cols="auto" class="text-center"> <v-card-title class="text-body-1"> До {{ disabledcard.text }} голосования осталось: </v-card-title>
<v-row no-gutters class="align-baseline">
<v-col 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" class="px-1">:</v-col>
<v-col cols="auto" class="text-center"> <v-col 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" class="px-1">:</v-col>
<v-col cols="auto" class="text-center"> <v-col 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" class="px-1">:</v-col>
<v-col cols="auto" class="text-center"> <v-col 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,13 +41,15 @@ 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()
}}
} }
}, },
setup(props, {emit}) {
setup(props) {
const seconds = 1000 const seconds = 1000
const displayMinutes = ref(0); const displayMinutes = ref(0);
const displayHours = ref(0); const displayHours = ref(0);
@@ -68,14 +72,40 @@ 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,
}
emit('changeBtn', true)
} else {
disabledcard.value= {
text: 'окончания',
disabled: false,
}
emit('changeBtn', 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() 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 +130,8 @@ export default {
displayDays, displayDays,
displaySeconds, displaySeconds,
declOfNum, declOfNum,
dateendorStart,
disabledcard
} }
} }
} }
@@ -37,8 +37,6 @@
hide-header hide-header
@update:modelValue="dateStart" @update:modelValue="dateStart"
border border
:max="formatDash(new Date())"
:min="formatDash(appStore.countvisitor.visitdate)"
/> />
</v-locale-provider> </v-locale-provider>
+31 -22
View File
@@ -3,39 +3,40 @@
<v-stepper v-model="activeStep"> <v-stepper v-model="activeStep">
<v-card-title>{{ data.name }}</v-card-title> <v-card-title>{{ data.name }}</v-card-title>
<v-card-subtitle>{{ data.description }}</v-card-subtitle> <v-card-subtitle>{{ data.description }}</v-card-subtitle>
{{ data }}
<!-- Шаги голосования --> <!-- Шаги голосования -->
<v-stepper-header> <v-stepper-header>
<v-stepper-item <v-stepper-item
v-for="(question, index) in data.questions" v-for="question in data.questions"
:key="index" :key="question.numb"
:complete="index < activeStep" :complete="question.numb < activeStep"
:step="index + 1" :step="question.numb"
> >
Вопрос {{ index + 1 }} Вопрос {{ question.numb }}
</v-stepper-item> </v-stepper-item>
</v-stepper-header> </v-stepper-header>
<v-stepper-window> <v-stepper-window>
<v-stepper-window-item <v-stepper-window-item
v-for="(question, index) in data.questions" v-for="(question, index) in data.questions"
:key="index" :key="question.numb"
:step="index + 1" :step="question.numb"
> >
<v-card flat> <v-card flat>
<v-card-title>{{ question.question }}</v-card-title> <v-card-title>{{ question.question }}</v-card-title>
<v-card-text> <v-card-text>
<!-- Ответы на вопрос --> <!-- Ответы на вопрос -->
{{ result }}--
<v-row v-for="(answer, id) in question.answers" :key="id"> <v-row v-for="(answer, id) in question.answers" :key="id">
<v-checkbox <v-checkbox
v-model="answers[index]" v-model="result[question.id]"
:value="answer.answer" :label="answer.answer"
:value="answer.id"
color="teal-darken-4" color="teal-darken-4"
hide-details hide-details
> >
<template #label>
<span class="text-black">{{ answer.answer }}</span>
</template>
</v-checkbox> </v-checkbox>
</v-row> </v-row>
</v-card-text> </v-card-text>
@@ -94,9 +95,15 @@ export default {
const isVoteSubmitted = ref(false); const isVoteSubmitted = ref(false);
const isCurrentQuestionAnswered = computed(() => { const isCurrentQuestionAnswered = computed(() => {
return !!answers.value[activeStep.value]; let q = props.data.questions.find(e=>e.numb==activeStep.value+1)
return result.value[q.id].length>0;
}); });
const getres=()=>{
return props.data.questions.reduce((acc,item)=> {acc[item.id]=[]
return acc
},{})
}
const result=ref(getres())
const nextStep = () => { const nextStep = () => {
if (activeStep.value < props.data.questions.length - 1) { if (activeStep.value < props.data.questions.length - 1) {
activeStep.value++; activeStep.value++;
@@ -110,14 +117,15 @@ export default {
}; };
const submitVote = () => { const submitVote = () => {
const voteData = props.data.questions.map((question, index) => ({ // const voteData = props.data.questions.map((question, index) => ({
question: question.question, // question: question.id,
answer: answers.value[index], // answer: answers.value[index],
})); // }));
console.log("Отправляем данные голосования:", voteData); result.value
console.log("Отправляем данные голосования:", result.value);
isVoteSubmitted.value = true; // isVoteSubmitted.value = true;
emit("submit", voteData); // emit("submit", voteData);
}; };
return { return {
@@ -128,6 +136,7 @@ export default {
prevStep, prevStep,
submitVote, submitVote,
isVoteSubmitted, isVoteSubmitted,
result
}; };
}, },
}; };
+33 -15
View File
@@ -1,16 +1,26 @@
<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-row>
<v-card-text class="text-body-1">{{ voteCard.description }}</v-card-text> <v-col>
<TimerUI :endTime="voteCard.dateend" />
<v-card-actions class="justify-space-between"> <v-carousel show-arrows="hover" hide-delimiters cycle height="200">
<v-carousel-item v-for="(picture, index) in images"
:key="index"
:src="`${baseURL.slice(0, -1)}${picture}`">
</v-carousel-item>
</v-carousel>
</v-col>
</v-row>
<v-card-text class="">{{ voteCard.description }}</v-card-text>
<Timer :voteTime="{dateend:voteCard.dateend,datestart:voteCard.datestart}" @changeBtn="(time) => timeChange = time"/>
<v-card-actions class="justify-space-between mt-4 pb-2">
<v-btn <v-btn
v-if="!voteCard.is_passed" :disabled="voteCard.is_passed || timeChange"
color="teal-darken-4" color="teal-darken-4"
prepend-icon="mdi-vote-outline" prepend-icon="mdi-vote-outline"
variant="outlined" variant="outlined"
@@ -18,9 +28,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>
@@ -29,10 +38,11 @@
</template> </template>
<script> <script>
import TimerUI from '../secret/TimerUI.vue'; import Timer from "@/components/UI/Timer.vue"
import { baseURL } from "@/utils/axios-api";
import { ref, computed } from 'vue'
export default { export default {
components: { TimerUI }, components: { Timer },
emits: ['openVoteModal', 'openEditVoteModal', 'deleteVoting'], emits: ['openVoteModal', 'openEditVoteModal', 'deleteVoting'],
props: { props: {
voteCard: { voteCard: {
@@ -40,15 +50,23 @@ export default {
default: () => { default: () => {
return { return {
id: 0, id: 0,
name: "Допустим, здесь могла быть ваша реклама", name: "",
description: "Но таких денег у вас нет, чтобы получить ее на нашем прекрасном голосовании", description: "",
pictures: "https://cdn.vuetifyjs.com/images/parallax/material.jpg", files: [],
dateend: new Date(new Date().getTime() + 600000), dateend: new Date(new Date().getTime() + 600000),
is_passed: false, is_passed: true,
} }
} }
} }
},
setup(props) {
const timeChange = ref(false)
const images = computed(()=>{
return props.voteCard.files.length>0? props.voteCard.files:['/media/defaultimg/vote.png']
})
return { timeChange, baseURL ,images}
} }
} }
</script> </script>
@@ -25,58 +25,41 @@
<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>
:placeholder="`${form.startDate.toLocaleDateString()} ${form.startDate.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}`" <h6 class="text-h6">Дата начала:</h6>
:value="`${form.startDate.toLocaleDateString()} ${form.startDate.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}`" <date-select :datedefault="form.startDate" @returndate="returnstart" />
color="teal-darken-4" <v-select
label="Дата и время начала" v-model="selectedTimeStart"
persistentPlaceholder :items="timeOptions"
readonly dense
> label="Время начала"
<v-menu activator="parent"> outlined
<v-date-picker prepend-icon="mdi-calendar-clock"
v-model="form.startDate"
color="teal-darken-4"
hideHeader
hideWeekdays
/> />
</v-menu> </div>
<v-btn flat icon style="background-color: transparent"> <div>
<v-icon>mdi-calendar-clock</v-icon> <h6 class="text-h6">Дата окончания:</h6>
</v-btn> <date-select :datedefault="form.endDate" @returndate="returnend" />
</v-text-field> <v-select
v-model="selectedTimeEnd"
<v-text-field :items="timeOptions"
:placeholder="`${form.endDate.toLocaleDateString()} ${form.endDate.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}`" dense
:value="`${form.endDate.toLocaleDateString()} ${form.endDate.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}`" label="Время окончания"
color="teal-darken-4" outlined
label="Дата и время окончания" prepend-icon="mdi-calendar-clock"
persistentPlaceholder
readonly
>
<v-menu activator="parent">
<v-date-picker
v-model="form.endDate"
color="teal-darken-4"
hideHeader
hideWeekdays
/> />
</v-menu> </div>
<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,8 +78,8 @@
<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>
@@ -116,10 +99,10 @@
></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>
@@ -132,9 +115,9 @@
<v-text-field <v-text-field
v-model="answer.text" v-model="answer.text"
:label="'Ответ ' + (index + 1)" :label="'Ответ ' + (index + 1)"
:rules="[rules.required]"
class="mr-4" class="mr-4"
outlined outlined
:rules="[rules.required]"
></v-text-field> ></v-text-field>
<v-file-input <v-file-input
v-model="answer.image" v-model="answer.image"
@@ -230,7 +213,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,10 +226,12 @@
</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";
import DateSelect from "@/components/UI/date-select.vue";
export default { export default {
components: {DateSelect},
emits: ['updating'], emits: ['updating'],
setup(props, {emit}) { setup(props, {emit}) {
const step = ref(0); const step = ref(0);
@@ -342,7 +327,55 @@ 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] = selectedTimeEnd.value.split(":").map(Number);
console.log( form.value.endDate);
form.value.endDate.setHours(hours, minutes);
};
const returnstart = (dates) => {
form.value.startDate = dates
}
const returnend = (dates) => {
form.value.endtDate = dates
}
return { return {
returnend,
returnstart,
step, step,
form, form,
questionTypes, questionTypes,
@@ -359,29 +392,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();
+2 -2
View File
@@ -1,5 +1,5 @@
<template> <template>
<v-container> <v-container class="py-0">
<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>
@@ -84,7 +84,7 @@
</v-card-text> </v-card-text>
</v-card> </v-card>
</v-dialog> </v-dialog>
{{res}}
<v-dialog v-model="editVoteModal" max-width="1200px" @click:outside="closeModal"> <v-dialog v-model="editVoteModal" max-width="1200px" @click:outside="closeModal">
<v-card> <v-card>
<v-card-title>Редактировать голосование: {{ selectedVoting?.title }}</v-card-title> <v-card-title>Редактировать голосование: {{ selectedVoting?.title }}</v-card-title>