diff --git a/src/front/src/components/calendar_of_events/UI_calendar/CustomCalendar.vue b/src/front/src/components/calendar_of_events/UI_calendar/CustomCalendar.vue index 6f27b9b22..a93eb8e61 100644 --- a/src/front/src/components/calendar_of_events/UI_calendar/CustomCalendar.vue +++ b/src/front/src/components/calendar_of_events/UI_calendar/CustomCalendar.vue @@ -135,6 +135,20 @@ export default { selectable: true, unselectAuto: false, selectMirror: false, + + dayCellDidMount: (arg) => { + const date = arg.date; + const dayInfo = calendarStore.isNonWorkingDay(date); + console.log(dayInfo); + + if (dayInfo.isHoliday === true) { + arg.el.classList.add('non-working-day'); + } + + if (dayInfo.isWeekendForStyling === true) { + arg.el.classList.add('grey-background'); + } + }, views: { timeGridDay: { type: 'timeGrid', @@ -357,6 +371,15 @@ export default { }); }); + onMounted(async () => { + try { + const currentYear = new Date().getFullYear(); + await calendarStore.fetchHolidays(currentYear); + } catch (error) { + console.error('Failed to load holidays:', error); + } + }); + watch(selectedDate, (newDate) => { if (newDate && calendarApi.value && lastUpdatedBy.value !== 'calendar') { nextTick(() => { @@ -403,6 +426,7 @@ export default { updateCalendarEvents, handleEventClick, calendarColorMap, + calendarStore, }; }, }; @@ -494,6 +518,27 @@ export default { :deep(.fc-popover) { background-color: rgb(248, 244, 244) !important; } + +.non-working-day { + color: red !important; +} + +:global(.fc-daygrid-day.non-working-day .fc-daygrid-day-number) { + color: #d32f2f !important; +} + +:global(.fc-daygrid-day.grey-background.fc-daygrid-day-number) { + background-color: rgb(196, 187, 187) !important; +} + +.grey-background { + background-color: rgb(240, 229, 229) !important; +} + +:deep(.fc-day.grey-background) { + background-color: #f5f5f5 !important; +} + /* :deep(.fc-daygrid-day-frame) { position: relative; min-height: 50px; diff --git a/src/front/src/components/calendar_of_events/UI_calendar/HomeCalendarWidget.vue b/src/front/src/components/calendar_of_events/UI_calendar/HomeCalendarWidget.vue index 4dd009590..76d8d755b 100644 --- a/src/front/src/components/calendar_of_events/UI_calendar/HomeCalendarWidget.vue +++ b/src/front/src/components/calendar_of_events/UI_calendar/HomeCalendarWidget.vue @@ -32,6 +32,8 @@ 'current-month': day.isCurrentMonth, today: isToday(day.date), selected: isSelected(day.date), + 'non-working-day': calendarStore.isNonWorkingDay(day.date).isHoliday, + 'grey-background': calendarStore.isNonWorkingDay(day.date).isWeekendForStyling, }" @click="onDateClick(day.date)" > @@ -55,7 +57,7 @@
-

{{ formattedSelectedDate }}

+

Сегодня, {{ formattedSelectedDate }}

@@ -106,6 +108,7 @@ export default { // Реактивные данные const currentDate = ref(new Date()); const selectedDate = ref(''); // Будет установлено в формате YYYY-MM-DD + const currentYear = new Date().getFullYear(); // Работа с хранилищем const calendarStore = useCalendarStore(); @@ -131,7 +134,7 @@ export default { // Преобразование событий с защитой от ошибок const events = computed(() => { - return allEvents.value.map((event) => { + const userEvents = allEvents.value.map((event) => { return { id: event.id, title: event.name || event.title || 'Без названия', @@ -139,8 +142,11 @@ export default { end: event.date_end || event.end, description: event.description, color: event.color || '#1976d2', + isHoliday: false, }; }); + + return [...userEvents]; }); const russianWeekdays = ['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс']; @@ -262,8 +268,14 @@ export default { currentDate.value = date; }; - onMounted(() => { + const isWeekendOrHoliday = (dateString) => { + const dayInfo = calendarStore.isNonWorkingDay(dateString); + return dayInfo.isHoliday || dayInfo.isWeekendForStyling; + }; + + onMounted(async () => { selectedDate.value = formatToLocalDate(new Date()); + calendarStore.fetchHolidays(currentYear); }); return { @@ -278,6 +290,7 @@ export default { currentMonth, formattedSelectedDate, dayEvents, + isWeekendOrHoliday, // Методы isToday, @@ -370,7 +383,7 @@ export default { } .day-cell.selected { - background-color: #2196f3; + background-color: #00897B; color: white; } @@ -416,7 +429,7 @@ export default { } .day-title { - font-size: 1rem; + font-size: 1.2rem; font-weight: 600; margin: 0; color: #333; @@ -485,4 +498,16 @@ export default { .day-schedule::-webkit-scrollbar-thumb:hover { background: #a8a8a8; } + +.non-working-day { + color: red !important; +} + +.grey-background { + background-color: rgb(243, 243, 243) !important; +} + +.day-cell:not(.current-month).non-working-day { + color: inherit !important; +} diff --git a/src/front/src/components/calendar_of_events/UI_calendar/MiniCalendar.vue b/src/front/src/components/calendar_of_events/UI_calendar/MiniCalendar.vue index 7050f385e..ea7c034a6 100644 --- a/src/front/src/components/calendar_of_events/UI_calendar/MiniCalendar.vue +++ b/src/front/src/components/calendar_of_events/UI_calendar/MiniCalendar.vue @@ -113,7 +113,7 @@ export default { diff --git a/src/front/src/store/calendarStore.js b/src/front/src/store/calendarStore.js index 8d8997a73..2c7cd8bc8 100644 --- a/src/front/src/store/calendarStore.js +++ b/src/front/src/store/calendarStore.js @@ -14,6 +14,7 @@ export const useCalendarStore = defineStore('calendarStore', () => { const currentView = ref('dayGridMonth'); // Текущий вид календаря const calendars = ref([]); // Список календарей пользователя const lastUpdatedBy = ref(null); + const holidays = ref([]); // Массив ID скрытых календарей. Загружаем из localStorage при инициализации. const hiddenCalendarIds = ref(JSON.parse(localStorage.getItem('hiddenCalendars')) || []); @@ -151,6 +152,93 @@ export const useCalendarStore = defineStore('calendarStore', () => { return editableEvents.value.some((e) => e.id === id); }; + const fetchHolidays = async (year) => { + try { + const response = await axiosApiInstance.get( + `api/calendar_of_events/exclusion_dates/?year=${year}`, + ); + holidays.value = response.data; + return holidays.value; + } catch (err) { + console.error('Ошибка загрузки праздников:', err); + throw err; + } + }; + + // Метод для проверки, является ли день выходным или праздничным + const isNonWorkingDay = (dateInput) => { + let date; + + // Если входные данные — это строка в формате 'YYYY-MM-DD' + if (typeof dateInput === 'string') { + date = new Date(dateInput); + } + // Если входные данные — это объект Date + else if (dateInput instanceof Date) { + date = new Date(dateInput); + } + // Если входные данные некорректны + else { + console.error('Invalid date input:', dateInput); + return false; + } + + // Проверяем, что дата корректна + if (isNaN(date.getTime())) { + console.error('Invalid date:', dateInput); + return false; + } + + console.log('Processing date:', date); + + const day = date.getDay(); + + // Проверка на выходной (суббота или воскресенье) + const isWeekend = day === 0 || day === 6; + + // Получаем год, месяц и день + const year = date.getFullYear(); + const month = date.getMonth() + 1; // Месяцы в JS начинаются с 0 + const dayOfMonth = date.getDate(); + + const normalizedCurrentDate = `${year}-${String(month).padStart(2, '0')}-${String(dayOfMonth).padStart(2, '0')}`; + console.log('Current date:', normalizedCurrentDate); + // Логируем данные о праздничных днях + console.log(`Holidays for ${year}:`, holidays.value[year]); + console.log(`Holidays for ${year}-${month}:`, holidays.value[year]?.[month]); + // Проверяем, что данные о праздничных днях существуют для текущего года и месяца + const holidaysForYear = holidays.value[year] || {}; + const holidaysForMonth = holidaysForYear[month] || []; + + // Проверка на исключение (рабочая суббота или праздничный будний день) + const isExceptionDay = holidaysForMonth.includes(normalizedCurrentDate); + + console.log('Is weekend:', isWeekend); + console.log('Is exception day:', isExceptionDay); + + + return { + isNonWorking: (isWeekend && !isExceptionDay) || (!isWeekend && isExceptionDay), + isWeekendForStyling: isWeekend && !isExceptionDay, // только для серого фона + isHoliday: !isWeekend && isExceptionDay, // только праздничный будний + }; + // // Если день — суббота или воскресенье, но он в исключениях (рабочий), то не выходной + // if (isWeekend && isExceptionDay) { + // console.log('Working weekend day!'); + // return false; + // } + + // // Если день — будний, но он в исключениях (праздник), то выходной + // if (!isWeekend && isExceptionDay) { + // console.log('Holiday weekday!'); + // return true; + // } + + // // Во всех остальных случаях — стандартная логика + // console.log('Standard weekend logic.'); + // return isWeekend; + }; + // Открыть диалог создания/редактирования const openEventDialog = (event = null) => { selectedEvent.value = event; @@ -173,6 +261,7 @@ export const useCalendarStore = defineStore('calendarStore', () => { calendars, lastUpdatedBy, hiddenCalendarIds, + holidays, // Getters formattedSelectedDate, @@ -189,11 +278,12 @@ export const useCalendarStore = defineStore('calendarStore', () => { setSelectedDate, setCurrentView, loadCalendars, - // loadEvents, openEventDialog, closeEventDialog, setSelectedDateFromCalendar, setSelectedDateFromPicker, toggleCalendarVisibility, + fetchHolidays, + isNonWorkingDay, }; });