fix [P-293]: создание календаря при создании события
This commit is contained in:
1 parent
6cb204b3ac
commit
ceb398c070
5 files changed
+876
-655
No files matched your search
@@ -4,46 +4,237 @@
|
||||
<mini-calendar />
|
||||
</v-col>
|
||||
<v-col class="d-flex flex-column">
|
||||
<custom-calendar :key="calendarKey" />
|
||||
<custom-calendar
|
||||
:key="calendarKey"
|
||||
@openEventDialog="openEventDialog"
|
||||
@openEventView="openEventView"
|
||||
/>
|
||||
</v-col>
|
||||
|
||||
<v-dialog v-model="showEventDialog" max-width="700">
|
||||
<event-create
|
||||
@closeDialog="closeEventDialog"
|
||||
:eventCalendar="eventFromCalendar"
|
||||
:allCalendars="allCalendars"
|
||||
@getCalendar="getCalendar"
|
||||
@update:eventCalendar="eventFromCalendar = $event"
|
||||
ref="createEvents"
|
||||
:key="eventKey"
|
||||
/>
|
||||
</v-dialog>
|
||||
|
||||
<event-calendar-show
|
||||
v-model:show="showViewDialog"
|
||||
:all-calendars="allCalendars"
|
||||
:event-data="selectedEventForView"
|
||||
@close="handleViewDialogClose"
|
||||
:employees="calendarStore.employees"
|
||||
/>
|
||||
</v-row>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { ref, onMounted, watch } from 'vue';
|
||||
import { ref, onMounted, watch, computed, provide } from 'vue';
|
||||
import { useWeekendsStore } from '@/store/WeekendsStore';
|
||||
import EventCreate from '@/components/calendar_of_events/event-create.vue';
|
||||
import CustomCalendar from '@/components/calendar_of_events/UI_calendar/CustomCalendar.vue';
|
||||
import MiniCalendar from '@/components/calendar_of_events/UI_calendar/MiniCalendar.vue';
|
||||
import { useCalendarStore } from '@/store/calendarStore';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import MiniCalendar from '@/components/calendar_of_events/UI_calendar/MiniCalendar.vue';
|
||||
import { axiosApiInstance } from '@/utils/axios-api';
|
||||
import { useAccountStore } from '@/store/AccountStore';
|
||||
import { useRoute } from 'vue-router';
|
||||
import EventCalendarShow from '@/components/calendar_of_events/event-calendar-show.vue';
|
||||
|
||||
export default {
|
||||
components: { MiniCalendar, CustomCalendar },
|
||||
components: { EventCreate, MiniCalendar, CustomCalendar, EventCalendarShow },
|
||||
setup() {
|
||||
const week = useWeekendsStore();
|
||||
const selectdate = ref(new Date());
|
||||
const MyYear = ref(selectdate.value.getFullYear());
|
||||
const MyMonth = ref(selectdate.value.getMonth() + 1);
|
||||
const calendarForMy = ref([]);
|
||||
const eventFromCalendar = ref({});
|
||||
const eventKey = ref(0);
|
||||
const calendarKey = ref(0);
|
||||
const miniCalendarRef = ref(null);
|
||||
|
||||
const calendarStore = useCalendarStore();
|
||||
const accountStore = useAccountStore();
|
||||
const calendarKey = ref(0);
|
||||
const route = useRoute();
|
||||
const showViewDialog = ref(false);
|
||||
const selectedEventForView = ref({});
|
||||
|
||||
onMounted(() => {
|
||||
const currentYear = new Date().getFullYear();
|
||||
calendarStore.fetchHolidays(currentYear);
|
||||
const { selectedDate, showEventDialog } = storeToRefs(calendarStore); // синхронизируем с date-picker
|
||||
|
||||
const getMonth = (month) => {
|
||||
MyMonth.value = month + 1;
|
||||
};
|
||||
const getYear = (year) => {
|
||||
MyYear.value = year;
|
||||
};
|
||||
|
||||
const getCalendar = () => {
|
||||
calendarStore.loadCalendars();
|
||||
};
|
||||
|
||||
const getDictEmployee = () => {
|
||||
calendarStore.loadDictEmployees();
|
||||
};
|
||||
|
||||
const getEmployees = () => {
|
||||
calendarStore.loadEmployees();
|
||||
if (route.query.date) {
|
||||
calendarStore.setSelectedDate(route.query.date);
|
||||
};
|
||||
|
||||
const allCalendars = computed(() => [
|
||||
...calendarStore.myCalendars,
|
||||
...calendarStore.subscribedCalendars,
|
||||
]);
|
||||
|
||||
const getEvent = (idEvent) => {
|
||||
if (!idEvent) {
|
||||
eventFromCalendar.value = createEmptyEvent();
|
||||
return;
|
||||
} else {
|
||||
axiosApiInstance.get(`api/calendar_of_events/my_events/?id=${idEvent}`).then((res) => {
|
||||
eventFromCalendar.value = res.data;
|
||||
calendarStore.openEventDialog();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const createEmptyEvent = () => ({
|
||||
event: {
|
||||
name: '',
|
||||
participant: [accountStore.user.is_idEmployee],
|
||||
files: [],
|
||||
date_start: new Date().toISOString(),
|
||||
date_end: new Date().toISOString(),
|
||||
period: null,
|
||||
description: '',
|
||||
calendar: null,
|
||||
},
|
||||
});
|
||||
|
||||
const openEventDialog = (selectedEvent) => {
|
||||
// Всегда сбрасываем данные перед открытием нового диалога
|
||||
if (!selectedEvent) {
|
||||
eventFromCalendar.value = createEmptyEvent();
|
||||
eventKey.value++;
|
||||
}
|
||||
|
||||
getEvent(selectedEvent?.event?.id);
|
||||
calendarStore.openEventDialog();
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
getEvent();
|
||||
week.getWeekend(MyYear.value);
|
||||
getDictEmployee();
|
||||
getCalendar();
|
||||
getEmployees();
|
||||
});
|
||||
|
||||
const closeEventDialog = () => {
|
||||
calendarStore.closeEventDialog();
|
||||
|
||||
// При ручном закрытии сбрасываем данные сразу
|
||||
setTimeout(() => {
|
||||
eventFromCalendar.value = createEmptyEvent();
|
||||
eventKey.value++;
|
||||
}, 200);
|
||||
};
|
||||
|
||||
const CheckingStore = () => {
|
||||
if (MyYear.value in week.week) {
|
||||
weekendsData();
|
||||
} else {
|
||||
week.getWeekend(MyYear.value);
|
||||
}
|
||||
};
|
||||
|
||||
const openCalendarCreate = () => {
|
||||
miniCalendarRef.value?.openCalendarCreate();
|
||||
};
|
||||
|
||||
provide('openCalendarCreate', openCalendarCreate);
|
||||
|
||||
watch(
|
||||
() => accountStore.user?.id,
|
||||
(newId, oldId) => {
|
||||
if (newId !== oldId) calendarKey.value += 1;
|
||||
() => calendarStore.showEventDialog,
|
||||
(newValue, oldValue) => {
|
||||
if (!newValue && oldValue) {
|
||||
// Диалог был открыт и закрыт не через нашу кнопку
|
||||
// Добавляем проверку чтобы не сбрасывать при инициализации
|
||||
if (eventFromCalendar.value.event?.id) {
|
||||
setTimeout(() => {
|
||||
eventFromCalendar.value = createEmptyEvent();
|
||||
eventKey.value++;
|
||||
}, 200);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
return { calendarKey };
|
||||
watch(
|
||||
() => accountStore.user?.id,
|
||||
(newUserId, oldUserId) => {
|
||||
if (newUserId !== oldUserId) {
|
||||
console.log('User changed, forcing calendar recreation...');
|
||||
calendarKey.value += 1; // Изменяем key для пересоздания компонента
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
const getEventForView = (idEvent) => {
|
||||
if (!idEvent) {
|
||||
selectedEventForView.value = {};
|
||||
return;
|
||||
}
|
||||
|
||||
axiosApiInstance.get(`api/calendar_of_events/my_events/?id=${idEvent}`).then((res) => {
|
||||
selectedEventForView.value = res.data;
|
||||
showViewDialog.value = true;
|
||||
});
|
||||
};
|
||||
|
||||
const openEventView = (eventId) => {
|
||||
if (eventId) {
|
||||
getEventForView(eventId);
|
||||
} else {
|
||||
console.log('❌ No event ID provided');
|
||||
}
|
||||
};
|
||||
|
||||
// Закрытие модалки
|
||||
const handleViewDialogClose = () => {
|
||||
showViewDialog.value = false;
|
||||
};
|
||||
|
||||
return {
|
||||
selectedDate,
|
||||
getMonth,
|
||||
getYear,
|
||||
week,
|
||||
CheckingStore,
|
||||
showEventDialog,
|
||||
calendarForMy,
|
||||
getCalendar,
|
||||
getEvent,
|
||||
eventFromCalendar,
|
||||
calendarStore,
|
||||
accountStore,
|
||||
closeEventDialog,
|
||||
openEventDialog,
|
||||
createEmptyEvent,
|
||||
eventKey,
|
||||
getDictEmployee,
|
||||
openEventView,
|
||||
handleViewDialogClose,
|
||||
showViewDialog,
|
||||
selectedEventForView,
|
||||
allCalendars,
|
||||
eventKey,
|
||||
calendarKey,
|
||||
openCalendarCreate,
|
||||
};
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<v-card class="h-100 rounded-0 d-flex flex-column">
|
||||
<v-card class="h-100 rounded-0 d-flex flex-colmn">
|
||||
<v-row no-gutters class="flex-column">
|
||||
<v-col class="flex-grow-0 px-2 pt-1">
|
||||
<SearchEvents />
|
||||
@@ -56,7 +56,7 @@ import { useCalendarStore } from '@/store/calendarStore';
|
||||
import { useAccountStore } from '@/store/AccountStore';
|
||||
import CalendarMy from '@/components/calendar_of_events/calendar-my.vue';
|
||||
import SearchEvents from '@/components/calendar_of_events/UI_calendar/SearchEvents.vue';
|
||||
import { onMounted, watch, nextTick, ref, onBeforeUnmount } from 'vue';
|
||||
import { onMounted, watch, nextTick, ref } from 'vue';
|
||||
import { storeToRefs } from 'pinia';
|
||||
|
||||
export default {
|
||||
@@ -67,10 +67,14 @@ export default {
|
||||
const accountStore = useAccountStore();
|
||||
|
||||
const { selectedDate, myCalendars, subscribedCalendars } = storeToRefs(calendarStore);
|
||||
|
||||
// const selectedDate = computed(() => calendarStore.selectedDate);
|
||||
// const myCalendars = computed(() => calendarStore.myCalendars);
|
||||
// const subscribedCalendars = computed(() => calendarStore.subscribedCalendars);
|
||||
|
||||
const { user } = storeToRefs(accountStore);
|
||||
|
||||
const currentDisplay = ref(null);
|
||||
let observer = null;
|
||||
|
||||
const handleDateClick = (date) => {
|
||||
calendarStore.setSelectedDateFromPicker(date);
|
||||
@@ -85,6 +89,12 @@ export default {
|
||||
calendarStore.loadCalendars();
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
loadCalendars();
|
||||
|
||||
updateCalendarDays();
|
||||
});
|
||||
|
||||
// Реакция на изменения пользователя
|
||||
watch(user, (newUser) => {
|
||||
if (newUser) {
|
||||
@@ -182,24 +192,25 @@ export default {
|
||||
{ deep: true },
|
||||
);
|
||||
|
||||
// При смене месяца через кнопки навигации
|
||||
const observer = new MutationObserver((mutations) => {
|
||||
mutations.forEach((mutation) => {
|
||||
if (mutation.type === 'childList') {
|
||||
updateCalendarDays();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
loadCalendars();
|
||||
updateCalendarDays();
|
||||
// Наблюдаем за изменениями в DOM date-picker
|
||||
const datePicker = document.querySelector('.minCal');
|
||||
if (datePicker) {
|
||||
observer = new MutationObserver(() => updateCalendarDays());
|
||||
observer.observe(datePicker, { childList: true, subtree: true });
|
||||
}
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
observer?.disconnect();
|
||||
});
|
||||
|
||||
return {
|
||||
accountStore,
|
||||
calendarStore,
|
||||
user,
|
||||
myCalendars,
|
||||
subscribedCalendars,
|
||||
@@ -214,7 +225,16 @@ export default {
|
||||
};
|
||||
</script>
|
||||
<style scoped>
|
||||
.minCal .v-date-picker-month__day {
|
||||
/* .minCal:deep(.v-date-picker-month__days) {
|
||||
display: grid !important;
|
||||
grid-template-columns: repeat(7, 40px) !important;
|
||||
gap: 3px !important;
|
||||
width: 250px !important;
|
||||
justify-content: center !important;
|
||||
margin: 0 auto !important;
|
||||
} */
|
||||
|
||||
.minCal .v-date-picker-monWth__day {
|
||||
height: 31px;
|
||||
width: 31px;
|
||||
}
|
||||
@@ -235,24 +255,23 @@ export default {
|
||||
/* СТИЛИ ДЛЯ ВЫХОДНЫХ И ПРАЗДНИКОВ */
|
||||
|
||||
.minCal:deep(.weekend-day .v-btn__content) {
|
||||
color: rgb(var(--v-theme-weekend_text)) !important;
|
||||
color: #666 !important;
|
||||
}
|
||||
|
||||
.minCal:deep(.holiday-day .v-btn__content) {
|
||||
color: rgb(var(--v-theme-holiday_text)) !important;
|
||||
font-weight: 600 !important;
|
||||
color: #ff4444 !important;
|
||||
font-weight: bold !important;
|
||||
}
|
||||
|
||||
.minCal:deep(.weekend-day.holiday-day) .v-btn {
|
||||
background-color: rgba(var(--v-theme-holiday_text), 0.12) !important;
|
||||
.minCal:deep(.weekend-day.holiday-day) {
|
||||
background-color: #ffe0e0 !important;
|
||||
}
|
||||
|
||||
.minCal:deep(.weekend-day.holiday-day .v-btn__content) {
|
||||
color: rgb(var(--v-theme-holiday_text)) !important;
|
||||
font-weight: 600 !important;
|
||||
color: #cc0000 !important;
|
||||
}
|
||||
|
||||
.search-dropdown {
|
||||
search-dropdown {
|
||||
max-height: 300px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
@@ -27,10 +27,16 @@
|
||||
<v-col v-for="(x, key) in color" :key="key">
|
||||
<v-avatar
|
||||
class="cursor-pointer"
|
||||
:class="{ 'avatar-dimmed': propsCalendar.cl_color && propsCalendar.cl_color !== x }"
|
||||
@click="colorPik(x, key)"
|
||||
size="x-small"
|
||||
:color="x"
|
||||
:variant="
|
||||
propsCalendar.cl_color === null
|
||||
? 'flat'
|
||||
: propsCalendar.cl_color === x
|
||||
? 'flat'
|
||||
: 'tonal'
|
||||
"
|
||||
/> </v-col
|
||||
></v-row>
|
||||
|
||||
@@ -229,6 +235,23 @@ export default {
|
||||
'#22c55e', // Зеленый
|
||||
];
|
||||
|
||||
// const color = [
|
||||
// '#3b82f6', // Синий
|
||||
// '#10b981', // Зеленый
|
||||
// '#dc2626', // Красный
|
||||
// '#d97706', // Оранжевый
|
||||
// '#7c3aed', // Фиолетовый
|
||||
// '#0ea5e9', // Голубой
|
||||
// '#84cc16', // Лаймовый
|
||||
// '#f59e0b', // Янтарный
|
||||
// '#8b5cf6', // Пурпурный
|
||||
// '#06b6d4', // Бирюзовый
|
||||
// '#f97316', // Теплый оранжевый
|
||||
// '#6366f1', // Фиолетово-синий
|
||||
// '#14b8a6', // Морской волны
|
||||
// '#ec4899', // Розовый
|
||||
// '#64748b', // Серо-синий
|
||||
// ];
|
||||
const colorPik = (col) => {
|
||||
if (propsCalendar.value.cl_color === col) {
|
||||
propsCalendar.value.cl_color = null;
|
||||
@@ -276,13 +299,4 @@ export default {
|
||||
.custom-tooltip {
|
||||
max-width: 350px; /* Установка максимальной ширины для подсказки */
|
||||
}
|
||||
|
||||
.avatar-dimmed {
|
||||
opacity: 0.45;
|
||||
transition: opacity 0.15s ease;
|
||||
}
|
||||
|
||||
.avatar-dimmed:hover {
|
||||
opacity: 0.8;
|
||||
}
|
||||
</style>
|
||||
@@ -8,11 +8,8 @@
|
||||
|
||||
<v-btn
|
||||
v-if="title === 'Мои календари'"
|
||||
size="x-regular"
|
||||
icon="mdi-plus"
|
||||
variant="outlined"
|
||||
color="btn_text"
|
||||
class="pa-1 ml-2 simple-hover"
|
||||
class="simple-hover"
|
||||
@click.stop="editCreatedCalendar()"
|
||||
></v-btn>
|
||||
</v-expansion-panel-title>
|
||||
@@ -76,102 +73,95 @@
|
||||
</v-expansion-panels>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { ref, watch } from 'vue';
|
||||
<script setup>
|
||||
import { onMounted, ref, watch } from 'vue';
|
||||
import calendarCreate from '@/components/calendar_of_events/calendar-create.vue';
|
||||
import { useAccountStore } from '@/store/AccountStore';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { useCalendarStore } from '@/store/calendarStore';
|
||||
|
||||
export default {
|
||||
components: { calendarCreate },
|
||||
const props = defineProps({
|
||||
calendars: Array,
|
||||
title: String,
|
||||
});
|
||||
|
||||
props: {
|
||||
calendars: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
},
|
||||
const emit = defineEmits(['getCalendar']);
|
||||
|
||||
title: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
},
|
||||
const showDialog = ref(false);
|
||||
const accountStore = useAccountStore();
|
||||
const { user } = storeToRefs(accountStore);
|
||||
const calendarStore = useCalendarStore();
|
||||
const { toggleCalendarVisibility, hiddenCalendarIds } = calendarStore;
|
||||
|
||||
setup(props) {
|
||||
const showDialog = ref(false);
|
||||
const accountStore = useAccountStore();
|
||||
const { user } = storeToRefs(accountStore);
|
||||
const calendarStore = useCalendarStore();
|
||||
const { toggleCalendarVisibility, hiddenCalendarIds } = calendarStore;
|
||||
const calendar = ref(null);
|
||||
const openGroup = ref([0]);
|
||||
// const trans = ref(false);
|
||||
const hover = ref(0);
|
||||
|
||||
const calendar = ref(null);
|
||||
const openGroup = ref([0]);
|
||||
const trans = ref(false);
|
||||
const hover = ref(0);
|
||||
|
||||
const editCreatedCalendar = (cal) => {
|
||||
if (cal === undefined) {
|
||||
calendar.value = {
|
||||
cl_name: '',
|
||||
participant: [{ editor: true, participant_calendar: user.value.is_idEmployee }],
|
||||
cl_color: 'red',
|
||||
cl_descr: '',
|
||||
};
|
||||
} else {
|
||||
calendar.value = { ...cal };
|
||||
}
|
||||
showDialog.value = true;
|
||||
const editCreatedCalendar = (cal) => {
|
||||
if (cal === undefined) {
|
||||
calendar.value = {
|
||||
cl_name: '',
|
||||
participant: [{ editor: true, participant_calendar: user.value.is_idEmployee }],
|
||||
cl_color: 'red',
|
||||
cl_descr: '',
|
||||
};
|
||||
|
||||
const handleCloseDialog = () => {
|
||||
showDialog.value = false;
|
||||
};
|
||||
|
||||
const resetCalendar = () => {
|
||||
calendar.value = {};
|
||||
};
|
||||
|
||||
const toggleVisiblityEvents = (cal) => {
|
||||
toggleCalendarVisibility(cal.id);
|
||||
};
|
||||
|
||||
watch(hiddenCalendarIds, (newHiddenIds) => {}, { deep: true });
|
||||
|
||||
watch(
|
||||
() => props.calendars,
|
||||
(newCalendars) => {},
|
||||
{ deep: true },
|
||||
);
|
||||
|
||||
return {
|
||||
accountStore,
|
||||
user,
|
||||
calendar,
|
||||
showDialog,
|
||||
editCreatedCalendar,
|
||||
toggleVisiblityEvents,
|
||||
openGroup,
|
||||
trans,
|
||||
hover,
|
||||
handleCloseDialog,
|
||||
resetCalendar,
|
||||
};
|
||||
},
|
||||
} else {
|
||||
calendar.value = { ...cal };
|
||||
}
|
||||
showDialog.value = true;
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
window.$createCalendar = () => {
|
||||
editCreatedCalendar();
|
||||
};
|
||||
});
|
||||
|
||||
const handleCloseDialog = () => {
|
||||
if (calendar.value.cl_name.length > 1) {
|
||||
const calendarData = JSON.parse(JSON.stringify(calendar.value));
|
||||
window.dispatchEvent(
|
||||
new CustomEvent('calendarCreated', {
|
||||
detail: calendarData,
|
||||
}),
|
||||
);
|
||||
}
|
||||
showDialog.value = false;
|
||||
};
|
||||
|
||||
const resetCalendar = () => {
|
||||
calendar.value = {};
|
||||
};
|
||||
|
||||
const toggleVisiblityEvents = (cal) => {
|
||||
toggleCalendarVisibility(cal.id);
|
||||
};
|
||||
|
||||
watch(hiddenCalendarIds, (newHiddenIds) => {}, { deep: true });
|
||||
|
||||
watch(
|
||||
() => props.calendars,
|
||||
(newCalendars) => {},
|
||||
{ deep: true },
|
||||
);
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.simple-hover {
|
||||
opacity: 0.6;
|
||||
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
min-width: 30px !important;
|
||||
height: 30px !important;
|
||||
width: 22px !important;
|
||||
height: 22px !important;
|
||||
border-radius: 3px !important;
|
||||
margin-left: 0.5rem;
|
||||
background-color: #00897b !important;
|
||||
color: white;
|
||||
margin-bottom: 2px;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.simple-hover:hover {
|
||||
opacity: 1;
|
||||
background-color: rgba(0, 137, 123, 0.1) !important;
|
||||
background-color: #004d40 !important;
|
||||
transform: scale(1.1);
|
||||
}
|
||||
.fade-enter-active,
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user