P-97 Админка для голосования

This commit is contained in:
Denzel committed 2025-01-09 16:52:21 +03:00
1 parent 9d350fdbb9
commit 50444493ce
5 files changed
+265 -139

No files matched your search

+1 -1
View File
@@ -10,7 +10,7 @@ class Settings():
'ENGINE': 'django.db.backends.mysql',
'NAME': 'accounting',
'USER': 'root',
'PASSWORD': 'ADMIN',
'PASSWORD': 'Vojn1389',
'HOST': '127.0.0.1',
'PORT': '3306',
}
+4 -4
View File
@@ -175,10 +175,10 @@ USE_TZ = True
STATIC_URL = '/static/'
STATICFILES_DIRS = (
BASE_DIR.joinpath('static'),
)
# STATIC_ROOT = BASE_DIR.joinpath('static')
# STATICFILES_DIRS = (
# BASE_DIR.joinpath('static'),
# )
STATIC_ROOT = BASE_DIR.joinpath('static')
CKEDITOR_UPLOAD_PATH = "uploads/"
# Media
MEDIA_URL = '/media/'
+6 -1
View File
@@ -141,12 +141,17 @@ const routes = [
},
},
{
path: "/vote",
name: "Vote",
component: () =>
import("@/views/Vote.vue")
},
{
path: "/voteconstructor",
name: "VoteConstructor",
component: () =>
import("@/views/VoteConstructor.vue")
},
],
},
];
+8 -133
View File
@@ -31,7 +31,6 @@
:class="{ 'cursor-pointer': admin_panel }">
{{
Math.round((voteresults.uservotedthanks.length * 100 / (allsorted.length + 1)).toFixed(2)) }}%</span>
</template>
<template v-slot:default="{ isActive }">
<v-row justify="center" class="h-100 admin-vote">
@@ -58,18 +57,17 @@
</div>
<div v-else class="flip-card-front" @click="toggleFlip2">
<!-- Передняя сторона карточки -->
<v-card
<v-card
class="elevation-24 d-flex align-сenter justify-space-between flex-column" width="500" height="510" variant="elevated" >
<div class="">
<div class="text-h5 my-2">ЛУЧШИЙ НОВОГОДНИЙ КОСТЮМ</div>
<div class="mt-4 ">
<div class=" align-center font-weight-bold">
Выберите сотрудника,
костюм которого вам больше всего понравился
</div>
</div>
@@ -117,7 +115,7 @@
<v-card class="d-flex align-сenter justify-space-between elevated-24 flex-column" width="500" height="510" variant="elevated">
<div class="text-h5 my-2">ЛУЧШИЙ НОВОГОДНИЙ КОСТЮМ</div>
<!-- <v-card-text class=""> -->
<vote-form class="flex-grow-1 " ref="voteform" :type_fetch="'thanks'"
:persons="allsorted"
:myrealdep="myrealdep" @voted="toggleFlip2" />
@@ -137,53 +135,6 @@
</div>
</v-col>
</v-col>
<!-- <v-col cols="12" class="d-flex justify-center align-end ">
<h1>ПРИНЯЛИ УЧАСТИЕ В ГОЛОСОВАНИИ</h1>
</v-col> -->
<!-- <v-col cols="12" class="d-flex justify-center align-end pa-0">
<v-col v-if="admin_panel" justify="center" align="center" cols="6" class=" pa-0">
<v-dialog> -->
<!-- <template v-slot:activator="{ props: activatorProps }">
<v-btn v-bind="activatorProps " variant='plain'
class="procent_card_font pa-0">
{{ Math.round((voteresults.usersvotedbest.filter(e=>e.department_user==mydepartment[0].department).length*100/(mydepartment.length+1)).toFixed(2))}}%
</v-btn>
</template> -->
<!-- <template v-slot:default="{ isActive }">
<v-row justify="center" class="h-100 admin-vote">
<v-card width="1500" height="900">
<vote-admin :usersvotedbest="voteresults.usersvotedbest" :uservotedthanks="voteresults.uservotedthanks" :all_cod="allsorted"/>
<v-row justify="center" align="center">
<v-btn color="teal-darken-1"
@click="isActive.value = false">ЗАКРЫТЬ</v-btn>
</v-row>
</v-card>
</v-row>
</template>
</v-dialog>
</v-col> -->
<!-- <v-col v-else justify="center" align="center" cols="6" class="procent_card_font pa-0">
<span>{{ (Math.round(((voteresults.usersvotedbest.filter(e=>e.department_user==mydepartment[0].department).length )*100/(mydepartment.length+1)).toFixed(2)))}}%</span>
</v-col> -->
<!-- <v-col v-else justify="center" align="center" cols="6" class="procent_card_font pa-0">
<span>{{ Math.round((voteresults.uservotedthanks.length*100/(allsorted.length+1)).toFixed(2))}}%</span>
</v-col> -->
<!-- </v-col> -->
<!-- <v-col cols="12" class="d-flex justify-center align-start pa-0">
<v-col justify="center" align="center" cols="6" class="vote-cards_cell ">
</v-col>
</v-col> -->
<!-- Голосование Спасибо КОНЕЦ-->
</v-row>
</template>
<script>
@@ -209,7 +160,7 @@ export default {
},
setup() {
const voteform=ref(null)
const voted_best = ref([])
const full_list_pers = ref([])
@@ -224,40 +175,15 @@ export default {
const isFlipped2 = ref(false);
const voteresults = ref({ usersvotedbest: [], uservotedthanks: [] })
// const isVoted = () => {
// clearAxios.get(`/api/vote/getthanks/`).then((data) => {
// votedListThn = data.data;
// let finded_thn = votedListThn.find(({ voted_user }) => voted_user === account_login)
// if (finded_thn.voted_user === account_login) {
// voted_thn.value = true;
// }
// });
// clearAxios.get(`/api/vote/getbest/`).then((data) => {
// votedListBst = data.data;
// let finded_bst = votedListBst.find(({ voted_user }) => voted_user === account_login)
// if (finded_bst.voted_user === account_login) {
// voted_bst.value = true;
// }
// });
// }
axiosApiInstance.get('/api/vote/getvoteinfo/').then((res) => {
allcod.value = res.data.allcod
// console.log(account_login.user);
myrealdep.value = allcod.value.find(e => e.login === account_login.user.login)
console.log(myrealdep.value);
// uservoted.value = res.data.uservoted
voteresults.value = res.data.voteresults
console.log(res.data.voteresults);
})
const toggleFlip1 = () => {
isFlipped1.value = !isFlipped1.value;
};
const toggleFlip2 = () => {
isFlipped2.value = !isFlipped2.value;
@@ -265,11 +191,10 @@ export default {
if (['9966-00-134', '9966-00-141', '9966-00-011', '9966-00-125'].includes(account_login.user.login)) {
admin_panel.value = true;
}
const allsorted = computed({
get() {
let all = allcod.value.filter(e => e.id != myrealdep.value.id)
let all = allcod.value.filter(e => e.id !== myrealdep.value.id)
return all.sort((a, b) => {
if (b.fio > a.fio) return -1
else if (b.fio < a.fio) return 1
@@ -277,14 +202,10 @@ export default {
})
}
})
// isVoted();
const uservotedthanks = computed({
get() {
let ind = voteresults.value.uservotedthanks.findIndex(e => e.voted_user === account_login.user.login)
if (ind > -1) return false
return true
}
@@ -292,7 +213,6 @@ export default {
const uservotedbest = computed({
get() {
let ind = voteresults.value.usersvotedbest.findIndex(e => e.voted_user === account_login.user.login)
if (ind > -1) return false
return true
@@ -300,7 +220,6 @@ export default {
})
const mydepartment = computed({
get() {
console.log(allcod.value);
let ac = allcod.value.filter(e => e.id_dict_department === myrealdep.value.id_dict_department && e.id != myrealdep.value.id)
return ac.sort((a, b) => {
if (b.fio > a.fio) return -1
@@ -340,8 +259,6 @@ export default {
height: 600px !important;
}
.flip-card-inner {
display: flex;
position: relative;
@@ -364,56 +281,14 @@ export default {
transform: rotateY(-180deg);
}
.vote-card-title {
background-color: rgba(255, 255, 255, 0.1);
color: white;
font-size: 1.7em;
}
.vote-button {
margin-top: 57px;
}
.vote-cards_cell {
height: 2% !important;
}
.procent_card_font {
font-size: 5em;
color: #008000;
}
.card-count {
font-size: 3em;
}
.you-voted {
background-color: rgba(182, 182, 182, 0.4);
color: #ffff;
border-radius: 5px;
}
.vote-card-information {
background-color: rgba(255, 255, 255, 0.7);
margin-top: 20%;
width: 460px;
height: 200px;
}
.vote-card-information-title {
font-size: 1.2em;
}
.vote-title {
font-size: 1.8em;
font-weight: 400;
}
.vote-main-title {
font-size: 2.3em;
font-weight: 400;
}</style>
</style>
+246
View File
@@ -0,0 +1,246 @@
<template>
<v-container>
<v-stepper v-model="step" editable>
<!-- Заголовки шагов -->
<v-stepper-header>
<v-stepper-item :complete="step > 0" step="1">Основная информация</v-stepper-item>
<v-divider></v-divider>
<v-stepper-item :complete="step > 1" step="2">Создание опроса</v-stepper-item>
<v-divider></v-divider>
<v-stepper-item :complete="step > 2" step="3">Настройка ответов</v-stepper-item>
<v-divider></v-divider>
<v-stepper-item step="4">Подтверждение</v-stepper-item>
</v-stepper-header>
<!-- Контент шагов -->
<v-stepper-window>
<v-stepper-window-item step="1">
<v-card flat>
<v-card-title>Основная информация</v-card-title>
<v-card-text>
<v-text-field v-model="form.title" label="Название голосования" outlined></v-text-field>
<v-textarea v-model="form.description" label="Описание" outlined></v-textarea>
<v-text-field
:placeholder="form.startDate.toLocaleDateString()"
:value="form.startDate.toLocaleDateString()"
color="primary"
label="Дата начала"
persistentPlaceholder
readonly
>
<v-menu activator="parent">
<v-date-picker
v-model="form.startDate"
color="primary"
hideHeader
hideWeekdays
>
</v-date-picker>
</v-menu>
<v-btn flat icon style="background-color: transparent">
<v-icon>mdi-calendar</v-icon>
</v-btn>
</v-text-field>
<v-text-field
:placeholder="form.endDate.toLocaleDateString()"
:value="form.endDate.toLocaleDateString()"
color="primary"
label="Дата окончания"
persistentPlaceholder
readonly
>
<v-menu activator="parent">
<v-date-picker
v-model="form.endDate"
color="primary"
hideHeader
hideWeekdays
>
</v-date-picker>
</v-menu>
<v-btn flat icon style="background-color: transparent">
<v-icon>mdi-calendar</v-icon>
</v-btn>
</v-text-field>
</v-card-text>
<v-card-actions>
<v-btn color="primary" @click="step = 1">Далее</v-btn>
</v-card-actions>
</v-card>
</v-stepper-window-item>
<v-stepper-window-item step="2">
<v-card flat>
<v-card-title>Создание опроса</v-card-title>
<v-card-text>
<v-text-field v-model="form.question" label="Текст опроса" outlined></v-text-field>
<v-select v-model="form.type" :items="questionTypes" label="Тип ответа" outlined></v-select>
<v-file-input v-model="form.image" label="Картинка для вопроса" outlined></v-file-input>
</v-card-text>
<v-card-actions>
<v-btn color="primary" @click="step-=1">Назад</v-btn>
<v-btn color="primary" @click="step = 2">Далее</v-btn>
</v-card-actions>
</v-card>
</v-stepper-window-item>
<v-stepper-window-item step="3">
<v-card flat>
<v-card-title>Настройка ответов</v-card-title>
<v-card-text>
<div v-if="form.type === 'Ввести вручную'">
<div v-for="(answer, index) in form.answers" :key="index" class="d-flex align-start">
<v-text-field
v-model="answer.text"
:label="'Ответ ' + (index + 1)"
outlined
></v-text-field>
<v-file-input
v-model="answer.image"
accept="image/*"
dense
hide-details
label="Картинка"
outlined
></v-file-input>
<v-btn
color="red-lighten-2"
icon
@click="removeManualAnswer(index)"
>
<v-icon>mdi-delete</v-icon>
</v-btn>
</div>
<v-btn color="primary" @click="addManualAnswer">Добавить ответ</v-btn>
</div>
<div v-else>
<v-autocomplete
v-model="form.selectedEmployees"
:items="groupedEmployees"
item-title="fio"
item-value="id"
label="Выберите сотрудников"
multiple
outlined
></v-autocomplete>
<div v-for="(person, index) in form.selectedEmployees" :key="person.id"
style="display: flex; align-items: center; gap: 16px; margin-bottom: 8px;">
<v-chip>{{ findEmployeeById(person).fio }}</v-chip>
<v-file-input
v-model="employeeImages[person]"
accept="image/*"
dense
hide-details
label="Картинка"
outlined
style="flex-grow: 1;"
></v-file-input>
<v-btn
color="red-lighten-2"
icon
@click="removeEmployee(index)"
>
<v-icon>mdi-delete</v-icon>
</v-btn>
</div>
</div>
</v-card-text>
<v-card-actions>
<v-btn color="primary" @click="step -= 1">Назад</v-btn>
<v-btn color="primary" @click="step = 3">Далее</v-btn>
</v-card-actions>
</v-card>
</v-stepper-window-item>
<v-stepper-window-item step="4">
<v-card flat>
<v-card-title>Подтверждение</v-card-title>
<v-card-text>
<p><strong>Название:</strong> {{ form.title }}</p>
<p><strong>Описание:</strong> {{ form.description }}</p>
<p><strong>Вопрос:</strong> {{ form.question }}</p>
<p><strong>Тип вопроса:</strong> {{ form.type }}</p>
<p><strong>Варианты ответа:</strong>
{{ form.type === 'Ввести вручную' ? form.answers : form.selectedEmployees }}</p>
<p><strong>Картинка:</strong> {{ form.image ?? 'отсутсвует' }}</p>
</v-card-text>
<v-card-actions>
<v-btn color="primary" @click="step -=1 ">Назад</v-btn>
<v-btn color="primary" @click="saveVoting">Сохранить</v-btn>
</v-card-actions>
</v-card>
</v-stepper-window-item>
</v-stepper-window>
</v-stepper>
</v-container>
</template>
<script>
import {ref} from "vue";
export default {
setup() {
const step = ref(0);
const form = ref({
title: "",
description: "",
startDate: new Date(),
endDate: new Date(new Date().setDate(new Date().getDate() + 14)), // добавляем 14 дней,
question: '',
answers: [],
type: '',
image: null,
selectedEmployees: [],
});
const employeeImages = ref({});
const findEmployeeById = (id) => {
return groupedEmployees.find((employee) => employee.id === id) || {};
};
const removeEmployee = (index) => {
const employeeId = form.value.selectedEmployees[index];
delete employeeImages.value[employeeId];
form.value.selectedEmployees.splice(index, 1);
};
const questionTypes = ["Ввести вручную", "Выбрать сотрудника"];
const groupedEmployees = [
{id: 11, fio: "Иван Иванов", department: "Отдел A"},
{id: 22, fio: "Петр Петров", department: "Отдел B"},
];
const removeManualAnswer = (index) => {
form.value.answers.splice(index, 1);
};
const addManualAnswer = () => {
form.value.answers.push({text: "", image: null});
};
const saveVoting = () => {
console.log("Голосование сохранено:", form.value);
};
return {
step,
form,
questionTypes,
groupedEmployees,
addManualAnswer,
saveVoting,
removeManualAnswer,
removeEmployee,
findEmployeeById,
employeeImages
};
},
};
</script>
<style scoped>
</style>