Merge branch 'develop' into сja

This commit is contained in:
Cja committed 2025-01-20 13:14:06 +03:00
commit b22474a14a
8 files changed
+500 -412

No files matched your search

+101 -101
View File
@@ -1,103 +1,102 @@
<template> <template>
<v-row class="px-2"> <v-row class="px-2">
<v-card variant="text" <v-card variant="text"
:disabled="disabledcard.disabled" :disabled="disabledcard.disabled"
class="py-2 mx-auto"> class="py-2 mx-auto">
<v-card-title class="text-body-1"> До {{ disabledcard.text }} голосования осталось: </v-card-title> <v-card-title class="text-body-1">
<v-row no-gutters class="align-baseline"> До {{ disabledcard.text }} голосования осталось:
<v-col class="text-center">
<v-card class="bg-yellow-darken-4"> </v-card-title>
<div>{{ displayDays }}</div> <v-row no-gutters class="align-baseline">
</v-card> <v-col class="text-center">
<span class="text-caption">{{ declOfNum(displayDays, [' день', ' дня', ' дней']) }}</span> <v-card class="bg-yellow-darken-4">
</v-col> <div>{{ displayDays }}</div>
<v-col cols="auto" class="px-1">:</v-col> </v-card>
<v-col class="text-center"> <span class="text-caption">{{ declOfNum(displayDays, [' день', ' дня', ' дней']) }}</span>
<v-card class="bg-yellow-darken-4"> </v-col>
<div>{{ displayHours }}</div> <v-col cols="auto" class="px-1">:</v-col>
</v-card> <v-col class="text-center">
<span class="text-caption">{{ declOfNum(displayHours, [' час', ' часа', ' часов']) }}</span> <v-card class="bg-yellow-darken-4">
</v-col> <div>{{ displayHours }}</div>
<v-col cols="auto" class="px-1">:</v-col> </v-card>
<v-col class="text-center"> <span class="text-caption">{{ declOfNum(displayHours, [' час', ' часа', ' часов']) }}</span>
<v-card class="bg-yellow-darken-4"> </v-col>
<div>{{ displayMinutes }}</div> <v-col cols="auto" class="px-1">:</v-col>
</v-card> <v-col class="text-center">
<span class="text-caption">{{ declOfNum(displayMinutes, [' минута', ' минуты', ' минут']) }}</span> <v-card class="bg-yellow-darken-4">
</v-col> <div>{{ displayMinutes }}</div>
<v-col cols="auto" class="px-1">:</v-col> </v-card>
<v-col class="text-center"> <span class="text-caption">{{ declOfNum(displayMinutes, [' минута', ' минуты', ' минут']) }}</span>
<v-card class="bg-yellow-darken-4"> </v-col>
<div>{{ displaySeconds }}</div> <v-col cols="auto" class="px-1">:</v-col>
</v-card> <v-col class="text-center">
<span class="text-caption">{{ declOfNum(displaySeconds, [' секунда', ' секунды', ' секунд']) }}</span> <v-card class="bg-yellow-darken-4">
</v-col> <div>{{ displaySeconds }}</div>
</v-row> </v-card>
</v-card> <span class="text-caption">{{ declOfNum(displaySeconds, [' секунда', ' секунды', ' секунд']) }}</span>
</v-row> </v-col>
</v-row>
</v-card>
</v-row>
</template> </template>
<script> <script>
import { computed, ref } from 'vue' import { computed, ref } from 'vue'
export default { export default {
props: { props: {
voteTime: { voteTime: {
type: Object, type: Object,
default: () => { return { default: () => { return {
dateend:new Date().setFullYear(), dateend: new Date().setFullYear(),
datestart:new Date().setFullYear() datestart: new Date().setFullYear()
}} }}
} }
}, },
setup(props, {emit}) { setup(props, {emit}) {
const seconds = 1000 const seconds = 1000
const displayMinutes = ref(0); const displayMinutes = ref(0);
const displayHours = ref(0); const displayHours = ref(0);
const displayDays = ref(0); const displayDays = ref(0);
const displaySeconds = ref(0) const displaySeconds = ref(0);
const isFinished = ref(false);
const minutes = computed(() => { const minutes = computed(() => seconds * 60);
return seconds * 60 const hours = computed(() => minutes.value * 60);
}) const days = computed(() => hours.value * 24);
const hours = computed(() => { function declOfNum(value, titles) {
return minutes.value * 60 const cases = [2, 0, 1, 1, 1, 2];
}) return titles[(value % 100 > 4 && value % 100 < 20) ? 2 : cases[(value % 10 < 5) ? value % 10 : 5]];
}
const days = computed(() => { const disabledcard = ref({
return hours.value * 24 text: 'окончания',
}) disabled: false
});
function declOfNum(value, titles) {
const cases = [2, 0, 1, 1, 1, 2]
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() { 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() {
const timer = setInterval(() => { const timer = setInterval(() => {
const date = new Date() const date = new Date()
const distance = new Date(props.voteTime[dateendorStart()]).getTime() - date.getTime() const distance = new Date(props.voteTime[dateendorStart()]).getTime() - date.getTime()
@@ -124,15 +123,16 @@ export default {
countDown() countDown()
return { return {
displayMinutes, displayMinutes,
displayHours, displayHours,
displayDays, displayDays,
displaySeconds, displaySeconds,
declOfNum, declOfNum,
dateendorStart, dateendorStart,
disabledcard disabledcard,
}
} };
}
} }
</script> </script>
@@ -156,7 +156,7 @@
<br /> <br />
<span class="text-h5 text-grey" <span class="text-h5 text-grey"
>Сейчас вакансий нет, <br /> >Сейчас вакансий нет, <br />
загляните позжет</span загляните позже</span
> >
</v-card-subtitle> </v-card-subtitle>
</v-card> </v-card>
+92 -109
View File
@@ -1,127 +1,110 @@
<template> <template>
<template v-if="!isVoteSubmitted"> <template v-if="!isVoteSubmitted">
<v-card style="height: 85vh;"> <v-card style="height: 85vh;">
<div class="d-flex flex-column flex-fill px-2 " > <div class="d-flex flex-column flex-fill px-2 ">
<v-col cols="auto"> <v-col cols="auto">
<v-row class="d-flex flex-column"> <v-row class="d-flex flex-column">
<v-col cols="12" class="d-flex flex-row pa-0"> <v-col class="d-flex flex-row pa-0" cols="12">
<v-col> <v-col>
<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>
</v-col> </v-col>
<v-col cols="auto"> <v-col cols="auto">
<v-btn color="red-darken-1" density="compact" size="small" icon="mdi-close-thick" @click="$emit('closer')"> <v-btn color="red-darken-1" density="compact" icon="mdi-close-thick" size="small"
@click="$emit('closer')">
</v-btn> </v-btn>
</v-col> </v-col>
</v-col> </v-col>
</v-row> </v-row>
</v-col> </v-col>
<div class="d-flex flex-column flex-fill "> <div class="d-flex flex-column flex-fill ">
<v-stepper class="d-flex flex-column flex-fill" v-model="activeStep"> <v-stepper v-model="activeStep" class="d-flex flex-column flex-fill">
<!-- Шаги голосования --> <!-- Шаги голосования -->
<v-stepper-header class="py-0"> <v-stepper-header class="py-0">
<template v-for="question in data.questions" :key="question.numb"> <template v-for="question in data.questions" :key="question.numb">
<v-stepper-item <v-stepper-item
:color="question.numb < activeStep+1?'success':'warning'" :color="question.numb < activeStep+1?'success':'warning'"
edit-icon="mdi-help" :complete="question.numb < activeStep+1"
:complete="question.numb < activeStep+1" :step="question.numb"> :step="question.numb" edit-icon="mdi-help">
Вопрос {{ question.numb }} Вопрос {{ question.numb }}
</v-stepper-item> </v-stepper-item>
</template> </template>
</v-stepper-header> </v-stepper-header>
<v-stepper-window class="d-flex flex-column flex-fill " > <v-stepper-window class="d-flex flex-column flex-fill">
<v-stepper-window-item v-for="(question, index) in data.questions" :key="question.numb" <v-stepper-window-item v-for="(question, index) in data.questions" :key="question.numb"
class="" :step="question.numb"
:step="question.numb"> class="">
<!-- <v-card class="d-flex flex-fill" > -->
<div class=""> <div class="">
<div class="" >{{ question.name }}</div> <h3 class="text-center">{{ question.name }}</h3>
<v-row> <v-row>
<div class="v-col align-self-center "> <div class="v-col align-self-start">
<v-img class="" <v-img :src="question.file"
style="max-height:400px" class="cursor-pointer"
@click.stop="opendialog({answer:question.question, file:question.file})" style="max-height:45vh"
:src="question.file"/> @click.stop="opendialog({answer:question.question, file:question.file})"/>
</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 }}
<template v-slot:prepend="{ isSelected }">
<v-list-item-action start>
<v-checkbox-btn :model-value="isSelected"></v-checkbox-btn>
</v-list-item-action>
</template>
<template v-slot:append>
<v-avatar :image="answer.file" @click.stop="opendialog(answer)"></v-avatar>
</template>
</v-list-item>
</v-list>
</div>
</v-row>
</div> </div>
<div class="v-col-6">
<v-list v-model:selected="result[question.id]" slim density="compact" select-strategy="leaf">
<v-list-item density="compact" v-for="answer in question.answers" :key="answer.id"
:value="answer.id">
{{ answer.name }}
<template v-slot:prepend="{ isSelected }">
<v-list-item-action start>
<v-checkbox-btn :model-value="isSelected"></v-checkbox-btn>
</v-list-item-action>
</template>
<template v-slot:append>
<v-avatar @click.stop="opendialog(answer)" :image="answer.file"></v-avatar>
</template>
</v-list-item>
</v-list>
</div>
</v-row>
</div>
<!-- Действия --> <!-- Действия -->
<v-card-actions class=""> <v-card-actions class="">
</v-card-actions> </v-card-actions>
<!-- </v-card> -->
<!-- </v-card> -->
</v-stepper-window-item> </v-stepper-window-item>
</v-stepper-window> </v-stepper-window>
<v-stepper-actions > <v-stepper-actions>
<template v-slot:prev> <template v-slot:prev>
<v-btn @click="prevStep" outlined>Назад</v-btn></template> <v-btn outlined @click="prevStep">Назад</v-btn>
<template v-slot:next> </template>
<template v-slot:next>
<v-btn v-if="activeStep < data.questions.length - 1" :disabled="!isCurrentQuestionAnswered" @click="nextStep"
color="teal-darken-4"> <v-btn v-if="activeStep < data.questions.length - 1" :disabled="!isCurrentQuestionAnswered"
Далее color="teal-darken-4"
</v-btn> @click="nextStep">
<v-btn v-else :disabled="!isCurrentQuestionAnswered" color="teal-darken-4" @click="submitVote"> Далее
Отправить </v-btn>
</v-btn> <v-btn v-else :disabled="!isCurrentQuestionAnswered" color="teal-darken-4" @click="submitVote">
</template></v-stepper-actions> Отправить
</v-btn>
</template>
</v-stepper-actions>
</v-stepper> </v-stepper>
</div> </div>
</div> </div>
</v-card> </v-card>
<v-dialog v-model="dialog"> <v-dialog v-model="dialog" max-width="100vh">
<v-card max-height="800"> <v-card max-height="800">
<v-card-title class="v-row"> <v-card-title class="v-row">
<div clas="v-col-auto"> <div class="v-col-auto">
{{ activepick.answer }}
</div>
<v-spacer></v-spacer>
<div>
<v-btn color="red-darken-1" density="compact" icon="mdi-close-thick" size="small" @click="dialog=false"/>
</div>
{{ activepick.answer }} </div>
<v-spacer></v-spacer>
<div clas="bg-yellow">
<v-btn color="red-darken-1" density="compact" size="small" icon="mdi-close-thick" @click="dialog=false">
</v-btn>
</div>
</v-card-title> </v-card-title>
<v-card-item> <v-card-item>
<v-img :src="activepick.file" max-height="600"></v-img>
<v-img :src="activepick.file" max-height="600" ></v-img>
</v-card-item> </v-card-item>
</v-card> </v-card>
</v-dialog> </v-dialog>
@@ -129,22 +112,22 @@
<!-- Спасибо за голос --> <!-- Спасибо за голос -->
<template v-else> <template v-else>
<v-card width="400" class="mx-auto"> <v-card class="mx-auto" width="400">
<v-row align="center" justify="center" class="pa-3"> <v-row align="center" class="pa-3" justify="center">
<v-col class="text-center"> <v-col class="text-center">
<v-icon :color="messeger[messeger.key].color" :icon="messeger[messeger.key].icon" size="64" /> <v-icon :color="messeger[messeger.key].color" :icon="messeger[messeger.key].icon" size="64"/>
<h2>{{ messeger[messeger.key].text }}</h2> <h2>{{ messeger[messeger.key].text }}</h2>
<v-btn @click="$emit('closer')" class="ma-3 ">Закрыть</v-btn> <v-btn class="ma-3 " @click="$emit('closer')">Закрыть</v-btn>
</v-col> </v-col>
</v-row> </v-row>
</v-card> </v-card>
</template> </template>
</template> </template>
<script> <script>
import { axiosApiInstance } from "@/utils/axios-api"; import {axiosApiInstance} from "@/utils/axios-api";
import { computed, ref } from "vue"; import {computed, ref} from "vue";
import { useAccountStore } from "@/store/AccountStore"; import {useAccountStore} from "@/store/AccountStore";
export default { export default {
name: 'CurrentVote', name: 'CurrentVote',
@@ -156,11 +139,11 @@ export default {
default: () => ({}), default: () => ({}),
}, },
}, },
setup(props, { emit }) { setup(props, {emit}) {
const accountStore = useAccountStore(); const accountStore = useAccountStore();
const messeger = ref({ const messeger = ref({
good: { icon: 'mdi-check-circle', text: 'Спасибо за Ваш голос!', color: "green" }, good: {icon: 'mdi-check-circle', text: 'Спасибо за Ваш голос!', color: "green"},
bad: { icon: 'mdi-alert', text: 'Произошла ошибка!', color: "red" }, bad: {icon: 'mdi-alert', text: 'Произошла ошибка!', color: "red"},
key: 'good' key: 'good'
}) })
const activeStep = ref(0); const activeStep = ref(0);
@@ -168,9 +151,10 @@ export default {
const isVoteSubmitted = ref(false); const isVoteSubmitted = ref(false);
const isCurrentQuestionAnswered = computed(() => { const isCurrentQuestionAnswered = computed(() => {
let q = props.data.questions.find(e => e.numb == activeStep.value + 1) let q = props.data.questions.find(e => e.numb === activeStep.value + 1)
return result.value[q.id].length > 0; return q !== undefined ? result.value[q.id].length > 0 : false;
}); });
const getres = () => { const getres = () => {
return props.data.questions.reduce((acc, item) => { return props.data.questions.reduce((acc, item) => {
acc[item.id] = [] acc[item.id] = []
@@ -195,25 +179,24 @@ export default {
console.log("Отправляем данные голосования:", result.value); console.log("Отправляем данные голосования:", result.value);
let voteData = [] let voteData = []
for (let val of Object.values(result.value)) { for (let val of Object.values(result.value)) {
val.forEach(e => voteData.push({ answer: e, comment: null, user: accountStore.user.id })) val.forEach(e => voteData.push({answer: e, comment: null, user: accountStore.user.id}))
} }
axiosApiInstance.post('api/vote/voteresultcreate/', voteData).then(res => { axiosApiInstance.post('api/vote/voteresultcreate/', voteData).then(res => {
messeger.value.key = 'good' messeger.value.key = 'good'
}).catch(e => { }).catch(e => {
console.log(e); console.log(e);
messeger.value.key = 'bad' messeger.value.key = 'bad'
} }
).finally(() => isVoteSubmitted.value = true) ).finally(() => isVoteSubmitted.value = true)
}; };
const activepick = ref(null) const activepick = ref(null)
const dialog=ref(false) const dialog = ref(false)
const opendialog=(val)=>{ const opendialog = (val) => {
dialog.value=true dialog.value = true
activepick.value=val activepick.value = val
} }
return { return {
+137 -89
View File
@@ -1,100 +1,148 @@
<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">
<v-btn flat size="medium" @click="$emit('openEditVoteModal', voteCard)"> <v-tooltip bottom>
<v-icon color="orange-lighten-1">mdi-pencil</v-icon> <template v-slot:activator="{ props }">
</v-btn> <span
</v-card-text> v-bind="props"
<v-row> style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<v-col> {{ 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-icon color="orange-lighten-1">mdi-pencil</v-icon>
</v-btn>
</v-card-text>
<v-row>
<v-col>
<v-carousel
cycle
height="200" hide-delimiters
show-arrows="hover">
<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="">
<v-tooltip bottom>
<template v-slot:activator="{ props }">
<span
v-bind="props"
style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
{{ voteCard.description }}
</span>
</template>
<span>{{ voteCard.description }}</span>
</v-tooltip>
</v-card-text>
<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>
<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"
rounded="xl" size="small" variant="outlined" @click="$emit('openVoteModal', voteCard)">
{{ !voteCard.is_passed ? "Проголосовать" : "Уже проголосовали" }}
</v-btn>
</template>
<template v-else>
<v-btn color="teal-darken-4" prepend-icon="mdi-trophy-outline"
rounded="xl" size="small" variant="outlined" @click="$emit('openResultModal', voteCard)">
Результаты
</v-btn>
</template>
<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-carousel <v-card class="flex" max-width="450">
show-arrows="hover" <v-btn
hide-delimiters cycle class="align-self-end ma-2 text-red"
height="200"> icon="mdi-close"
<v-carousel-item size="medium"
v-for="(picture, index) in images" variant="text"
:key="index" @click="youSure = false"
:src="`${baseURL.slice(0, -1)}${picture}`"> />
</v-carousel-item> <div class="ml-5 text-h6">
</v-carousel> Вы действительно хотите удалить голосование?
</v-col> </div>
</v-row> <template v-slot:actions>
<v-card-text class="">{{ voteCard.description }}</v-card-text> <v-btn-group>
<Timer :voteTime="{ dateend: voteCard.dateend, datestart: voteCard.datestart }" @changeBtn="(time) => timeChange = time" /> <v-btn
<v-card-actions class="justify-space-between mt-4 pb-2"> class="text-red"
<v-btn :disabled="voteCard.is_passed || timeChange" color="teal-darken-4" prepend-icon="mdi-vote-outline" @click="$emit('deleteVoting', voteCard.id), youSure = false">
variant="outlined" rounded="xl" size="small" @click="$emit('openVoteModal', voteCard)"> Да
{{ !voteCard.is_passed ? "Проголосовать" : "Уже проголосовали" }} </v-btn>
</v-btn> <v-btn
<v-btn color="error" @click="youSure=true" size="medium"> class="text-green"
<v-icon>mdi-delete</v-icon> @click="youSure = false">
<v-dialog v-model="youSure" width="500"> Нет
</v-btn>
<v-card max-width="450" class="flex"> </v-btn-group>
<v-btn </template>
class="align-self-end ma-2 text-red" </v-card>
icon="mdi-close" </v-dialog>
variant="text" </v-btn>
size="medium" </v-card-actions>
@click="youSure = false" </v-card>
/>
<div class="ml-5 text-h6">
Вы действительно хотите удалить голосование?
</div>
<template v-slot:actions>
<v-btn-group>
<v-btn
class="text-red"
@click="$emit('deleteVoting', voteCard.id), youSure = false">
Да
</v-btn>
<v-btn
class="text-green"
@click="youSure = false">
Нет
</v-btn>
</v-btn-group>
</template>
</v-card>
</v-dialog>
</v-btn>
</v-card-actions>
</v-card>
</template> </template>
<script> <script>
import Timer from "@/components/UI/Timer.vue" import Timer from "@/components/UI/Timer.vue"
import { baseURL } from "@/utils/axios-api"; import {baseURL} from "@/utils/axios-api";
import { ref, computed } from 'vue' import {computed, ref} from 'vue'
export default { import {useAccountStore} from "@/store/AccountStore";
components: { Timer },
emits: ['openVoteModal', 'openEditVoteModal', 'deleteVoting'],
props: {
voteCard: {
type: Object,
default: () => {
return {
id: 0,
name: "",
description: "",
files: [],
dateend: new Date(new Date().getTime() + 600000),
is_passed: true,
}
}
}
},
setup(props) {
const timeChange = ref(false)
const youSure = ref(false)
const images = computed(() => { export default {
return props.voteCard.files.length > 0 ? props.voteCard.files : ['/media/defaultimg/vote.png'] components: {Timer},
}) emits: ['openVoteModal', 'openEditVoteModal', 'deleteVoting', 'openResultModal'],
return { timeChange, baseURL, images, youSure } props: {
isFinished:{
type:Boolean,
default: false
},
voteCard: {
type: Object,
default: () => {
return {
id: 0,
name: "",
description: "",
files: [],
dateend: new Date(new Date().getTime() + 600000),
is_passed: true,
}
}
} }
},
setup(props) {
const timeChange = ref(false)
const youSure = ref(false)
const isFinished = ref(false);
const accountStore = useAccountStore();
const user = accountStore.user;
const images = computed(() => {
return props.voteCard.files.length > 0 ? props.voteCard.files : ['/media/defaultimg/vote.png']
})
const date = new Date();
const endDate = new Date(props.voteCard.dateend);
const distance = endDate.getTime() - date.getTime();
if (distance <= 0) {
isFinished.value = true;
}
return {timeChange, baseURL, images, youSure, isFinished, user}
}
} }
</script> </script>
@@ -1,5 +1,5 @@
<template> <template>
<v-container> <v-row class="pt-2 mx-2 h-100 flex-column">
<template v-if="isVoteCreated"> <template v-if="isVoteCreated">
<v-card class="text-center pa-8" flat> <v-card class="text-center pa-8" flat>
<v-icon color="success" size="48">mdi-check-circle</v-icon> <v-icon color="success" size="48">mdi-check-circle</v-icon>
@@ -8,18 +8,21 @@
</v-card> </v-card>
</template> </template>
<template v-else> <template v-else>
<v-stepper v-model="step" editable> <div class="v-col">
<v-stepper-header>
<v-stepper class="h-100 v-row flex-column" v-model="step" editable>
<v-stepper-header class="v-col-auto pa-0">
<v-stepper-item :complete="step > 0" step="1">Основная информация</v-stepper-item> <v-stepper-item :complete="step > 0" step="1">Основная информация</v-stepper-item>
<v-divider></v-divider> <v-divider></v-divider>
<v-stepper-item :complete="step > 1" step="2">Создание опроса</v-stepper-item> <v-stepper-item :complete="step > 1" step="2">Создание опроса</v-stepper-item>
<v-divider></v-divider> <v-divider></v-divider>
<v-stepper-item :complete="step > 2" step="3">Подтверждение</v-stepper-item> <v-stepper-item :complete="step > 2" step="3">Подтверждение</v-stepper-item>
</v-stepper-header> </v-stepper-header>
<v-stepper-window> <v-stepper-window class="v-col d-flex">
<!-- Основная информация --> <!-- Основная информация -->
<v-stepper-window-item step="1"> <v-stepper-window-item step="1" class="">
<v-card flat> <v-card flat>
<v-card-title>Основная информация</v-card-title> <v-card-title>Основная информация</v-card-title>
<v-card-text> <v-card-text>
@@ -36,31 +39,30 @@
outlined outlined
></v-textarea> ></v-textarea>
<div> <div class="d-flex ga-10">
<h6 class="text-h6">Дата начала:</h6> <div class="d-flex ga-3 align-center">
<h6 class="text-subtitle-1">Дата и время начала:</h6>
<date-select :datedefault="form.startDate" @returndate="returnstart" /> <date-select :datedefault="form.startDate" @returndate="returnstart" />
<v-select <v-select
v-model="selectedTimeStart" v-model="selectedTimeStart"
:items="timeOptions" :items="timeOptions"
dense dense
label="Время начала"
outlined outlined
prepend-icon="mdi-calendar-clock" hide-details
/> />
</div> </div>
<div> <div class="d-flex ga-3 align-center">
<h6 class="text-h6">Дата окончания:</h6> <h6 class="text-subtitle-1">Дата и время окончания:</h6>
<date-select :datedefault="form.endDate" @returndate="returnend" /> <date-select :datedefault="form.endDate" @returndate="returnend" />
<v-select <v-select
v-model="selectedTimeEnd" v-model="selectedTimeEnd"
:items="timeOptions" :items="timeOptions"
dense dense
label="Время окончания"
outlined outlined
prepend-icon="mdi-calendar-clock" hide-details
/> />
</div> </div>
</div>
</v-card-text> </v-card-text>
<v-card-actions> <v-card-actions>
<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>
@@ -148,7 +150,7 @@
></v-switch> ></v-switch>
<v-autocomplete <v-autocomplete
clearable clearable
v-model="selectedEmployees" v-model="question.selectedEmployees"
:items="allEmployees" :items="allEmployees"
item-title="fio" item-title="fio"
item-value="id" item-value="id"
@@ -244,22 +246,20 @@
</v-stepper-window> </v-stepper-window>
</v-stepper> </v-stepper>
</div>
</template> </template>
</v-container> </v-row>
</template> </template>
<script> <script>
import {computed, ref, watch} from "vue"; import {computed, ref, watch} from "vue";
import {createVote, getEmployees} from "@/utils/axios-api"; import {createVote, getEmployees} from "@/utils/axios-api";
import DateSelect from "@/components/UI/date-select.vue"; import DateSelect from "@/components/UI/date-select.vue";
import {useAccountStore} from "@/store/AccountStore";
export default { export default {
components: {DateSelect}, components: {DateSelect},
emits: ['updating'], emits: ['updating'],
setup(props, {emit}) { setup(props, {emit}) {
const accountStore = useAccountStore();
const user = accountStore.user;
const step = ref(0); const step = ref(0);
const isVoteCreated = ref(false); const isVoteCreated = ref(false);
const form = ref({ const form = ref({
@@ -298,20 +298,13 @@ export default {
const handleSelectAll = (selected) => { const handleSelectAll = (selected) => {
if (selected.includes("all")) { if (selected.includes("all")) {
currentQuestion.value.answers = groupedEmployees.value.map((employee) => ({ form.value.questions[currentQuestionIndex.value].answers = groupedEmployees.value.map((employee) => ({
text: employee.id, text: employee.id,
image: null image: null,
})); }));
selectedEmployees.value = groupedEmployees.value.map(employee => employee.id); selectedEmployees.value = groupedEmployees.value.map(employee => employee.id);
} else if (
selected.length === groupedEmployees.value.length &&
!selected.includes("all")
) {
currentQuestion.value.answers = selected.map((id) => ({ text: id, image: null }));
selectedEmployees.value = groupedEmployees.value.map(employee => employee.id);
} else { } else {
currentQuestion.value.answers = selected.map((id) => ({ text: id, image: null })); form.value.questions[currentQuestionIndex.value].answers = selected.map((id) => ({ text: id, image: null }));
selectedEmployees.value = groupedEmployees.value.map(employee => employee.id);
} }
}; };
@@ -320,10 +313,12 @@ export default {
const addQuestion = () => { const addQuestion = () => {
form.value.questions.push({ form.value.questions.push({
text: "", text: "",
settings: {type: "Ввести вручную", multiChoice: 1, onlyDep: false, withoutDirector: false}, settings: { type: "Ввести вручную", multiChoice: 1, onlyDep: false, withoutDirector: false },
image: null, image: null,
answers: [], answers: [],
selectedEmployees: []
}); });
currentQuestionIndex.value = form.value.questions.length - 1;
}; };
const removeQuestion = (index) => { const removeQuestion = (index) => {
@@ -335,7 +330,7 @@ export default {
const addAnswer = () => { const addAnswer = () => {
if (currentQuestion.value) { if (currentQuestion.value) {
currentQuestion.value.answers.push({text: "", image: null}); form.value.questions[currentQuestionIndex.value].answers.push({ text: "", image: null });
} }
}; };
@@ -429,20 +424,16 @@ export default {
const selectedEmployees = ref([]); const selectedEmployees = ref([]);
const onEmployeesChange = (selected) => { const onEmployeesChange = (selected) => {
currentQuestion.value.answers = selected.map((id) => ({ text: id, image: null })); form.value.questions[currentQuestionIndex.value].answers = selected.map((id) => ({ text: id, image: null }));
}; };
return { return {
selectedEmployees,
onEmployeesChange, onEmployeesChange,
returnend, returnend,
returnstart, returnstart,
step, step,
form, form,
questionTypes, questionTypes,
groupedEmployees,
currentQuestionIndex,
currentQuestion,
addQuestion, addQuestion,
removeQuestion, removeQuestion,
addAnswer, addAnswer,
@@ -0,0 +1,67 @@
<template>
<v-container>
<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-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>
</v-container>
</template>
<script>
import { computed } from 'vue';
export default {
name: 'VoteResult',
props: {
results: {
type: Array,
required: true,
default: () => []
}
},
setup(props) {
const winner = computed(() => {
return props.results.reduce((max, option) => (option.votes > max.votes ? option : max), { name: '', votes: 0 });
});
const sortedResults = computed(() => {
return [...props.results].sort((a, b) => b.votes - a.votes);
});
return {
winner,
sortedResults
};
}
};
</script>
<style scoped>
h1 {
margin-bottom: 20px;
}
</style>
+5 -10
View File
@@ -93,22 +93,20 @@ async function getVotes(status) {
} }
} }
async function createVote(voteData) { async function createVote(voteData) {
try { try {
const formData = new FormData(); const formData = new FormData();
voteData.questions.forEach(question => { voteData.questions.forEach(question => {
formData.append('questionsfiles', question.image) formData.append('questionsfiles', question.image)
console.log(question.image);
if(!!question.image){ if(!!question.image){
const {name,size,lastModified}=question.image const {name,size,lastModified}=question.image
question.image={name,size,lastModified} question.image={name,size,lastModified}
} }
question.answers.forEach(answer=>{ question.answers.forEach(answer=>{
formData.append('answersfiles', answer.image) formData.append('answersfiles', answer.image)
if(!!answer.image){ if(!!answer.image){
const {name,size,lastModified}=answer.image const {name,size,lastModified}=answer.image
@@ -125,8 +123,8 @@ async function createVote(voteData) {
formData.append('startDate', new Date(voteData.startDate).toISOString()); formData.append('startDate', new Date(voteData.startDate).toISOString());
formData.append('endDate', new Date(voteData.endDate).toISOString()); formData.append('endDate', new Date(voteData.endDate).toISOString());
formData.append('questions', JSON.stringify(voteData.questions)); formData.append('questions', JSON.stringify(voteData.questions));
const response = await axiosApiInstance.post('/api/vote/votecreate/', formData, { const response = await axiosApiInstance.post('/api/vote/votecreate/', formData, {
headers: {'Content-Type': 'multipart/form-data'}, headers: {'Content-Type': 'multipart/form-data'},
}); });
@@ -188,9 +186,6 @@ async function getEmployees() {
} }
} }
getEmployees()
.then(r => console.log(r))
export { export {
axiosApiInstance, axiosApiInstance,
+69 -65
View File
@@ -1,79 +1,56 @@
<template> <template>
<v-container class="py-0"> <v-container fluid class="pt-2 d-flex flex-column">
<v-toolbar color="transparent"> <v-row class="flex-column">
<v-toolbar-title>Голосования</v-toolbar-title> <v-col cols="auto">
<template v-slot:extension> <v-tabs
<v-tabs v-model="currentTab"> align="center"
<v-tab value="current">Текущие голосования</v-tab> v-model="currentTab">
<v-tab value="completed">Завершенные голосования</v-tab> <v-tab
<v-tab value="constructor">Создать новое голосование</v-tab>
</v-tabs> v-for="x in tabs" :key="x.value" :value="x.value">{{ x.text }}</v-tab>
</template>
</v-toolbar> </v-tabs>
</v-col>
<v-tabs-window v-model="currentTab"> <v-col class="overflow-auto pa-0">
<v-window v-model="currentTab" class=" h-100" >
<!-- Текущие голосования --> <!-- Текущие голосования -->
<v-tabs-window-item value="current"> <!-- <v-tabs-window v-model="currentTab"> -->
<v-container> <!-- Текущие голосования -->
<v-row> <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-col
v-for="voting in sortedCurrentVotes" v-for="voting in sortedVotes"
:key="voting.id" :key="voting.id"
cols="12" cols="12"
lg="3" lg="3"
md="4" md="4"
> >
<VoteCardVue <VoteCardVue
:isFinished="currentTab=='active'"
:voteCard="voting" :voteCard="voting"
@openVoteModal="(voting) => openModal('vote', voting)" @openVoteModal="(voting) => openModal('vote', voting)"
@openEditVoteModal="(voting) => openModal('edit', voting)" @openEditVoteModal="(voting) => openModal('edit', voting)"
@openResultModal="(voting) => openModal('results', voting)"
@deleteVoting="deleteVoting" @deleteVoting="deleteVoting"
/> />
</v-col> </v-col>
</v-row> </v-row>
</v-container>
</v-tabs-window-item> </v-tabs-window-item>
<!-- Завершенные голосования --> <!-- Завершенные голосования -->
<v-tabs-window-item value="completed">
<v-container>
<v-row>
<v-col
v-for="voting in sortedCompletedVotes"
:key="voting.id"
cols="12"
lg="3"
md="4"
:class="{ 'voted-card': voting.voted }"
>
<v-card>
<v-card-title>{{ voting.title }}</v-card-title>
<v-card-subtitle>
Завершено: {{ formatDate(voting.endDate) }}
</v-card-subtitle>
<v-card-actions class="justify-space-between">
<v-btn color="teal-darken-4" size="medium" @click="(voting) => openModal('results', voting)">
Результаты
</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-row>
</v-container>
</v-tabs-window-item>
<!-- Конструктор --> <!-- Конструктор -->
<v-tabs-window-item value="constructor"> <v-tabs-window-item value="constructor" class="h-100 overflow-auto bg-yellow">
<VoteConstructor @updating="updating" /> <VoteConstructor @updating="updating" />
</v-tabs-window-item> </v-tabs-window-item>
</v-tabs-window> <!-- </v-tabs-window> -->
</v-window>
<!-- Модальные окна --> <!-- Модальные окна -->
<v-dialog v-model="voteModal" @click:outside="closeModal"> <v-dialog v-model="voteModal" @click:outside="closeModal">
<CurrentVote :data="res" @closer="closeModal"/> <CurrentVote :data="res" @closer="closeModal"/>
@@ -97,13 +74,22 @@
<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> <VoteResult :results="testResults"/>
</v-card-text> </v-card-text>
<v-card-actions> <v-card-actions>
<v-btn @click="closeModal">Закрыть</v-btn> <v-btn @click="closeModal">Закрыть</v-btn>
</v-card-actions> </v-card-actions>
</v-card> </v-card>
</v-dialog> </v-dialog>
</v-col>
</v-row>
</v-container> </v-container>
</template> </template>
@@ -113,15 +99,30 @@ 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 { deleteVote, getVoteDetail, getVotes } from "@/utils/axios-api"; import { deleteVote, getVoteDetail, 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 }, components: { CurrentVote, VoteConstructor, VoteCardVue, VoteResult },
setup() { setup() {
const currentTab = ref("current"); const tabs=[
{value:"active", text:'Текущие голосования'},
{value:"completed", text:'Завершенные голосования'},
{value:"constructor", text:'Создать новое голосование'},
]
const testResults = [
{name: 'Дональд Трамп', votes: 99},
{name: 'Иван Иванов', votes: 30},
{name: 'Аркадий Упукник', votes: 95},
];
const currentTab = ref("active");
const votes = ref([]); const votes = ref([]);
const router = useRouter(); const router = useRouter();
const route = useRoute(); const route = useRoute();
@@ -139,17 +140,13 @@ export default {
const resultsModal = ref(false); const resultsModal = ref(false);
const selectedVoting = ref(null); const selectedVoting = ref(null);
const sortedCurrentVotes = computed(() => const sortedVotes = computed(() =>{
votes.value 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))
.filter((v) => new Date(v.dateend) > new Date()) }
.sort((a, b) => new Date(a.dateend) - new Date(b.dateend))
); );
const sortedCompletedVotes = computed(() =>
votes.value
.filter((v) => new Date(v.dateend) <= new Date())
.sort((a, b) => new Date(b.dateend) - new Date(a.dateend))
);
const loadVoteDetails = async (id) => { const loadVoteDetails = async (id) => {
try { try {
@@ -194,6 +191,12 @@ export default {
console.error("Ошибка при удалении голосования:", error); console.error("Ошибка при удалении голосования:", error);
} }
}; };
watch(currentTab,
async () =>{
votes.value=[]
await updating(currentTab.value)}
)
watch( watch(
() => route, () => route,
@@ -217,8 +220,8 @@ export default {
return { return {
currentTab, currentTab,
votes, votes,
sortedCurrentVotes, sortedVotes,
sortedCompletedVotes, testResults,
voteModal, voteModal,
editVoteModal, editVoteModal,
resultsModal, resultsModal,
@@ -228,6 +231,7 @@ export default {
deleteVoting, deleteVoting,
updating, updating,
res, res,
tabs
}; };
}, },
}; };