P-92 добавление роутов в модалки + валидация формы конструктора
This commit is contained in:
1 parent
99dc314a1f
commit
135c5fb87d
5 files changed
+143
-96
No files matched your search
@@ -15,7 +15,6 @@ class GetVotes(APIView):
|
|||||||
|
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
user = request.user
|
user = request.user
|
||||||
print(type(user))
|
|
||||||
# user = User.objects.get(username='9966-00-125')
|
# user = User.objects.get(username='9966-00-125')
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
status = request.query_params.get('status')
|
status = request.query_params.get('status')
|
||||||
|
|||||||
@@ -25,8 +25,18 @@
|
|||||||
<v-card flat>
|
<v-card flat>
|
||||||
<v-card-title>Основная информация</v-card-title>
|
<v-card-title>Основная информация</v-card-title>
|
||||||
<v-card-text>
|
<v-card-text>
|
||||||
<v-text-field v-model="form.title" label="Название голосования" outlined></v-text-field>
|
<v-text-field
|
||||||
<v-textarea v-model="form.description" label="Описание" outlined></v-textarea>
|
v-model="form.title"
|
||||||
|
label="Название голосования"
|
||||||
|
outlined
|
||||||
|
:rules="[rules.required]"
|
||||||
|
></v-text-field>
|
||||||
|
<v-textarea
|
||||||
|
v-model="form.description"
|
||||||
|
label="Описание"
|
||||||
|
outlined
|
||||||
|
:rules="[rules.required]"
|
||||||
|
></v-textarea>
|
||||||
<v-text-field
|
<v-text-field
|
||||||
:placeholder="form.startDate.toLocaleDateString()"
|
:placeholder="form.startDate.toLocaleDateString()"
|
||||||
:value="form.startDate.toLocaleDateString()"
|
:value="form.startDate.toLocaleDateString()"
|
||||||
@@ -87,6 +97,7 @@
|
|||||||
v-model="question.text"
|
v-model="question.text"
|
||||||
:label="'Вопрос ' + (index + 1)"
|
:label="'Вопрос ' + (index + 1)"
|
||||||
outlined
|
outlined
|
||||||
|
:rules="[rules.required]"
|
||||||
></v-text-field>
|
></v-text-field>
|
||||||
<v-file-input
|
<v-file-input
|
||||||
v-model="question.image"
|
v-model="question.image"
|
||||||
@@ -142,6 +153,7 @@
|
|||||||
:label="'Ответ ' + (index + 1)"
|
:label="'Ответ ' + (index + 1)"
|
||||||
class="mr-4"
|
class="mr-4"
|
||||||
outlined
|
outlined
|
||||||
|
:rules="[rules.required]"
|
||||||
></v-text-field>
|
></v-text-field>
|
||||||
<v-file-input
|
<v-file-input
|
||||||
v-model="answer.image"
|
v-model="answer.image"
|
||||||
@@ -238,6 +250,9 @@
|
|||||||
<v-btn color="teal-darken-4" size="medium" @click="step -= 1">Назад</v-btn>
|
<v-btn color="teal-darken-4" size="medium" @click="step -= 1">Назад</v-btn>
|
||||||
<v-btn color="teal-darken-4" size="medium" @click="saveVoting">Сохранить</v-btn>
|
<v-btn color="teal-darken-4" size="medium" @click="saveVoting">Сохранить</v-btn>
|
||||||
</v-card-actions>
|
</v-card-actions>
|
||||||
|
<v-alert v-if="errorMessage" type="error" class="mb-4">
|
||||||
|
{{ errorMessage }}
|
||||||
|
</v-alert>
|
||||||
</v-card>
|
</v-card>
|
||||||
</v-stepper-window-item>
|
</v-stepper-window-item>
|
||||||
|
|
||||||
@@ -264,6 +279,10 @@ export default {
|
|||||||
questions: [],
|
questions: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const rules = {
|
||||||
|
required: (value) => !!value || "Это поле обязательно для заполнения",
|
||||||
|
};
|
||||||
|
|
||||||
const currentQuestionIndex = ref(0);
|
const currentQuestionIndex = ref(0);
|
||||||
const questionTypes = ["Ввести вручную", "Выбрать сотрудника"];
|
const questionTypes = ["Ввести вручную", "Выбрать сотрудника"];
|
||||||
|
|
||||||
@@ -313,7 +332,13 @@ export default {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const errorMessage = ref("");
|
||||||
|
|
||||||
const saveVoting = async () => {
|
const saveVoting = async () => {
|
||||||
|
if (!form.value.title || !form.value.description || form.value.questions < 1) {
|
||||||
|
errorMessage.value = "Все обязательные поля должны быть заполнены";
|
||||||
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const response = await createVote(form.value);
|
const response = await createVote(form.value);
|
||||||
console.log("Голосование успешно создано:", response);
|
console.log("Голосование успешно создано:", response);
|
||||||
@@ -351,7 +376,9 @@ export default {
|
|||||||
removeEmployee,
|
removeEmployee,
|
||||||
saveVoting,
|
saveVoting,
|
||||||
isVoteCreated,
|
isVoteCreated,
|
||||||
resetForm
|
resetForm,
|
||||||
|
rules,
|
||||||
|
errorMessage
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -152,6 +152,24 @@ const routes = [
|
|||||||
component: () =>
|
component: () =>
|
||||||
import("@/views/VoteHomePage.vue")
|
import("@/views/VoteHomePage.vue")
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: "/vote/voting/:id",
|
||||||
|
name: "Voting",
|
||||||
|
component: () =>
|
||||||
|
import("@/views/VoteHomePage.vue")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/vote/edit-vote/:id",
|
||||||
|
name: "EditVote",
|
||||||
|
component: () =>
|
||||||
|
import("@/views/VoteHomePage.vue")
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/vote/vote-results/:id",
|
||||||
|
name: "VoteResults",
|
||||||
|
component: () =>
|
||||||
|
import("@/views/VoteHomePage.vue")
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: '/secret',
|
path: '/secret',
|
||||||
name: 'Secret Page',
|
name: 'Secret Page',
|
||||||
|
|||||||
@@ -77,11 +77,6 @@ async error => {
|
|||||||
return axiosApiInstance(originalRequest);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,12 +2,11 @@
|
|||||||
<v-container>
|
<v-container>
|
||||||
<v-toolbar color="transparent">
|
<v-toolbar color="transparent">
|
||||||
<v-toolbar-title>Голосования</v-toolbar-title>
|
<v-toolbar-title>Голосования</v-toolbar-title>
|
||||||
|
|
||||||
<template v-slot:extension>
|
<template v-slot:extension>
|
||||||
<v-tabs v-model="currentTab">
|
<v-tabs v-model="currentTab">
|
||||||
<v-tab :key="0" value="current">Текущие голосования</v-tab>
|
<v-tab value="current">Текущие голосования</v-tab>
|
||||||
<v-tab :key="1" value="completed">Завершенные голосования</v-tab>
|
<v-tab value="completed">Завершенные голосования</v-tab>
|
||||||
<v-tab :key="2" value="constructor">Создать новое голосование</v-tab>
|
<v-tab value="constructor">Создать новое голосование</v-tab>
|
||||||
</v-tabs>
|
</v-tabs>
|
||||||
</template>
|
</template>
|
||||||
</v-toolbar>
|
</v-toolbar>
|
||||||
@@ -17,9 +16,19 @@
|
|||||||
<v-tabs-window-item value="current">
|
<v-tabs-window-item value="current">
|
||||||
<v-container>
|
<v-container>
|
||||||
<v-row>
|
<v-row>
|
||||||
<v-col v-for="voting in sortedCurrentVotes" :key="voting.id" cols="12" lg="3" md="4">
|
<v-col
|
||||||
<VoteCardVue :voteCard="voting" @openVoteModal="openVoteModal" @openEditVoteModal="openEditVoteModal"
|
v-for="voting in sortedCurrentVotes"
|
||||||
@deleteVoting="deleteVoting" />
|
:key="voting.id"
|
||||||
|
cols="12"
|
||||||
|
lg="3"
|
||||||
|
md="4"
|
||||||
|
>
|
||||||
|
<VoteCardVue
|
||||||
|
:voteCard="voting"
|
||||||
|
@openVoteModal="(voting) => openModal('vote', voting)"
|
||||||
|
@openEditVoteModal="(voting) => openModal('edit', voting)"
|
||||||
|
@deleteVoting="deleteVoting"
|
||||||
|
/>
|
||||||
</v-col>
|
</v-col>
|
||||||
</v-row>
|
</v-row>
|
||||||
</v-container>
|
</v-container>
|
||||||
@@ -29,14 +38,21 @@
|
|||||||
<v-tabs-window-item value="completed">
|
<v-tabs-window-item value="completed">
|
||||||
<v-container>
|
<v-container>
|
||||||
<v-row>
|
<v-row>
|
||||||
<v-col v-for="voting in sortedCompletedVotes" :key="voting.id" cols="12" lg="3" md="4">
|
<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>
|
||||||
<v-card-title>{{ voting.title }}</v-card-title>
|
<v-card-title>{{ voting.title }}</v-card-title>
|
||||||
<v-card-subtitle>
|
<v-card-subtitle>
|
||||||
Завершено: {{ formatDate(voting.endDate) }}
|
Завершено: {{ formatDate(voting.endDate) }}
|
||||||
</v-card-subtitle>
|
</v-card-subtitle>
|
||||||
<v-card-actions class="justify-space-between">
|
<v-card-actions class="justify-space-between">
|
||||||
<v-btn color="teal-darken-4" size="medium" @click="openResultsModal(voting)">
|
<v-btn color="teal-darken-4" size="medium" @click="(voting) => openModal('results', voting)">
|
||||||
Результаты
|
Результаты
|
||||||
</v-btn>
|
</v-btn>
|
||||||
<v-btn color="error" size="medium" @click="deleteVoting(voting.id)">
|
<v-btn color="error" size="medium" @click="deleteVoting(voting.id)">
|
||||||
@@ -55,12 +71,11 @@
|
|||||||
</v-tabs-window-item>
|
</v-tabs-window-item>
|
||||||
</v-tabs-window>
|
</v-tabs-window>
|
||||||
|
|
||||||
<!-- Модальное окно для голосования -->
|
<!-- Модальные окна -->
|
||||||
<v-dialog v-model="voteModal" max-width="1200px">
|
<v-dialog v-model="voteModal" max-width="1200px" @click:outside="closeModal">
|
||||||
<v-card>
|
<v-card>
|
||||||
<v-card-actions>
|
<v-card-actions>
|
||||||
<!--<v-btn color="teal-darken-4" @click="submitVote">Проголосовать</v-btn>-->
|
<v-btn color="red-darken-1" size="medium" @click="closeModal">
|
||||||
<v-btn color="red-darken-1" size="medium" @click="closeVoteModal">
|
|
||||||
<v-icon>mdi-close-thick</v-icon>
|
<v-icon>mdi-close-thick</v-icon>
|
||||||
</v-btn>
|
</v-btn>
|
||||||
</v-card-actions>
|
</v-card-actions>
|
||||||
@@ -71,30 +86,27 @@
|
|||||||
</v-card>
|
</v-card>
|
||||||
</v-dialog>
|
</v-dialog>
|
||||||
|
|
||||||
<!-- Модальное окно для редактирования -->
|
<v-dialog v-model="editVoteModal" max-width="1200px" @click:outside="closeModal">
|
||||||
<v-dialog v-model="editVoteModal" max-width="1200px">
|
|
||||||
<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> -->
|
|
||||||
<VoteConstructor />
|
<VoteConstructor />
|
||||||
</v-card-text>
|
</v-card-text>
|
||||||
<v-card-actions>
|
<v-card-actions>
|
||||||
<v-btn color="teal-darken-4">Сохранить</v-btn>
|
<v-btn color="teal-darken-4">Сохранить</v-btn>
|
||||||
<v-btn @click="closeEditVoteModal">Закрыть</v-btn>
|
<v-btn @click="closeModal">Закрыть</v-btn>
|
||||||
</v-card-actions>
|
</v-card-actions>
|
||||||
</v-card>
|
</v-card>
|
||||||
</v-dialog>
|
</v-dialog>
|
||||||
|
|
||||||
<!-- Модальное окно для результатов -->
|
<v-dialog v-model="resultsModal" max-width="1200px" @click:outside="closeModal">
|
||||||
<v-dialog v-model="resultsModal" max-width="1200px">
|
|
||||||
<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>
|
<p>Здесь отображаются результаты голосования...</p>
|
||||||
</v-card-text>
|
</v-card-text>
|
||||||
<v-card-actions>
|
<v-card-actions>
|
||||||
<v-btn @click="closeResultsModal">Закрыть</v-btn>
|
<v-btn @click="closeModal">Закрыть</v-btn>
|
||||||
</v-card-actions>
|
</v-card-actions>
|
||||||
</v-card>
|
</v-card>
|
||||||
</v-dialog>
|
</v-dialog>
|
||||||
@@ -102,25 +114,33 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { computed, ref } from "vue";
|
import { ref, computed, watch } from "vue";
|
||||||
import VoteConstructor from "@/components/vote/VoteConstructor.vue";
|
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 { getVotes } from "@/utils/axios-api"
|
import { useRoute, useRouter } from "vue-router";
|
||||||
import { votingData } from "@/test/testDataForVote"
|
import { getVotes } from "@/utils/axios-api";
|
||||||
|
import {votingData} from "@/test/testDataForVote";
|
||||||
|
import {formatDate} from "@vueuse/shared";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
methods: {formatDate},
|
||||||
|
computed: {
|
||||||
|
votingData() {
|
||||||
|
return votingData
|
||||||
|
}
|
||||||
|
},
|
||||||
components: { CurrentVote, VoteConstructor, VoteCardVue },
|
components: { CurrentVote, VoteConstructor, VoteCardVue },
|
||||||
setup() {
|
setup() {
|
||||||
const currentTab = ref("current");
|
const currentTab = ref("current");
|
||||||
const votes = ref([])
|
const votes = ref([]);
|
||||||
|
const router = useRouter();
|
||||||
|
const route = useRoute();
|
||||||
|
|
||||||
function updating(param) {
|
const updating = async (param) => {
|
||||||
getVotes(param)
|
const data = await getVotes(param);
|
||||||
.then(data => {
|
votes.value = data;
|
||||||
votes.value = data;
|
};
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
updating('active')
|
updating('active')
|
||||||
|
|
||||||
@@ -129,85 +149,73 @@ export default {
|
|||||||
const resultsModal = ref(false);
|
const resultsModal = ref(false);
|
||||||
const selectedVoting = ref(null);
|
const selectedVoting = ref(null);
|
||||||
|
|
||||||
const sortedCurrentVotes = computed(() => {
|
const sortedCurrentVotes = computed(() =>
|
||||||
return votes.value
|
votes.value
|
||||||
.filter((v) => new Date(v.dateend) > new Date())
|
.filter((v) => new Date(v.dateend) > new Date())
|
||||||
.sort((a, b) => new Date(a.dateend) - new Date(b.dateend));
|
.sort((a, b) => new Date(a.dateend) - new Date(b.dateend))
|
||||||
});
|
);
|
||||||
|
|
||||||
const sortedCompletedVotes = computed(() => {
|
const sortedCompletedVotes = computed(() =>
|
||||||
return votes.value
|
votes.value
|
||||||
.filter((v) => new Date(v.dateend) <= new Date())
|
.filter((v) => new Date(v.dateend) <= new Date())
|
||||||
.sort((a, b) => new Date(b.dateend) - new Date(a.dateend));
|
.sort((a, b) => new Date(b.dateend) - new Date(a.dateend))
|
||||||
});
|
);
|
||||||
|
|
||||||
const timeRemaining = (dateend) => {
|
const closeModal = () => {
|
||||||
const now = new Date();
|
|
||||||
const diff = new Date(dateend) - 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;
|
voteModal.value = false;
|
||||||
selectedVoting.value = null;
|
|
||||||
};
|
|
||||||
|
|
||||||
const openEditVoteModal = (voting) => {
|
|
||||||
selectedVoting.value = voting;
|
|
||||||
editVoteModal.value = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
const closeEditVoteModal = () => {
|
|
||||||
editVoteModal.value = false;
|
editVoteModal.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;
|
resultsModal.value = false;
|
||||||
selectedVoting.value = null;
|
selectedVoting.value = null;
|
||||||
|
router.push({ name: "VoteHomePage" });
|
||||||
|
};
|
||||||
|
|
||||||
|
const openModal = (type, voting) => {
|
||||||
|
selectedVoting.value = voting;
|
||||||
|
if (type === "vote") {
|
||||||
|
voteModal.value = true;
|
||||||
|
router.push({ name: "Voting", params: { id: voting.id } });
|
||||||
|
} else if (type === "edit") {
|
||||||
|
editVoteModal.value = true;
|
||||||
|
router.push({ name: "EditVote", params: { id: voting.id } });
|
||||||
|
} else if (type === "results") {
|
||||||
|
resultsModal.value = true;
|
||||||
|
router.push({ name: "VoteResults", params: { id: voting.id } });
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteVoting = (id) => {
|
const deleteVoting = (id) => {
|
||||||
votes.value = votes.value.filter((v) => v.id !== id);
|
votes.value = votes.value.filter((v) => v.id !== id);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => route,
|
||||||
|
() => {
|
||||||
|
if (!voteModal.value && !editVoteModal.value && !resultsModal.value) {
|
||||||
|
const voting = votes.value.find((v) => v.id === route.params.id);
|
||||||
|
if (route.name === "Voting") voteModal.value = true;
|
||||||
|
if (route.name === "EditVote") editVoteModal.value = true;
|
||||||
|
if (route.name === "VoteResults") resultsModal.value = true;
|
||||||
|
selectedVoting.value = voting || null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ immediate: true }
|
||||||
|
);
|
||||||
|
|
||||||
|
updating("active");
|
||||||
|
|
||||||
return {
|
return {
|
||||||
currentTab,
|
currentTab,
|
||||||
votes,
|
votes,
|
||||||
sortedCurrentVotes,
|
sortedCurrentVotes,
|
||||||
sortedCompletedVotes,
|
sortedCompletedVotes,
|
||||||
voteModal,
|
voteModal,
|
||||||
|
editVoteModal,
|
||||||
resultsModal,
|
resultsModal,
|
||||||
selectedVoting,
|
selectedVoting,
|
||||||
timeRemaining,
|
openModal,
|
||||||
formatDate,
|
closeModal,
|
||||||
openVoteModal,
|
|
||||||
closeVoteModal,
|
|
||||||
submitVote,
|
|
||||||
openResultsModal,
|
|
||||||
closeResultsModal,
|
|
||||||
deleteVoting,
|
deleteVoting,
|
||||||
editVoteModal,
|
updating,
|
||||||
openEditVoteModal,
|
|
||||||
closeEditVoteModal,
|
|
||||||
updating
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user