Merge branch 'develop' into Alex
This commit is contained in:
commit
b829574822
17 files changed
+751
-348
No files matched your search
@@ -141,17 +141,16 @@ const routes = [
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
path: "/vote",
|
||||
name: "Vote",
|
||||
component: () =>
|
||||
import("@/views/Vote.vue")
|
||||
},
|
||||
{
|
||||
path: "/secret",
|
||||
name: "Secret Page",
|
||||
path: "/votehomepage",
|
||||
name: "VoteHomePage",
|
||||
component: () =>
|
||||
import("@/views/secret/SecretPage.vue")
|
||||
import("@/views/VoteHomePage.vue")
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
@@ -2,7 +2,7 @@ import {useAccountStore} from '@/store/AccountStore'
|
||||
import axios from "axios";
|
||||
const spravURL = 'http://10.252.44.33/accounting6/images/photo/'
|
||||
const spravURLBase = 'http://10.252.44.33/accounting6/'
|
||||
const baseURL = process.env.NODE_ENV == 'development'? 'http://127.0.0.1:8000/': `http://${window.location.host}/`;
|
||||
const baseURL = process.env.NODE_ENV === 'development'? 'http://127.0.0.1:8000/': `http://${window.location.host}/`;
|
||||
const baseWS = process.env.NODE_ENV == 'development'? 'ws://127.0.0.1:8000/': `ws://${window.location.host}/`;
|
||||
// const baseURL = process.env.NODE_ENV == 'development'? 'http://127.0.0.1:8000/': `http://10.252.44.60:9965/`;
|
||||
// const baseWS = process.env.NODE_ENV == 'development'? 'ws://127.0.0.1:8000/': `ws://10.252.44.60:9966/`;
|
||||
@@ -17,18 +17,18 @@ async function refreshToken() {
|
||||
const result = await axios.post('/api/accounts/token/refresh/', {refresh}, {
|
||||
baseURL
|
||||
})
|
||||
|
||||
|
||||
if (result.config.data) localStorage.setItem('refresh', JSON.parse(result.config.data).refresh);
|
||||
localStorage.setItem('access', result.data.access)
|
||||
|
||||
return result.data.access;
|
||||
}
|
||||
|
||||
catch(e) {
|
||||
const accountStore = useAccountStore()
|
||||
|
||||
catch(e) {
|
||||
const accountStore = useAccountStore()
|
||||
accountStore.logout()
|
||||
accountStore.cod2user.value=false
|
||||
|
||||
|
||||
return Promise.reject(e);
|
||||
}
|
||||
}
|
||||
@@ -46,7 +46,7 @@ axiosApiInstance.defaults.headers.common['Authorization'] = `Bearer ${localStora
|
||||
axiosApiInstance.interceptors.request.use(config => {
|
||||
const access = localStorage.getItem('access');
|
||||
if (access) {
|
||||
config.headers = {
|
||||
config.headers = {
|
||||
'Authorization': `Bearer ${access}`,
|
||||
}
|
||||
}
|
||||
@@ -63,30 +63,63 @@ async error => {
|
||||
|
||||
const originalRequest = error.config;
|
||||
if ((error.response.status === 401 || error.response.status === 403) && !originalRequest._retry) {
|
||||
|
||||
|
||||
originalRequest._retry = true;
|
||||
try {
|
||||
|
||||
const token = await refreshToken();
|
||||
|
||||
axiosApiInstance.defaults.headers.common['Authorization'] = `Bearer ${token}`;
|
||||
|
||||
|
||||
axiosApiInstance.defaults.headers.common['Authorization'] = `Bearer ${token}`;
|
||||
|
||||
if (originalRequest.data){
|
||||
originalRequest.data = JSON.parse(originalRequest.data); }
|
||||
|
||||
originalRequest.data = JSON.parse(originalRequest.data); }
|
||||
|
||||
return axiosApiInstance(originalRequest);
|
||||
|
||||
} catch(e) {
|
||||
|
||||
//
|
||||
} catch(e) {
|
||||
|
||||
//
|
||||
// if (window.location.pathname!='/auth') window.location.reload()
|
||||
// window.location.reload()
|
||||
|
||||
|
||||
return Promise.reject(error);
|
||||
}
|
||||
}
|
||||
return Promise.reject(error);
|
||||
})
|
||||
|
||||
async function getVotes(status) {
|
||||
try {
|
||||
const response = await axiosApiInstance.get(`/api/vote/getvotes?status=${status}`,
|
||||
// {
|
||||
// params: {
|
||||
// status,
|
||||
// }
|
||||
// }
|
||||
);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error('Ошибка запроса голосования:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export { axiosApiInstance, clearAxios, baseURL,spravURL, spravURLBase, baseWS }
|
||||
getVotes('completed')
|
||||
.then(data => {
|
||||
console.log('Завершённые голосования:', data);
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('Ошибка:', err);
|
||||
});
|
||||
|
||||
getVotes('active')
|
||||
.then(data => {
|
||||
console.log('Активные голосования:', data);
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('Ошибка:', err);
|
||||
});
|
||||
|
||||
|
||||
|
||||
export { axiosApiInstance, clearAxios, baseURL,spravURL, spravURLBase, baseWS, getVotes }
|
||||
@@ -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>
|
||||
@@ -0,0 +1,325 @@
|
||||
<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="teal-darken-4"
|
||||
label="Дата начала"
|
||||
persistentPlaceholder
|
||||
readonly
|
||||
>
|
||||
<v-menu activator="parent">
|
||||
<v-date-picker
|
||||
v-model="form.startDate"
|
||||
color="teal-darken-4"
|
||||
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="teal-darken-4"
|
||||
label="Дата окончания"
|
||||
persistentPlaceholder
|
||||
readonly
|
||||
>
|
||||
<v-menu activator="parent">
|
||||
<v-date-picker
|
||||
v-model="form.endDate"
|
||||
color="teal-darken-4"
|
||||
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="teal-darken-4" @click="step = 1" size="medium">Далее</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>
|
||||
<div v-for="(question, index) in form.questions" :key="index" class="mb-4">
|
||||
<v-text-field
|
||||
v-model="question.text"
|
||||
:label="'Вопрос ' + (index + 1)"
|
||||
outlined
|
||||
></v-text-field>
|
||||
<v-file-input
|
||||
v-model="question.image"
|
||||
accept="image/*"
|
||||
label="Картинка для вопроса"
|
||||
outlined
|
||||
></v-file-input>
|
||||
<v-select
|
||||
v-model="question.type"
|
||||
:items="questionTypes"
|
||||
label="Тип ответа"
|
||||
outlined
|
||||
></v-select>
|
||||
<v-btn color="error" icon @click="removeQuestion(index)">
|
||||
<v-icon>mdi-delete</v-icon>
|
||||
</v-btn>
|
||||
</div>
|
||||
<v-btn color="teal-darken-4" @click="addQuestion">Добавить вопрос</v-btn>
|
||||
</v-card-text>
|
||||
<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 = 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-select
|
||||
v-model="currentQuestionIndex"
|
||||
:items="form.questions.map((q, i) => ({ text: `Вопрос ${i + 1}: ${q.text || 'Без названия'}`, value: i }))"
|
||||
class="ml-4"
|
||||
dense
|
||||
item-title="text"
|
||||
item-value="value"
|
||||
label="Выберите вопрос"
|
||||
outlined
|
||||
></v-select>
|
||||
</v-card-title>
|
||||
<v-card-text>
|
||||
<div v-if="currentQuestion">
|
||||
<div v-if="currentQuestion.type === 'Ввести вручную'">
|
||||
<div
|
||||
v-for="(answer, index) in currentQuestion.answers"
|
||||
:key="index"
|
||||
class="d-flex align-start mb-4"
|
||||
>
|
||||
<v-text-field
|
||||
v-model="answer.text"
|
||||
:label="'Ответ ' + (index + 1)"
|
||||
class="mr-4"
|
||||
outlined
|
||||
></v-text-field>
|
||||
<v-file-input
|
||||
v-model="answer.image"
|
||||
accept="image/*"
|
||||
dense
|
||||
hide-details
|
||||
label="Картинка"
|
||||
outlined
|
||||
></v-file-input>
|
||||
<v-btn color="error" icon @click="removeAnswer(index)">
|
||||
<v-icon>mdi-delete</v-icon>
|
||||
</v-btn>
|
||||
</div>
|
||||
<v-btn color="primary" @click="addAnswer">Добавить ответ</v-btn>
|
||||
</div>
|
||||
<div v-else>
|
||||
<v-autocomplete
|
||||
v-model="currentQuestion.selectedEmployees"
|
||||
:items="groupedEmployees"
|
||||
item-title="fio"
|
||||
item-value="id"
|
||||
label="Выберите сотрудников"
|
||||
multiple
|
||||
outlined
|
||||
></v-autocomplete>
|
||||
<div
|
||||
v-for="(person, index) in currentQuestion.selectedEmployees"
|
||||
:key="person.id"
|
||||
class="d-flex align-center mb-4"
|
||||
>
|
||||
<v-chip>{{ findEmployeeById(person).fio }}</v-chip>
|
||||
<v-file-input
|
||||
v-model="currentQuestion.selectedEmployeeImages[person]"
|
||||
accept="image/*"
|
||||
class="ml-4"
|
||||
dense
|
||||
hide-details
|
||||
label="Картинка"
|
||||
outlined
|
||||
></v-file-input>
|
||||
<v-btn color="error" icon @click="removeEmployee(index)">
|
||||
<v-icon>mdi-delete</v-icon>
|
||||
</v-btn>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else>
|
||||
<p>Выберите вопрос, чтобы добавить ответы.</p>
|
||||
</div>
|
||||
</v-card-text>
|
||||
<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 = 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.startDate.toLocaleDateString() }}</p>
|
||||
<p><strong>Дата окончания:</strong> {{ form.endDate.toLocaleDateString() }}</p>
|
||||
<p><strong>Вопросы:</strong></p>
|
||||
<ul>
|
||||
<li v-for="(question, index) in form.questions" :key="index" class="mb-4">
|
||||
<p><strong>Вопрос {{ index + 1 }}:</strong> {{ question.text }} ({{ question.type }})</p>
|
||||
<div v-if="question.type === 'Ввести вручную' && question.answers.length">
|
||||
<p><strong>Варианты ответов:</strong></p>
|
||||
<ul>
|
||||
<li v-for="(answer, answerIndex) in question.answers" :key="answerIndex">
|
||||
{{ answer.text }}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div v-if="question.type === 'Выбрать сотрудника' && question.selectedEmployees.length">
|
||||
<p><strong>Выбранные сотрудники:</strong></p>
|
||||
<ul>
|
||||
<li
|
||||
v-for="employeeId in question.selectedEmployees"
|
||||
:key="employeeId"
|
||||
>
|
||||
{{ findEmployeeById(employeeId).fio }}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</v-card-text>
|
||||
<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="saveVoting">Сохранить</v-btn>
|
||||
</v-card-actions>
|
||||
</v-card>
|
||||
</v-stepper-window-item>
|
||||
|
||||
</v-stepper-window>
|
||||
</v-stepper>
|
||||
</v-container>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {computed, 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)),
|
||||
questions: [],
|
||||
});
|
||||
|
||||
const currentQuestionIndex = ref(0);
|
||||
const questionTypes = ["Ввести вручную", "Выбрать сотрудника"];
|
||||
|
||||
const groupedEmployees = [
|
||||
{id: 1, fio: "Иван Иванов", department: "Отдел A"},
|
||||
{id: 2, fio: "Петр Петров", department: "Отдел B"},
|
||||
];
|
||||
|
||||
const currentQuestion = computed(() =>
|
||||
form.value.questions[currentQuestionIndex.value] || null
|
||||
);
|
||||
|
||||
const findEmployeeById = (id) =>
|
||||
groupedEmployees.find((employee) => employee.id === id) || {};
|
||||
|
||||
const removeEmployee = (index) => {
|
||||
currentQuestion.value.selectedEmployees.splice(index, 1);
|
||||
};
|
||||
|
||||
const addQuestion = () => {
|
||||
form.value.questions.push({
|
||||
text: "",
|
||||
type: "Ввести вручную",
|
||||
image: null,
|
||||
answers: [],
|
||||
selectedEmployees: [],
|
||||
selectedEmployeeImages: {},
|
||||
});
|
||||
};
|
||||
|
||||
const removeQuestion = (index) => {
|
||||
form.value.questions.splice(index, 1);
|
||||
if (currentQuestionIndex.value >= form.value.questions.length) {
|
||||
currentQuestionIndex.value = form.value.questions.length - 1;
|
||||
}
|
||||
};
|
||||
|
||||
const addAnswer = () => {
|
||||
if (currentQuestion.value) {
|
||||
currentQuestion.value.answers.push({text: "", image: null});
|
||||
}
|
||||
};
|
||||
|
||||
const removeAnswer = (index) => {
|
||||
if (currentQuestion.value) {
|
||||
currentQuestion.value.answers.splice(index, 1);
|
||||
}
|
||||
};
|
||||
|
||||
const saveVoting = () => {
|
||||
console.log("Голосование сохранено:", form.value);
|
||||
};
|
||||
|
||||
return {
|
||||
step,
|
||||
form,
|
||||
questionTypes,
|
||||
groupedEmployees,
|
||||
currentQuestionIndex,
|
||||
currentQuestion,
|
||||
addQuestion,
|
||||
removeQuestion,
|
||||
addAnswer,
|
||||
removeAnswer,
|
||||
findEmployeeById,
|
||||
removeEmployee,
|
||||
saveVoting,
|
||||
};
|
||||
},
|
||||
};
|
||||
</script>
|
||||
@@ -0,0 +1,227 @@
|
||||
<template>
|
||||
<v-container>
|
||||
<v-toolbar color="transparent">
|
||||
<v-toolbar-title>Голосования</v-toolbar-title>
|
||||
|
||||
<template v-slot:extension>
|
||||
<v-tabs v-model="currentTab">
|
||||
<v-tab :key="0" value="current">Текущие голосования</v-tab>
|
||||
<v-tab :key="1" value="completed">Завершенные голосования</v-tab>
|
||||
<v-tab :key="2" value="constructor">Создать новое голосование</v-tab>
|
||||
</v-tabs>
|
||||
</template>
|
||||
</v-toolbar>
|
||||
|
||||
<v-tabs-window v-model="currentTab">
|
||||
<!-- Текущие голосования -->
|
||||
<v-tabs-window-item value="current">
|
||||
<v-container>
|
||||
<v-row>
|
||||
<v-col
|
||||
v-for="voting in sortedCurrentVotes"
|
||||
:key="voting.id"
|
||||
cols="12" lg="3" md="4"
|
||||
>
|
||||
<v-card :class="{ 'voted-card': voting.voted }">
|
||||
<v-card-title class="d-flex justify-space-between">{{ voting.title }}
|
||||
<v-btn flat size="medium">
|
||||
<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" @click="deleteVoting(voting.id)" size="medium">
|
||||
<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="completed">
|
||||
<v-container>
|
||||
<v-row>
|
||||
<v-col
|
||||
v-for="voting in sortedCompletedVotes"
|
||||
:key="voting.id"
|
||||
cols="12" lg="3" md="4"
|
||||
>
|
||||
<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="openResultsModal(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">
|
||||
<VoteConstructor/>
|
||||
</v-tabs-window-item>
|
||||
</v-tabs-window>
|
||||
|
||||
<!-- Модальное окно для голосования -->
|
||||
<v-dialog v-model="voteModal" max-width="600px">
|
||||
<v-card>
|
||||
<v-card-title>Голосование: {{ selectedVoting?.title }}</v-card-title>
|
||||
<v-card-text>
|
||||
<p>Описание голосования...</p>
|
||||
</v-card-text>
|
||||
<v-card-actions>
|
||||
<v-btn color="primary" @click="submitVote">Проголосовать</v-btn>
|
||||
<v-btn @click="closeVoteModal">Закрыть</v-btn>
|
||||
</v-card-actions>
|
||||
</v-card>
|
||||
</v-dialog>
|
||||
|
||||
<!-- Модальное окно для результатов -->
|
||||
<v-dialog v-model="resultsModal" max-width="600px">
|
||||
<v-card>
|
||||
<v-card-title>Результаты голосования: {{ selectedVoting?.title }}</v-card-title>
|
||||
<v-card-text>
|
||||
<p>Здесь отображаются результаты голосования...</p>
|
||||
</v-card-text>
|
||||
<v-card-actions>
|
||||
<v-btn @click="closeResultsModal">Закрыть</v-btn>
|
||||
</v-card-actions>
|
||||
</v-card>
|
||||
</v-dialog>
|
||||
</v-container>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {computed, ref} from "vue";
|
||||
import VoteConstructor from "@/views/VoteConstructor.vue";
|
||||
|
||||
export default {
|
||||
components: {VoteConstructor},
|
||||
setup() {
|
||||
const currentTab = ref("current");
|
||||
const votes = ref([
|
||||
{
|
||||
id: 1,
|
||||
title: "Голосование 1",
|
||||
endDate: new Date(new Date().getTime() + 600000), // 10 минут
|
||||
voted: false,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
title: "Голосование 2",
|
||||
endDate: new Date(new Date().getTime() - 600000), // Уже завершено
|
||||
voted: true,
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
title: "Голосование 3",
|
||||
endDate: new Date(new Date().getTime() + 3600000), // 1 час
|
||||
voted: true,
|
||||
},
|
||||
]);
|
||||
|
||||
const voteModal = ref(false);
|
||||
const resultsModal = ref(false);
|
||||
const selectedVoting = ref(null);
|
||||
|
||||
const sortedCurrentVotes = computed(() => {
|
||||
return votes.value
|
||||
.filter((v) => new Date(v.endDate) > new Date())
|
||||
.sort((a, b) => new Date(a.endDate) - new Date(b.endDate));
|
||||
});
|
||||
|
||||
const sortedCompletedVotes = computed(() => {
|
||||
return votes.value
|
||||
.filter((v) => new Date(v.endDate) <= new Date())
|
||||
.sort((a, b) => new Date(b.endDate) - new Date(a.endDate));
|
||||
});
|
||||
|
||||
const timeRemaining = (endDate) => {
|
||||
const now = new Date();
|
||||
const diff = new Date(endDate) - now;
|
||||
return diff > 0 ? `${Math.floor(diff / 60000)} минут` : "Завершено";
|
||||
};
|
||||
|
||||
const formatDate = (date) => new Date(date).toLocaleString();
|
||||
|
||||
const openVoteModal = (voting) => {
|
||||
selectedVoting.value = voting;
|
||||
voteModal.value = true;
|
||||
};
|
||||
|
||||
const closeVoteModal = () => {
|
||||
voteModal.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;
|
||||
selectedVoting.value = null;
|
||||
};
|
||||
|
||||
const deleteVoting = (id) => {
|
||||
votes.value = votes.value.filter((v) => v.id !== id);
|
||||
};
|
||||
|
||||
return {
|
||||
currentTab,
|
||||
votes,
|
||||
sortedCurrentVotes,
|
||||
sortedCompletedVotes,
|
||||
voteModal,
|
||||
resultsModal,
|
||||
selectedVoting,
|
||||
timeRemaining,
|
||||
formatDate,
|
||||
openVoteModal,
|
||||
closeVoteModal,
|
||||
submitVote,
|
||||
openResultsModal,
|
||||
closeResultsModal,
|
||||
deleteVoting,
|
||||
};
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.voted-card {
|
||||
opacity: 0.6;
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user