fix [P-51]: добавлено визуальное отображение праздничных дней
This commit is contained in:
1 parent
ce275623a5
commit
f881e69415
4 files changed
+168
-7
No files matched your search
@@ -135,6 +135,20 @@ export default {
|
|||||||
selectable: true,
|
selectable: true,
|
||||||
unselectAuto: false,
|
unselectAuto: false,
|
||||||
selectMirror: 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: {
|
views: {
|
||||||
timeGridDay: {
|
timeGridDay: {
|
||||||
type: 'timeGrid',
|
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) => {
|
watch(selectedDate, (newDate) => {
|
||||||
if (newDate && calendarApi.value && lastUpdatedBy.value !== 'calendar') {
|
if (newDate && calendarApi.value && lastUpdatedBy.value !== 'calendar') {
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
@@ -403,6 +426,7 @@ export default {
|
|||||||
updateCalendarEvents,
|
updateCalendarEvents,
|
||||||
handleEventClick,
|
handleEventClick,
|
||||||
calendarColorMap,
|
calendarColorMap,
|
||||||
|
calendarStore,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -494,6 +518,27 @@ export default {
|
|||||||
:deep(.fc-popover) {
|
:deep(.fc-popover) {
|
||||||
background-color: rgb(248, 244, 244) !important;
|
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) {
|
/* :deep(.fc-daygrid-day-frame) {
|
||||||
position: relative;
|
position: relative;
|
||||||
min-height: 50px;
|
min-height: 50px;
|
||||||
|
|||||||
@@ -32,6 +32,8 @@
|
|||||||
'current-month': day.isCurrentMonth,
|
'current-month': day.isCurrentMonth,
|
||||||
today: isToday(day.date),
|
today: isToday(day.date),
|
||||||
selected: isSelected(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)"
|
@click="onDateClick(day.date)"
|
||||||
>
|
>
|
||||||
@@ -55,7 +57,7 @@
|
|||||||
<!-- Дневное расписание -->
|
<!-- Дневное расписание -->
|
||||||
<v-col cols="5" class="pl-2">
|
<v-col cols="5" class="pl-2">
|
||||||
<div class="schedule-header">
|
<div class="schedule-header">
|
||||||
<h3 class="day-title">{{ formattedSelectedDate }}</h3>
|
<h3 class="day-title">Сегодня, {{ formattedSelectedDate }}</h3>
|
||||||
<!-- <v-chip size="small" color="primary" variant="outlined" v-if="isToday(selectedDate)">
|
<!-- <v-chip size="small" color="primary" variant="outlined" v-if="isToday(selectedDate)">
|
||||||
Сегодня
|
Сегодня
|
||||||
</v-chip> -->
|
</v-chip> -->
|
||||||
@@ -106,6 +108,7 @@ export default {
|
|||||||
// Реактивные данные
|
// Реактивные данные
|
||||||
const currentDate = ref(new Date());
|
const currentDate = ref(new Date());
|
||||||
const selectedDate = ref(''); // Будет установлено в формате YYYY-MM-DD
|
const selectedDate = ref(''); // Будет установлено в формате YYYY-MM-DD
|
||||||
|
const currentYear = new Date().getFullYear();
|
||||||
|
|
||||||
// Работа с хранилищем
|
// Работа с хранилищем
|
||||||
const calendarStore = useCalendarStore();
|
const calendarStore = useCalendarStore();
|
||||||
@@ -131,7 +134,7 @@ export default {
|
|||||||
|
|
||||||
// Преобразование событий с защитой от ошибок
|
// Преобразование событий с защитой от ошибок
|
||||||
const events = computed(() => {
|
const events = computed(() => {
|
||||||
return allEvents.value.map((event) => {
|
const userEvents = allEvents.value.map((event) => {
|
||||||
return {
|
return {
|
||||||
id: event.id,
|
id: event.id,
|
||||||
title: event.name || event.title || 'Без названия',
|
title: event.name || event.title || 'Без названия',
|
||||||
@@ -139,8 +142,11 @@ export default {
|
|||||||
end: event.date_end || event.end,
|
end: event.date_end || event.end,
|
||||||
description: event.description,
|
description: event.description,
|
||||||
color: event.color || '#1976d2',
|
color: event.color || '#1976d2',
|
||||||
|
isHoliday: false,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return [...userEvents];
|
||||||
});
|
});
|
||||||
|
|
||||||
const russianWeekdays = ['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс'];
|
const russianWeekdays = ['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс'];
|
||||||
@@ -262,8 +268,14 @@ export default {
|
|||||||
currentDate.value = date;
|
currentDate.value = date;
|
||||||
};
|
};
|
||||||
|
|
||||||
onMounted(() => {
|
const isWeekendOrHoliday = (dateString) => {
|
||||||
|
const dayInfo = calendarStore.isNonWorkingDay(dateString);
|
||||||
|
return dayInfo.isHoliday || dayInfo.isWeekendForStyling;
|
||||||
|
};
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
selectedDate.value = formatToLocalDate(new Date());
|
selectedDate.value = formatToLocalDate(new Date());
|
||||||
|
calendarStore.fetchHolidays(currentYear);
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -278,6 +290,7 @@ export default {
|
|||||||
currentMonth,
|
currentMonth,
|
||||||
formattedSelectedDate,
|
formattedSelectedDate,
|
||||||
dayEvents,
|
dayEvents,
|
||||||
|
isWeekendOrHoliday,
|
||||||
|
|
||||||
// Методы
|
// Методы
|
||||||
isToday,
|
isToday,
|
||||||
@@ -370,7 +383,7 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.day-cell.selected {
|
.day-cell.selected {
|
||||||
background-color: #2196f3;
|
background-color: #00897B;
|
||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -416,7 +429,7 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.day-title {
|
.day-title {
|
||||||
font-size: 1rem;
|
font-size: 1.2rem;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
color: #333;
|
color: #333;
|
||||||
@@ -485,4 +498,16 @@ export default {
|
|||||||
.day-schedule::-webkit-scrollbar-thumb:hover {
|
.day-schedule::-webkit-scrollbar-thumb:hover {
|
||||||
background: #a8a8a8;
|
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;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
@@ -113,7 +113,7 @@ export default {
|
|||||||
<style scoped>
|
<style scoped>
|
||||||
/* .minCal:deep(.v-date-picker-month__days) {
|
/* .minCal:deep(.v-date-picker-month__days) {
|
||||||
display: grid !important;
|
display: grid !important;
|
||||||
grid-template-columns: repeat(7, 32px) !important;
|
grid-template-columns: repeat(7, 36px) !important;
|
||||||
gap: 3px !important;
|
gap: 3px !important;
|
||||||
width: 250px !important;
|
width: 250px !important;
|
||||||
justify-content: center !important;
|
justify-content: center !important;
|
||||||
@@ -137,4 +137,5 @@ export default {
|
|||||||
.minCal:deep(.v-date-picker-years__content) {
|
.minCal:deep(.v-date-picker-years__content) {
|
||||||
gap: 0;
|
gap: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
@@ -14,6 +14,7 @@ export const useCalendarStore = defineStore('calendarStore', () => {
|
|||||||
const currentView = ref('dayGridMonth'); // Текущий вид календаря
|
const currentView = ref('dayGridMonth'); // Текущий вид календаря
|
||||||
const calendars = ref([]); // Список календарей пользователя
|
const calendars = ref([]); // Список календарей пользователя
|
||||||
const lastUpdatedBy = ref(null);
|
const lastUpdatedBy = ref(null);
|
||||||
|
const holidays = ref([]);
|
||||||
|
|
||||||
// Массив ID скрытых календарей. Загружаем из localStorage при инициализации.
|
// Массив ID скрытых календарей. Загружаем из localStorage при инициализации.
|
||||||
const hiddenCalendarIds = ref(JSON.parse(localStorage.getItem('hiddenCalendars')) || []);
|
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);
|
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) => {
|
const openEventDialog = (event = null) => {
|
||||||
selectedEvent.value = event;
|
selectedEvent.value = event;
|
||||||
@@ -173,6 +261,7 @@ export const useCalendarStore = defineStore('calendarStore', () => {
|
|||||||
calendars,
|
calendars,
|
||||||
lastUpdatedBy,
|
lastUpdatedBy,
|
||||||
hiddenCalendarIds,
|
hiddenCalendarIds,
|
||||||
|
holidays,
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
formattedSelectedDate,
|
formattedSelectedDate,
|
||||||
@@ -189,11 +278,12 @@ export const useCalendarStore = defineStore('calendarStore', () => {
|
|||||||
setSelectedDate,
|
setSelectedDate,
|
||||||
setCurrentView,
|
setCurrentView,
|
||||||
loadCalendars,
|
loadCalendars,
|
||||||
// loadEvents,
|
|
||||||
openEventDialog,
|
openEventDialog,
|
||||||
closeEventDialog,
|
closeEventDialog,
|
||||||
setSelectedDateFromCalendar,
|
setSelectedDateFromCalendar,
|
||||||
setSelectedDateFromPicker,
|
setSelectedDateFromPicker,
|
||||||
toggleCalendarVisibility,
|
toggleCalendarVisibility,
|
||||||
|
fetchHolidays,
|
||||||
|
isNonWorkingDay,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user