P-92 добавление роутов в модалки + валидация формы конструктора

This commit is contained in:
Denzel committed 2025-01-14 15:07:30 +03:00
1 parent 99dc314a1f
commit 135c5fb87d
5 files changed
+143 -96

No files matched your search

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