Merge branch 'develop' into Alex
This commit is contained in:
commit
b829574822
17 files changed
+751
-348
No files matched your search
+2
-2
@@ -2,8 +2,8 @@ env/
|
||||
/__pycache__/
|
||||
/*/__pycache__/
|
||||
/*/migrations/
|
||||
portal/ds.py
|
||||
/front/node_modules/
|
||||
*.sqlite3
|
||||
/media/
|
||||
/static/
|
||||
/static/
|
||||
*.env
|
||||
@@ -0,0 +1,6 @@
|
||||
ENGINE=django.db.backends.mysql
|
||||
DBNAME = accounting
|
||||
USER =
|
||||
PASSWORD=
|
||||
HOST=127.0.0.1
|
||||
PORT=3306
|
||||
+12
-6
@@ -1,19 +1,25 @@
|
||||
from datetime import timedelta
|
||||
from dotenv import load_dotenv
|
||||
import os
|
||||
dotenv_path = os.path.join(os.path.dirname(__file__), '.env')
|
||||
load_dotenv(dotenv_path)
|
||||
class Settings():
|
||||
def __init__(self) -> None:
|
||||
|
||||
self.secret_key='V7bvDZMztr3EU8S9g1Dipw'
|
||||
self.redis_hosts = [("127.0.0.1", 6379)]
|
||||
self.access_token_lifetime = timedelta(minutes=480)
|
||||
self.refresh_token_lifetime = timedelta(days=1)
|
||||
self.db = {
|
||||
'default':{
|
||||
'ENGINE': 'django.db.backends.mysql',
|
||||
'NAME': 'accounting',
|
||||
'USER': 'root',
|
||||
'PASSWORD': 'admin',
|
||||
'HOST': '127.0.0.1',
|
||||
'PORT': '3306',
|
||||
'ENGINE': str(os.getenv('ENGINE')),
|
||||
'NAME': str(os.getenv('DBNAME')),
|
||||
'USER': str(os.getenv('USER')),
|
||||
'PASSWORD': str(os.getenv('PASSWORD')),
|
||||
'HOST': str(os.getenv('HOST')),
|
||||
'PORT': str(os.getenv('PORT')),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pass
|
||||
@@ -1,8 +0,0 @@
|
||||
class Settings():
|
||||
def __init__(self) -> None:
|
||||
self.secret_key=''
|
||||
self.redis_hosts = []
|
||||
self.db = {
|
||||
}
|
||||
|
||||
pass
|
||||
@@ -24,6 +24,7 @@ SECRET_KEY=stngs.secret_key
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
myDEBUG=True
|
||||
|
||||
SWAGGER_SETTINGS = {
|
||||
'DEFAULT_INFO': 'import.path.to.urls.api_info',
|
||||
'SECURITY_DEFINITIONS': {
|
||||
@@ -175,10 +176,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/'
|
||||
|
||||
+1
-12
@@ -1,15 +1,4 @@
|
||||
from django.contrib import admin
|
||||
from .models import *
|
||||
|
||||
# Register your models here.
|
||||
admin.site.register(ThanksVote)
|
||||
admin.site.register(BestVote)
|
||||
|
||||
|
||||
|
||||
class DictEmplyeeRAdmin(admin.ModelAdmin):
|
||||
list_display=('id_dict_employee', 'id_dict_department',)
|
||||
list_editable=('id_dict_department', )
|
||||
|
||||
|
||||
admin.site.register(DictEmplyeeR, DictEmplyeeRAdmin)
|
||||
admin.site.register(Vote)
|
||||
@@ -4,4 +4,5 @@ from django.apps import AppConfig
|
||||
class VoteConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'vote'
|
||||
verbose_name = 'Голосование'
|
||||
|
||||
+34
-32
@@ -1,43 +1,45 @@
|
||||
from django.db import models
|
||||
from userauth.models import *
|
||||
from accounts.models import User
|
||||
import datetime
|
||||
# Create your models here.
|
||||
|
||||
|
||||
class ThanksVote(models.Model):
|
||||
voted_user = models.CharField(blank=False, max_length=255)
|
||||
department_user = models.CharField(
|
||||
blank=False, default=None, max_length=255)
|
||||
cand_name = models.CharField(blank=False, default=None, max_length=255)
|
||||
vote_thanks_date = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
class Meta:
|
||||
verbose_name = "Голосование, хочу сказать спасибо!"
|
||||
verbose_name_plural = "Голосование, хочу сказать спасибо!"
|
||||
class Vote(models.Model):
|
||||
name = models.CharField(max_length=255,verbose_name='Название голосования')
|
||||
description = models.TextField(verbose_name='Описание')
|
||||
datestart = models.DateTimeField(default=datetime.datetime.now, verbose_name='Дата и время начала периода')
|
||||
dateend = models.DateTimeField(default=datetime.datetime.now, verbose_name='Дата и время окончания периода')
|
||||
settings = models.JSONField(default=dict, verbose_name='Json настроек голосования')
|
||||
author = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='Создатель голосования')
|
||||
|
||||
def __str__(self):
|
||||
return self.cand_name
|
||||
|
||||
|
||||
class BestVote(models.Model):
|
||||
voted_user = models.CharField(blank=False, max_length=255)
|
||||
department_user = models.CharField(
|
||||
blank=False, default=None, max_length=255)
|
||||
cand_name = models.CharField(blank=False, default=None, max_length=255)
|
||||
vote_best_date = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
return self.name
|
||||
|
||||
class Meta:
|
||||
verbose_name = "Голосование, мой коллега самый лучший"
|
||||
verbose_name_plural = "Голосование, мой коллега самый лучший"
|
||||
verbose_name = "Голосование"
|
||||
verbose_name_plural = "Голосования"
|
||||
|
||||
class Question(models.Model):
|
||||
question = models.CharField(max_length=255)
|
||||
vote = models.ForeignKey(Vote, related_name='questions', on_delete=models.CASCADE)
|
||||
file = models.ImageField(upload_to='question_images/', null=True, blank=True)
|
||||
numb = models.PositiveIntegerField()
|
||||
|
||||
def __str__(self):
|
||||
return self.cand_name
|
||||
return self.question
|
||||
|
||||
class Answer(models.Model):
|
||||
answer = models.CharField(max_length=255)
|
||||
file = models.FileField(upload_to='answer_files/', null=True, blank=True)
|
||||
question = models.ForeignKey(Question, related_name='answers', on_delete=models.CASCADE)
|
||||
|
||||
class DictEmplyeeR(models.Model):
|
||||
# id = models.IntegerField(primary_key=True)
|
||||
id_dict_employee = models.ForeignKey(DictEmployee, models.DO_NOTHING)
|
||||
id_dict_department = models.ForeignKey(DictDepartment, models.DO_NOTHING)
|
||||
class Meta:
|
||||
verbose_name = "Сотрудники(реальные отделы)"
|
||||
verbose_name_plural = "Сотрудники(реальные отделы)"
|
||||
def __str__(self):
|
||||
return str(self.id_dict_employee)
|
||||
return self.answer
|
||||
|
||||
class Result(models.Model):
|
||||
user = models.ForeignKey(DictEmployee, on_delete=models.CASCADE)
|
||||
answer = models.ForeignKey(Answer, on_delete=models.CASCADE)
|
||||
comment = models.TextField(null=True, blank=True)
|
||||
|
||||
def __str__(self):
|
||||
return f'Result by {self.user.username} for {self.answer.answer}'
|
||||
@@ -3,33 +3,26 @@ from .models import *
|
||||
from userauth.models import *
|
||||
|
||||
|
||||
class GetEmpSerializer(serializers.ModelSerializer):
|
||||
class VoteSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = DictEmployee
|
||||
fields = ['id', 'id_dict_department',
|
||||
'fio', 'post', 'department']
|
||||
model = Vote
|
||||
fields = '__all__'
|
||||
|
||||
class GetEmpSerializerR(serializers.ModelSerializer):
|
||||
id = serializers.IntegerField(source="id_dict_employee.id")
|
||||
fio = serializers.CharField(source="id_dict_employee.fio")
|
||||
id_dict_department = serializers.IntegerField(source="id_dict_department.id")
|
||||
post = serializers.CharField(source="id_dict_employee.post")
|
||||
department = serializers.CharField(source="id_dict_department.name")
|
||||
login=serializers.CharField(source='id_dict_employee.login')
|
||||
|
||||
class QuestionSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = DictEmplyeeR
|
||||
fields = ['id', 'id_dict_department',
|
||||
'fio', 'post', 'department','login']
|
||||
model = Question
|
||||
fields = '__all__'
|
||||
|
||||
class AnswerSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Answer
|
||||
fields = '__all__'
|
||||
|
||||
class ThanksVoteSerializer(serializers.ModelSerializer):
|
||||
class ResultSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = ThanksVote
|
||||
fields = ('id', 'voted_user', 'cand_name', 'vote_thanks_date','department_user')
|
||||
model = Result
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class BestVoteSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = BestVote
|
||||
fields = ('id', 'voted_user', 'cand_name', 'vote_best_date', 'department_user')
|
||||
class VoteResultSerializer(serializers.Serializer):
|
||||
answer = serializers.CharField(source='answer__answer')
|
||||
count = serializers.IntegerField()
|
||||
+1
-14
@@ -4,18 +4,5 @@ from .views import *
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
path('get_for_thn/', GetForThn.as_view(),),
|
||||
path('get_for_bst/', GetForBst.as_view(),),
|
||||
path('setthanks/', SetThanks.as_view(), name=''),
|
||||
path('getthanks/', GetThanks.as_view(), name=''),
|
||||
path('setbest/', SetBest.as_view(), name=''),
|
||||
path('getbest/', GetBest.as_view(), name=''),
|
||||
path('getnotvotethn/', GetNotVoteThn.as_view()),
|
||||
path('getnotvotebst/', GetNotVoteBst.as_view()),
|
||||
|
||||
|
||||
path('getvoteinfo/', GetVoteInfo.as_view()),
|
||||
|
||||
|
||||
|
||||
path('getvotes/', GetVotes.as_view(),name='GetVotes'),
|
||||
]
|
||||
+57
-91
@@ -5,98 +5,64 @@ from django.db.models import Q
|
||||
from .models import *
|
||||
from userauth.models import *
|
||||
from .serializers import *
|
||||
import datetime
|
||||
|
||||
# Create your views here.
|
||||
class GetVotes(APIView):
|
||||
|
||||
|
||||
class GetForThn(APIView):
|
||||
def get(self, request):
|
||||
user_login = request.GET.get('login')
|
||||
all_emps = DictEmplyeeR.objects.exclude(id_dict_employee__login=user_login).exclude(id_dict_department__name='Руководство').exclude(id_dict_employee__deleted=1).order_by('id_dict_employee__fio')
|
||||
return Response(GetEmpSerializerR(all_emps, many=True).data)
|
||||
|
||||
|
||||
class GetForBst(APIView):
|
||||
def get(self, request):
|
||||
user_login = request.GET.get('login')
|
||||
dep_id = DictEmplyeeR.objects.get(id_dict_employee__login=user_login)
|
||||
emp_user = DictEmplyeeR.objects.filter(Q(id_dict_department=dep_id.id_dict_department), ~Q(id_dict_employee__login=user_login)).exclude(id_dict_employee__deleted=1).order_by('id_dict_employee__fio')
|
||||
return Response(GetEmpSerializerR(emp_user, many=True).data)
|
||||
|
||||
|
||||
class SetThanks(APIView):
|
||||
def post(self, request):
|
||||
# department_user = request.data['department_user']
|
||||
cand_name = request.data['cand_name_id']
|
||||
depuser = DictEmplyeeR.objects.get(id_dict_employee__fio=cand_name)
|
||||
ThanksVote.objects.create(
|
||||
voted_user=request.user,
|
||||
department_user=depuser.id_dict_department.name,
|
||||
cand_name=cand_name
|
||||
)
|
||||
return Response("Ваш голос добавлен!")
|
||||
|
||||
|
||||
class GetThanks(APIView):
|
||||
def get(self, request):
|
||||
# Группировка кандидатов по имени и подсчет каждого
|
||||
count_thanks = ThanksVote.objects.values('voted_user',
|
||||
'cand_name').annotate(total=Count('id')).order_by('cand_name')
|
||||
return Response(count_thanks)
|
||||
|
||||
|
||||
class SetBest(APIView):
|
||||
def post(self, request):
|
||||
voted_user = request.user
|
||||
# department_user = request.data['department_user']
|
||||
cand_name = request.data['cand_name_id']
|
||||
depuser = DictEmplyeeR.objects.get(id_dict_employee__fio=cand_name)
|
||||
BestVote.objects.create(
|
||||
voted_user=voted_user,
|
||||
department_user=depuser.id_dict_department.name,
|
||||
cand_name=cand_name
|
||||
)
|
||||
return Response("Ваш голос добавлен!")
|
||||
|
||||
|
||||
|
||||
class GetBest(APIView):
|
||||
def get(self, request):
|
||||
# Группировка кандидатов по имени и подсчет каждого
|
||||
count_bests = BestVote.objects.values('voted_user','department_user', 'cand_name').annotate(total=Count('id')).order_by('cand_name')
|
||||
return Response(count_bests)
|
||||
|
||||
|
||||
class GetNotVoteThn(APIView):
|
||||
def get(self, request):
|
||||
list_thn_users = ThanksVote.objects.values('voted_user')
|
||||
list_emp = DictEmplyeeR.objects.filter(
|
||||
id_dict_employee__deleted=0).exclude(id_dict_employee__login__in=list_thn_users).exclude(id_dict_employee__department='Руководство').order_by('id_dict_employee__fio')
|
||||
return Response(GetEmpSerializerR(list_emp, many=True).data)
|
||||
|
||||
|
||||
class GetNotVoteBst(APIView):
|
||||
def get(self, request):
|
||||
list_bst_users = BestVote.objects.values('voted_user')
|
||||
list_emp_bst = DictEmplyeeR.objects.filter(
|
||||
id_dict_employee__deleted=0).exclude(id_dict_employee__login__in=list_bst_users).exclude(id_dict_employee__department='Руководство').order_by('id_dict_employee__fio')
|
||||
return Response(GetEmpSerializerR(list_emp_bst, many=True).data)
|
||||
|
||||
class GetVoteInfo(APIView):
|
||||
def get(self, request):
|
||||
print(request.user)
|
||||
allcod = DictEmplyeeR.objects.filter( id_dict_employee__deleted=0)
|
||||
|
||||
# try:
|
||||
realdep = allcod.get(id_dict_employee__login=request.user)
|
||||
|
||||
usersvotedbest=BestVote.objects.filter()
|
||||
user = request.user
|
||||
# user = DictEmployee.objects.get(login='9966-00-125')
|
||||
now = datetime.datetime.now()
|
||||
status = request.query_params.get('status')
|
||||
print(status)
|
||||
votes = self.get_votes_by_status(status, now)
|
||||
serialized_votes = VoteSerializer(votes, many=True).data
|
||||
|
||||
uservotedthanks=ThanksVote.objects.all()
|
||||
|
||||
return Response({'allcod':GetEmpSerializerR(allcod, many=True).data,
|
||||
'voteresults':{'uservotedthanks': ThanksVoteSerializer(uservotedthanks,many=True).data,
|
||||
'usersvotedbest':BestVoteSerializer(usersvotedbest, many=True).data,
|
||||
}
|
||||
}
|
||||
)
|
||||
for vote in serialized_votes:
|
||||
vote['is_passed'] = self.has_participated(user, vote['id'])
|
||||
|
||||
return Response(serialized_votes)
|
||||
|
||||
def get_votes_by_status(self, status, now):
|
||||
status_filters = {
|
||||
'active': Vote.objects.filter(dateend__gt=now),
|
||||
'completed': Vote.objects.filter(dateend__lt=now),
|
||||
}
|
||||
|
||||
return status_filters.get(status, Vote.objects.none()).order_by('dateend')
|
||||
|
||||
def has_participated(self, employee, vote):
|
||||
return Result.objects.filter(user=employee, answer__question__vote=vote).exists()
|
||||
|
||||
def create_vote(self, request):
|
||||
vote = Vote(
|
||||
name=request.data['name'],
|
||||
description=request.data['description'],
|
||||
datestart=request.data['datestart'],
|
||||
dateend=request.data['dateend'],
|
||||
settings=request.data.get('settings', {}),
|
||||
author=request.user,
|
||||
)
|
||||
vote.save()
|
||||
|
||||
def delete_vote(self,request):
|
||||
vote_id = request.data.get('vote_id')
|
||||
vote = Vote.objects.get(id=vote_id)
|
||||
questions = vote.questions.all()
|
||||
for question in questions:
|
||||
answers = question.answers.all()
|
||||
answers.delete()
|
||||
|
||||
questions.delete()
|
||||
|
||||
results = Result.objects.filter(answer__question__vote=vote)
|
||||
results.delete()
|
||||
|
||||
vote.delete()
|
||||
|
||||
def get_vote_results(self, request):
|
||||
vote_id = request.data.get('vote_id')
|
||||
vote = Vote.objects.get(id=vote_id)
|
||||
results = Result.objects.filter(answer__question__vote=vote).values('answer__answer').annotate(count=Count('id'))
|
||||
serialized_results = VoteResultSerializer(results, many=True).data
|
||||
return Response(serialized_results)
|
||||
@@ -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