style [P-302]: корректная подсветка выходных и праздников в светлой и тёмной темах
This commit is contained in:
1 parent
cd570a6c4b
commit
751538189d
6 files changed
+485
-480
No files matched your search
@@ -35,7 +35,6 @@
|
||||
|
||||
<script>
|
||||
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 { useCalendarStore } from '@/store/calendarStore';
|
||||
@@ -48,7 +47,6 @@ import EventCalendarShow from '@/components/calendar_of_events/event-calendar-sh
|
||||
export default {
|
||||
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);
|
||||
@@ -127,7 +125,7 @@ export default {
|
||||
|
||||
onMounted(() => {
|
||||
getEvent();
|
||||
week.getWeekend(MyYear.value);
|
||||
calendarStore.fetchHolidays(MyYear.value);
|
||||
getDictEmployee();
|
||||
getCalendar();
|
||||
getEmployees();
|
||||
@@ -143,15 +141,7 @@ export default {
|
||||
}, 200);
|
||||
};
|
||||
|
||||
const CheckingStore = () => {
|
||||
if (MyYear.value in week.week) {
|
||||
weekendsData();
|
||||
} else {
|
||||
week.getWeekend(MyYear.value);
|
||||
}
|
||||
};
|
||||
|
||||
const openCalendarCreate = () => {
|
||||
const openCalendarCreate = () => {
|
||||
miniCalendarRef.value?.openCalendarCreate();
|
||||
};
|
||||
|
||||
@@ -212,8 +202,6 @@ export default {
|
||||
selectedDate,
|
||||
getMonth,
|
||||
getYear,
|
||||
week,
|
||||
CheckingStore,
|
||||
showEventDialog,
|
||||
calendarForMy,
|
||||
getCalendar,
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<v-row no-gutters class="mb-2 align-end" style="height: 60px" justify="space-between">
|
||||
<v-col md="5" class="flex-grow-0 d-flex align-center">
|
||||
<template v-if="currentView !== 'listAllEvents'">
|
||||
<div class="pb-3 d-flex align-center">
|
||||
<div class="pb-1 d-flex align-center">
|
||||
<v-btn
|
||||
variant="outlined"
|
||||
class="text-subtitle-2 mr-2"
|
||||
@@ -38,7 +38,7 @@
|
||||
<v-icon size="large">mdi-chevron-right</v-icon>
|
||||
</v-btn>
|
||||
|
||||
<span class="text-h5 text-no-wrap ml-2">
|
||||
<span class="text-h6 text-no-wrap ml-2">
|
||||
{{ currentTitle }}
|
||||
</span>
|
||||
</div>
|
||||
@@ -62,12 +62,12 @@
|
||||
variant="plain"
|
||||
density="comfortable"
|
||||
>
|
||||
<v-btn value="timeGridDay">День</v-btn>
|
||||
<v-btn value="timeGridWeek">Неделя</v-btn>
|
||||
<v-btn value="dayGridMonth">Месяц</v-btn>
|
||||
<v-btn value="multiMonthYear">Год</v-btn>
|
||||
<v-btn value="listWeek">Расписание</v-btn>
|
||||
<v-btn value="listAllEvents">Все события</v-btn>
|
||||
<v-btn value="timeGridDay" class="px-2">День</v-btn>
|
||||
<v-btn value="timeGridWeek" class="px-2">Неделя</v-btn>
|
||||
<v-btn value="dayGridMonth" class="px-2">Месяц</v-btn>
|
||||
<v-btn value="multiMonthYear" class="px-2">Год</v-btn>
|
||||
<v-btn value="listWeek" class="px-2">Расписание</v-btn>
|
||||
<v-btn value="listAllEvents" class="px-2">Все события</v-btn>
|
||||
</v-btn-toggle>
|
||||
</v-col>
|
||||
</v-row>
|
||||
@@ -113,6 +113,12 @@ export default {
|
||||
EventsListView,
|
||||
EventListFilters,
|
||||
},
|
||||
|
||||
props: {
|
||||
forHomePage: { type: Boolean, default: false },
|
||||
view: { type: String, default: 'dayGridMonth' },
|
||||
},
|
||||
|
||||
setup(props, { emit }) {
|
||||
const currentView = ref('dayGridMonth');
|
||||
const currentTitle = ref('Календарь');
|
||||
@@ -175,19 +181,21 @@ export default {
|
||||
selectable: true,
|
||||
unselectAuto: false,
|
||||
selectMirror: false,
|
||||
|
||||
dayCellDidMount: (arg) => {
|
||||
const date = arg.date;
|
||||
const dayInfo = calendarStore.isNonWorkingDay(date);
|
||||
|
||||
if (dayInfo.isHoliday === true) {
|
||||
arg.el.classList.add('non-working-day');
|
||||
}
|
||||
|
||||
if (dayInfo.isWeekendForStyling === true) {
|
||||
arg.el.classList.add('grey-background');
|
||||
}
|
||||
dayCellClassNames: (arg) => {
|
||||
const dayInfo = calendarStore.isNonWorkingDay(arg.date);
|
||||
const classes = [];
|
||||
if (dayInfo.isHoliday) classes.push('non-working-day');
|
||||
if (dayInfo.isWeekendForStyling) classes.push('grey-background');
|
||||
return classes;
|
||||
},
|
||||
dayHeaderClassNames: (arg) => {
|
||||
const dayInfo = calendarStore.isNonWorkingDay(arg.date);
|
||||
const classes = [];
|
||||
if (dayInfo.isHoliday) classes.push('non-working-day');
|
||||
if (dayInfo.isWeekendForStyling) classes.push('grey-background');
|
||||
return classes;
|
||||
},
|
||||
|
||||
views: {
|
||||
timeGridDay: {
|
||||
type: 'timeGrid',
|
||||
@@ -312,7 +320,6 @@ export default {
|
||||
|
||||
successCallback(events);
|
||||
},
|
||||
selectable: true,
|
||||
eventClick: handleEventClick,
|
||||
|
||||
dateClick: (info) => {
|
||||
@@ -324,18 +331,8 @@ export default {
|
||||
|
||||
datesSet: (info) => {
|
||||
if (info.view.type === 'listWeek' && selectedDate.value) {
|
||||
const date = new Date(selectedDate.value);
|
||||
|
||||
const options = {
|
||||
weekday: 'long',
|
||||
day: 'numeric',
|
||||
month: 'long',
|
||||
year: 'numeric',
|
||||
};
|
||||
|
||||
const formattedDate = date.toLocaleDateString('ru-RU', options);
|
||||
currentTitle.value = `Расписание на ${formattedDate}`;
|
||||
} else {
|
||||
currentTitle.value = formatScheduleTitle(selectedDate.value);
|
||||
} else if (info.view.type !== 'listWeek') {
|
||||
currentTitle.value = info.view.title;
|
||||
}
|
||||
|
||||
@@ -395,39 +392,82 @@ export default {
|
||||
selectedDate.value = dateStr;
|
||||
};
|
||||
|
||||
onMounted(async () => {
|
||||
const weekdayMap = {
|
||||
воскресенье: 'воскресенье',
|
||||
понедельник: 'понедельник',
|
||||
вторник: 'вторник',
|
||||
среда: 'среду',
|
||||
четверг: 'четверг',
|
||||
пятница: 'пятницу',
|
||||
суббота: 'субботу',
|
||||
};
|
||||
|
||||
const formatScheduleTitle = (dateValue) => {
|
||||
const date = new Date(dateValue);
|
||||
const weekdayRaw = date.toLocaleDateString('ru-RU', { weekday: 'long' });
|
||||
const weekday = weekdayMap[weekdayRaw] || weekdayRaw;
|
||||
const rest = date.toLocaleDateString('ru-RU', {
|
||||
day: 'numeric',
|
||||
month: 'long',
|
||||
year: 'numeric',
|
||||
});
|
||||
return `Расписание на ${weekday}, ${rest}`;
|
||||
};
|
||||
|
||||
const applyView = async (newView) => {
|
||||
if (newView === 'listAllEvents') {
|
||||
currentTitle.value = 'Все события';
|
||||
return;
|
||||
}
|
||||
if (newView === 'listWeek' && selectedDate.value) {
|
||||
currentTitle.value = formatScheduleTitle(selectedDate.value);
|
||||
}
|
||||
|
||||
await nextTick();
|
||||
if (!calendarApi.value) return;
|
||||
|
||||
calendarApi.value.changeView(newView);
|
||||
|
||||
if (newView !== 'listWeek') {
|
||||
currentTitle.value = calendarApi.value.view.title;
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(async () => {
|
||||
const currentYear = new Date().getFullYear();
|
||||
calendarStore.fetchHolidays(currentYear);
|
||||
// Ждем следующего тика для гарантии, что календарь инициализирован
|
||||
await nextTick();
|
||||
|
||||
// Принудительно обновляем события после загрузки праздников
|
||||
if (calendarApi.value) {
|
||||
if (calendarApi.value && currentView.value !== 'listAllEvents') {
|
||||
calendarApi.value.refetchEvents();
|
||||
}
|
||||
|
||||
if (selectedDate.value) {
|
||||
if (selectedDate.value && currentView.value !== 'listAllEvents') {
|
||||
handleDateSelection(selectedDate.value);
|
||||
}
|
||||
});
|
||||
|
||||
watch(currentView, (newView) => {
|
||||
applyView(newView);
|
||||
});
|
||||
|
||||
watch(
|
||||
[() => calendarStore.calendars, () => calendarStore.hiddenCalendarIds],
|
||||
() => {
|
||||
// При изменении событий перезагружаем календарь
|
||||
if (calendarApi.value) {
|
||||
calendarApi.value.refetchEvents();
|
||||
}
|
||||
if (currentView.value === 'listAllEvents') return;
|
||||
calendarApi.value?.refetchEvents();
|
||||
},
|
||||
{ deep: true },
|
||||
);
|
||||
|
||||
watch(
|
||||
calendarColorMap,
|
||||
(newColorMap, oldColorMap) => {
|
||||
if (calendarRef.value && JSON.stringify(newColorMap) !== JSON.stringify(oldColorMap)) {
|
||||
renderEvents();
|
||||
}
|
||||
() => {
|
||||
if (currentView.value === 'listAllEvents') return;
|
||||
calendarApi.value?.refetchEvents();
|
||||
},
|
||||
{ deep: true },
|
||||
);
|
||||
@@ -441,15 +481,6 @@ export default {
|
||||
}
|
||||
});
|
||||
|
||||
watch(currentView, (newView) => {
|
||||
if (newView === 'listAllEvents') {
|
||||
currentTitle.value = 'Все события';
|
||||
} else if (calendarApi.value) {
|
||||
calendarApi.value.changeView(newView);
|
||||
currentTitle.value = calendarApi.value.view.title;
|
||||
}
|
||||
});
|
||||
|
||||
const handleFiltersUpdate = (newFilters) => {
|
||||
Object.keys(newFilters).forEach((key) => {
|
||||
if (filters[key] !== undefined) {
|
||||
@@ -504,7 +535,7 @@ export default {
|
||||
:deep(.fc-day-today .fc-daygrid-day-number) {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
color: #00897b;
|
||||
color: rgb(var(--v-theme-btn_text));
|
||||
|
||||
&::before {
|
||||
content: '';
|
||||
@@ -514,7 +545,7 @@ export default {
|
||||
transform: translate(-50%, -50%);
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border: 1px solid #00897b;
|
||||
border: 1px solid rgb(var(--v-theme-btn_text));
|
||||
border-radius: 50%;
|
||||
z-index: -1;
|
||||
}
|
||||
@@ -529,7 +560,7 @@ export default {
|
||||
:deep(.fc-day-selected-custom .fc-daygrid-day-number) {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
color: white !important;
|
||||
color: rgb(var(--v-theme-bg_white)) !important;
|
||||
}
|
||||
|
||||
:deep(.fc-day-selected-custom .fc-daygrid-day-number::before) {
|
||||
@@ -540,7 +571,7 @@ export default {
|
||||
transform: translate(-50%, -50%);
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
background-color: #00897b;
|
||||
background-color: rgb(var(--v-theme-btn_text));
|
||||
border-radius: 50%;
|
||||
z-index: -1;
|
||||
}
|
||||
@@ -555,11 +586,16 @@ export default {
|
||||
|
||||
:deep(.v-btn--active) {
|
||||
background-color: transparent !important;
|
||||
color: #00897b !important;
|
||||
color: rgb(var(--v-theme-btn_text)) !important;
|
||||
}
|
||||
|
||||
:deep(.fc .fc-timegrid-col.fc-day-today) {
|
||||
background-color: #e0f2f1 !important;
|
||||
background-color: rgba(var(--v-theme-btn_text), 0.1) !important;
|
||||
}
|
||||
|
||||
:deep(.fc-timegrid-col.non-working-day),
|
||||
:deep(.fc-day.non-working-day:not(.fc-daygrid-day)) {
|
||||
background-color: rgba(var(--v-theme-holiday_text), 0.05) !important;
|
||||
}
|
||||
|
||||
:deep(.fc-highlight) {
|
||||
@@ -571,27 +607,31 @@ export default {
|
||||
}
|
||||
|
||||
:deep(.fc-popover) {
|
||||
background-color: rgb(248, 244, 244) !important;
|
||||
background-color: rgb(var(--v-theme-cards)) !important;
|
||||
}
|
||||
|
||||
.non-working-day {
|
||||
color: red !important;
|
||||
:deep(.fc-day.non-working-day .fc-daygrid-day-number),
|
||||
:deep(.fc-day.non-working-day .fc-daygrid-day-top) {
|
||||
color: rgb(var(--v-theme-holiday_text)) !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-col-header-cell.non-working-day),
|
||||
:deep(.fc-col-header-cell.non-working-day .fc-col-header-cell-cushion) {
|
||||
color: rgb(var(--v-theme-holiday_text)) !important;
|
||||
}
|
||||
|
||||
:deep(.grey-background),
|
||||
:deep(.fc-day.grey-background) {
|
||||
background-color: #f5f5f5 !important;
|
||||
background-color: rgb(var(--v-theme-weekend_bg)) !important;
|
||||
}
|
||||
|
||||
:deep(.fc-day.grey-background .fc-daygrid-day-number) {
|
||||
color: rgb(var(--v-theme-weekend_text)) !important;
|
||||
}
|
||||
|
||||
:deep(.fc-col-header-cell.grey-background),
|
||||
:deep(.fc-col-header-cell.grey-background .fc-col-header-cell-cushion) {
|
||||
color: rgb(var(--v-theme-weekend_text)) !important;
|
||||
}
|
||||
|
||||
.custom-calendar {
|
||||
|
||||
Executable → Regular
+310
-199
@@ -1,15 +1,15 @@
|
||||
<template>
|
||||
<v-card class="home-calendar-widget" elevation="2">
|
||||
<v-card class="home-calendar-widget" elevation="2" rounded="lg">
|
||||
<v-card-text class="pa-4">
|
||||
<v-row no-gutters class="calendar-pair">
|
||||
<!-- Месячный календарь -->
|
||||
<v-col cols="7" class="pr-2">
|
||||
<div class="calendar-header">
|
||||
<v-btn icon size="small" class="nav-btn" @click="prevMonth">
|
||||
<v-btn icon size="small" @click="prevMonth" class="nav-btn">
|
||||
<v-icon>mdi-chevron-left</v-icon>
|
||||
</v-btn>
|
||||
<span class="month-title">{{ currentMonth }}</span>
|
||||
<v-btn icon size="small" class="nav-btn" @click="nextMonth">
|
||||
<v-btn icon size="small" @click="nextMonth" class="nav-btn">
|
||||
<v-icon>mdi-chevron-right</v-icon>
|
||||
</v-btn>
|
||||
</div>
|
||||
@@ -17,11 +17,13 @@
|
||||
<v-table class="month-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th v-for="day in WEEKDAYS" :key="day" class="weekday-header">{{ day }}</th>
|
||||
<th v-for="day in russianWeekdays" :key="day" class="weekday-header">
|
||||
{{ day }}
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="(week, i) in calendarWeeks" :key="i">
|
||||
<tr v-for="(week, weekIndex) in calendarWeeks" :key="weekIndex">
|
||||
<td
|
||||
v-for="day in week"
|
||||
:key="day.date"
|
||||
@@ -33,8 +35,7 @@
|
||||
'non-working-day': day.isHoliday,
|
||||
'grey-background': day.isWeekend,
|
||||
}"
|
||||
@click="selectedDate = day.date"
|
||||
@dblclick.stop="goToDay(day.date)"
|
||||
@click="onDateClick(day.date)"
|
||||
>
|
||||
<div class="day-content">
|
||||
<span class="day-number">{{ day.day }}</span>
|
||||
@@ -44,7 +45,7 @@
|
||||
:key="event.id"
|
||||
class="event-indicator"
|
||||
:style="{ backgroundColor: event.color }"
|
||||
/>
|
||||
></span>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
@@ -63,25 +64,28 @@
|
||||
|
||||
<v-card variant="outlined" class="day-schedule" elevation="0">
|
||||
<v-list density="comfortable" class="py-0">
|
||||
<template v-if="dayEvents.length">
|
||||
<v-list-item
|
||||
v-for="event in dayEvents"
|
||||
:key="event.id"
|
||||
class="schedule-item"
|
||||
:class="{ 'current-event': isCurrentEvent(event) }"
|
||||
@click="calendarStore.handleEventClick({ event: { id: event.id } })"
|
||||
>
|
||||
<template #prepend>
|
||||
<div class="event-color-indicator" :style="{ backgroundColor: event.color }" />
|
||||
</template>
|
||||
<v-list-item-title class="event-time">{{
|
||||
formatTime(event.start)
|
||||
}}</v-list-item-title>
|
||||
<v-list-item-subtitle class="event-title">{{ event.title }}</v-list-item-subtitle>
|
||||
</v-list-item>
|
||||
</template>
|
||||
<v-list-item
|
||||
v-for="event in dayEvents"
|
||||
:key="event.id"
|
||||
class="schedule-item"
|
||||
:class="{ 'current-event': isCurrentEvent(event) }"
|
||||
>
|
||||
<template #prepend>
|
||||
<div
|
||||
class="event-color-indicator"
|
||||
:style="{ backgroundColor: event.color }"
|
||||
></div>
|
||||
</template>
|
||||
|
||||
<v-list-item v-else class="no-events">
|
||||
<v-list-item-title class="event-time">
|
||||
{{ formatTime(event.start) }}
|
||||
</v-list-item-title>
|
||||
<v-list-item-subtitle class="event-title">
|
||||
{{ event.title }}
|
||||
</v-list-item-subtitle>
|
||||
</v-list-item>
|
||||
|
||||
<v-list-item v-if="dayEvents.length === 0" class="no-events">
|
||||
<v-list-item-title class="text-grey text-center">
|
||||
На этот день событий нет
|
||||
</v-list-item-title>
|
||||
@@ -94,187 +98,292 @@
|
||||
</v-card>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, computed, onMounted } from 'vue';
|
||||
<script>
|
||||
import { ref, computed, onMounted, watch } from 'vue';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { useCalendarStore } from '@/store/calendarStore';
|
||||
import { useRecurrence } from '@/components/calendar_of_events/composables/useReccurrence';
|
||||
|
||||
const WEEKDAYS = ['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс'];
|
||||
export default {
|
||||
name: 'HomeCalendarWidget',
|
||||
|
||||
const toLocalDateStr = (date) => {
|
||||
const y = date.getFullYear();
|
||||
const m = String(date.getMonth() + 1).padStart(2, '0');
|
||||
const d = String(date.getDate()).padStart(2, '0');
|
||||
return `${y}-${m}-${d}`;
|
||||
};
|
||||
setup() {
|
||||
// Реактивные данные
|
||||
const currentDate = ref(new Date());
|
||||
const selectedDate = ref(''); // Будет установлено в формате YYYY-MM-DD
|
||||
const currentYear = new Date().getFullYear();
|
||||
|
||||
const startOfDay = (date) => {
|
||||
const d = new Date(date);
|
||||
d.setHours(0, 0, 0, 0);
|
||||
return d;
|
||||
};
|
||||
// Работа с хранилищем
|
||||
const calendarStore = useCalendarStore();
|
||||
const { allEvents, calendarColorMap } = storeToRefs(calendarStore);
|
||||
const { generateRecurringInstances, isRecurringEvent } = useRecurrence();
|
||||
|
||||
const datesEqual = (a, b) => startOfDay(a).getTime() === startOfDay(b).getTime();
|
||||
// Утилиты для работы с датами (главный источник проблем!)
|
||||
const formatToLocalDate = (date) => {
|
||||
const year = date.getFullYear();
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(date.getDate()).padStart(2, '0');
|
||||
return `${year}-${month}-${day}`;
|
||||
};
|
||||
|
||||
const router = useRouter();
|
||||
const calendarStore = useCalendarStore();
|
||||
const { allEvents, calendarColorMap } = storeToRefs(calendarStore);
|
||||
const { generateRecurringInstances } = useRecurrence();
|
||||
const getStartOfDay = (date) => {
|
||||
const newDate = new Date(date);
|
||||
newDate.setHours(0, 0, 0, 0);
|
||||
return newDate;
|
||||
};
|
||||
|
||||
const currentDate = ref(new Date());
|
||||
const selectedDate = ref('');
|
||||
const areDatesEqual = (date1, date2) => {
|
||||
return getStartOfDay(date1).getTime() === getStartOfDay(date2).getTime();
|
||||
};
|
||||
|
||||
const prevMonth = () => {
|
||||
const d = new Date(currentDate.value);
|
||||
d.setMonth(d.getMonth() - 1);
|
||||
currentDate.value = d;
|
||||
};
|
||||
const events = computed(() => {
|
||||
const expandedEvents = allEvents.value.flatMap((event) => {
|
||||
const startDate = new Date(event.date_start);
|
||||
const endDate = new Date(event.date_end);
|
||||
const isMultiDay = startDate.toDateString() !== endDate.toDateString();
|
||||
const hasRecurrence = event.period && event.period !== 'null';
|
||||
|
||||
const nextMonth = () => {
|
||||
const d = new Date(currentDate.value);
|
||||
d.setMonth(d.getMonth() + 1);
|
||||
currentDate.value = d;
|
||||
};
|
||||
// 1. Периодичное + многодневное
|
||||
if (hasRecurrence && isMultiDay) {
|
||||
const instances = generateRecurringInstances(event, 12);
|
||||
return instances.flatMap((instance) => expandMultiDayInstance(event, instance));
|
||||
}
|
||||
|
||||
const goToDay = (date) => {
|
||||
calendarStore.setSelectedDate(date);
|
||||
router.push({ name: 'Calendar', query: { date, view: 'day' } });
|
||||
};
|
||||
// 2. Периодичное + однодневное
|
||||
if (hasRecurrence && !isMultiDay) {
|
||||
const instances = generateRecurringInstances(event, 12);
|
||||
return instances.map((instance) => ({
|
||||
...event,
|
||||
id: instance.id,
|
||||
date_start: instance.date_start || instance.start,
|
||||
date_end: instance.date_end || instance.end,
|
||||
isRecurringInstance: true,
|
||||
}));
|
||||
}
|
||||
|
||||
const expandMultiDay = (originalEvent, instance) => {
|
||||
const start = new Date(instance.date_start || instance.start);
|
||||
const end = new Date(instance.date_end || instance.end);
|
||||
const days = [];
|
||||
const cur = new Date(start);
|
||||
// 3. Непериодичное + многодневное
|
||||
if (!hasRecurrence && isMultiDay) {
|
||||
return expandMultiDayInstance(event, event);
|
||||
}
|
||||
|
||||
while (cur < end) {
|
||||
const dayEnd = new Date(cur);
|
||||
dayEnd.setDate(dayEnd.getDate() + 1);
|
||||
days.push({
|
||||
...originalEvent,
|
||||
id: instance.id,
|
||||
date_start: new Date(cur).toISOString(),
|
||||
date_end: dayEnd.toISOString(),
|
||||
allday: true,
|
||||
isMultiDayPart: true,
|
||||
isRecurringInstance: instance.isRecurringInstance || false,
|
||||
});
|
||||
cur.setDate(cur.getDate() + 1);
|
||||
}
|
||||
return days;
|
||||
};
|
||||
// 4. Непериодичное + однодневное
|
||||
return event;
|
||||
});
|
||||
|
||||
const toWidgetEvent = (event) => ({
|
||||
id: event.id,
|
||||
title: event.name || 'Без названия',
|
||||
start: event.date_start,
|
||||
end: event.date_end,
|
||||
color: event.calendarData?.cl_color || calendarColorMap.value?.get(event.calendar) || '#1976d2',
|
||||
description: event.description,
|
||||
calendar: event.calendar,
|
||||
isRecurringInstance: event.isRecurringInstance || false,
|
||||
isMultiDayPart: event.isMultiDayPart || false,
|
||||
});
|
||||
|
||||
const events = computed(() =>
|
||||
allEvents.value
|
||||
.flatMap((event) => {
|
||||
const start = new Date(event.date_start);
|
||||
const end = new Date(event.date_end);
|
||||
const isMultiDay = start.toDateString() !== end.toDateString();
|
||||
const hasRecur = event.period && event.period !== 'null';
|
||||
|
||||
if (hasRecur && isMultiDay) {
|
||||
return generateRecurringInstances(event, 12).flatMap((inst) => expandMultiDay(event, inst));
|
||||
}
|
||||
if (hasRecur && !isMultiDay) {
|
||||
return generateRecurringInstances(event, 12).map((inst) => ({
|
||||
...event,
|
||||
id: inst.id,
|
||||
date_start: inst.date_start || inst.start,
|
||||
date_end: inst.date_end || inst.end,
|
||||
isRecurringInstance: true,
|
||||
}));
|
||||
}
|
||||
if (!hasRecur && isMultiDay) return expandMultiDay(event, event);
|
||||
return event;
|
||||
})
|
||||
.map(toWidgetEvent),
|
||||
);
|
||||
|
||||
const calendarWeeks = computed(() => {
|
||||
const year = currentDate.value.getFullYear();
|
||||
const month = currentDate.value.getMonth();
|
||||
const start = new Date(year, month, 1);
|
||||
start.setDate(start.getDate() - ((start.getDay() + 6) % 7));
|
||||
|
||||
const weeks = [];
|
||||
let week = [];
|
||||
|
||||
for (let i = 0; i < 42; i++) {
|
||||
const day = new Date(start);
|
||||
day.setDate(start.getDate() + i);
|
||||
const info = calendarStore.isNonWorkingDay(day);
|
||||
|
||||
week.push({
|
||||
day: day.getDate(),
|
||||
date: toLocalDateStr(day),
|
||||
isCurrentMonth: day.getMonth() === month,
|
||||
isHoliday: info.isHoliday,
|
||||
isWeekend: info.isWeekendForStyling,
|
||||
return expandedEvents.map((event) => formatForWidget(event));
|
||||
});
|
||||
|
||||
if (week.length === 7) {
|
||||
weeks.push([...week]);
|
||||
week = [];
|
||||
}
|
||||
}
|
||||
return weeks;
|
||||
});
|
||||
// Разбивает многодневный экземпляр на дни
|
||||
const expandMultiDayInstance = (originalEvent, instance) => {
|
||||
const startDate = new Date(instance.date_start || instance.start);
|
||||
const endDate = new Date(instance.date_end || instance.end);
|
||||
const days = [];
|
||||
const currentDay = new Date(startDate);
|
||||
|
||||
const currentMonth = computed(() =>
|
||||
currentDate.value.toLocaleDateString('ru-RU', { month: 'long', year: 'numeric' }),
|
||||
);
|
||||
while (currentDay < endDate) {
|
||||
const dayStart = new Date(currentDay);
|
||||
const dayEnd = new Date(currentDay);
|
||||
dayEnd.setDate(dayEnd.getDate() + 1);
|
||||
|
||||
const formattedSelectedDate = computed(() => {
|
||||
if (!selectedDate.value) return '';
|
||||
return new Date(`${selectedDate.value}T12:00:00`).toLocaleDateString('ru-RU', {
|
||||
day: 'numeric',
|
||||
month: 'long',
|
||||
year: 'numeric',
|
||||
});
|
||||
});
|
||||
days.push({
|
||||
...originalEvent,
|
||||
id: instance.id, // ID от экземпляра периодичности
|
||||
date_start: dayStart.toISOString(),
|
||||
date_end: dayEnd.toISOString(),
|
||||
allday: true,
|
||||
isMultiDayPart: true,
|
||||
isRecurringInstance: instance.isRecurringInstance || false,
|
||||
originalStart: instance.date_start || instance.start,
|
||||
originalEnd: instance.date_end || instance.end,
|
||||
});
|
||||
|
||||
const dayEvents = computed(() => {
|
||||
if (!selectedDate.value) return [];
|
||||
const sel = new Date(`${selectedDate.value}T12:00:00`);
|
||||
return events.value
|
||||
.filter((e) => datesEqual(new Date(e.start), sel))
|
||||
.sort((a, b) => new Date(a.start) - new Date(b.start));
|
||||
});
|
||||
currentDay.setDate(currentDay.getDate() + 1);
|
||||
}
|
||||
|
||||
const isToday = (date) => datesEqual(new Date(), new Date(`${date}T12:00:00`));
|
||||
const isSelected = (date) => date === selectedDate.value;
|
||||
return days;
|
||||
};
|
||||
|
||||
const getDayEvents = (date) => {
|
||||
const d = new Date(`${date}T12:00:00`);
|
||||
return events.value.filter((e) => datesEqual(new Date(e.start), d));
|
||||
// Форматирование для виджета
|
||||
const formatForWidget = (event) => {
|
||||
const eventColor =
|
||||
event.calendarData?.cl_color || calendarColorMap.value?.get(event.calendar) || '#1976d2';
|
||||
|
||||
return {
|
||||
id: event.id,
|
||||
title: event.name || 'Без названия',
|
||||
start: event.date_start,
|
||||
end: event.date_end,
|
||||
description: event.description,
|
||||
color: eventColor,
|
||||
calendar: event.calendar,
|
||||
calendarData: event.calendarData,
|
||||
isRecurringInstance: event.isRecurringInstance || false,
|
||||
isMultiDayPart: event.isMultiDayPart || false,
|
||||
};
|
||||
};
|
||||
|
||||
const russianWeekdays = ['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс'];
|
||||
|
||||
// Генерация календаря
|
||||
const calendarWeeks = computed(() => {
|
||||
const year = currentDate.value.getFullYear();
|
||||
const month = currentDate.value.getMonth();
|
||||
const firstDay = new Date(year, month, 1);
|
||||
|
||||
const weeks = [];
|
||||
let week = [];
|
||||
|
||||
// Находим понедельник первой недели
|
||||
const startDay = new Date(firstDay);
|
||||
startDay.setDate(startDay.getDate() - ((startDay.getDay() + 6) % 7));
|
||||
|
||||
// Генерируем 6 недель (фиксированное количество для стабильности)
|
||||
for (let i = 0; i < 42; i++) {
|
||||
const currentDay = new Date(startDay);
|
||||
currentDay.setDate(startDay.getDate() + i);
|
||||
|
||||
const dayInfo = calendarStore.isNonWorkingDay(currentDay);
|
||||
|
||||
week.push({
|
||||
day: currentDay.getDate(),
|
||||
date: formatToLocalDate(currentDay),
|
||||
isCurrentMonth: currentDay.getMonth() === month,
|
||||
isHoliday: dayInfo.isHoliday,
|
||||
isWeekend: dayInfo.isWeekendForStyling,
|
||||
});
|
||||
|
||||
if (week.length === 7) {
|
||||
weeks.push([...week]);
|
||||
week = [];
|
||||
}
|
||||
}
|
||||
|
||||
return weeks;
|
||||
});
|
||||
|
||||
const currentMonth = computed(() => {
|
||||
return currentDate.value.toLocaleDateString('ru-RU', {
|
||||
month: 'long',
|
||||
year: 'numeric',
|
||||
});
|
||||
});
|
||||
|
||||
const formattedSelectedDate = computed(() => {
|
||||
if (!selectedDate.value) return '';
|
||||
|
||||
// Добавляем время для избежания смещения часовых поясов
|
||||
const date = new Date(selectedDate.value + 'T12:00:00');
|
||||
return date.toLocaleDateString('ru-RU', {
|
||||
day: 'numeric',
|
||||
month: 'long',
|
||||
year: 'numeric',
|
||||
});
|
||||
});
|
||||
|
||||
const dayEvents = computed(() => {
|
||||
if (!selectedDate.value) return [];
|
||||
|
||||
const selected = new Date(selectedDate.value + 'T12:00:00');
|
||||
|
||||
return events.value
|
||||
.filter((event) => {
|
||||
const eventDate = new Date(event.start);
|
||||
return areDatesEqual(eventDate, selected);
|
||||
})
|
||||
.sort((a, b) => new Date(a.start).getTime() - new Date(b.start).getTime());
|
||||
});
|
||||
|
||||
// Методы
|
||||
const isToday = (date) => {
|
||||
const today = new Date();
|
||||
const checkDate = new Date(date + 'T12:00:00');
|
||||
return areDatesEqual(today, checkDate);
|
||||
};
|
||||
|
||||
const isSelected = (date) => {
|
||||
return date === selectedDate.value;
|
||||
};
|
||||
|
||||
const getDayEvents = (date) => {
|
||||
const checkDate = new Date(date + 'T12:00:00');
|
||||
|
||||
return events.value.filter((event) => {
|
||||
const eventDate = new Date(event.start);
|
||||
return areDatesEqual(eventDate, checkDate);
|
||||
});
|
||||
};
|
||||
|
||||
const isCurrentEvent = (event) => {
|
||||
const now = new Date();
|
||||
const start = new Date(event.start);
|
||||
const end = new Date(event.end);
|
||||
return now >= start && now <= end;
|
||||
};
|
||||
|
||||
const formatTime = (dateString) => {
|
||||
return new Date(dateString).toLocaleTimeString('ru-RU', {
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
});
|
||||
};
|
||||
|
||||
const onDateClick = (date) => {
|
||||
selectedDate.value = date;
|
||||
};
|
||||
|
||||
const prevMonth = () => {
|
||||
const date = new Date(currentDate.value);
|
||||
date.setMonth(date.getMonth() - 1);
|
||||
currentDate.value = date;
|
||||
};
|
||||
|
||||
const nextMonth = () => {
|
||||
const date = new Date(currentDate.value);
|
||||
date.setMonth(date.getMonth() + 1);
|
||||
currentDate.value = date;
|
||||
};
|
||||
|
||||
const isWeekendOrHoliday = (dateString) => {
|
||||
const dayInfo = calendarStore.isNonWorkingDay(dateString);
|
||||
return dayInfo.isHoliday || dayInfo.isWeekendForStyling;
|
||||
};
|
||||
|
||||
onMounted(async () => {
|
||||
selectedDate.value = formatToLocalDate(new Date());
|
||||
await calendarStore.fetchHolidays(currentYear);
|
||||
});
|
||||
|
||||
return {
|
||||
// Реактивные данные
|
||||
currentDate,
|
||||
selectedDate,
|
||||
|
||||
// Вычисляемые свойства
|
||||
events,
|
||||
russianWeekdays,
|
||||
calendarWeeks,
|
||||
currentMonth,
|
||||
formattedSelectedDate,
|
||||
dayEvents,
|
||||
isWeekendOrHoliday,
|
||||
|
||||
// Методы
|
||||
isToday,
|
||||
isSelected,
|
||||
getDayEvents,
|
||||
isCurrentEvent,
|
||||
formatTime,
|
||||
onDateClick,
|
||||
prevMonth,
|
||||
nextMonth,
|
||||
|
||||
calendarStore,
|
||||
allEvents,
|
||||
expandMultiDayInstance,
|
||||
formatForWidget,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
const isCurrentEvent = (event) => {
|
||||
const now = new Date();
|
||||
return now >= new Date(event.start) && now <= new Date(event.end);
|
||||
};
|
||||
|
||||
const formatTime = (dateStr) =>
|
||||
new Date(dateStr).toLocaleTimeString('ru-RU', { hour: '2-digit', minute: '2-digit' });
|
||||
|
||||
onMounted(async () => {
|
||||
selectedDate.value = toLocalDateStr(new Date());
|
||||
await calendarStore.fetchHolidays(new Date().getFullYear());
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
@@ -282,7 +391,6 @@ onMounted(async () => {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
font-family: 'Roboto', sans-serif;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.calendar-pair {
|
||||
@@ -347,6 +455,19 @@ onMounted(async () => {
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.day-cell.today {
|
||||
background-color: rgba(var(--v-theme-primary), 0.15);
|
||||
}
|
||||
|
||||
.day-cell.selected {
|
||||
background-color: rgb(var(--v-theme-btn_text));
|
||||
color: rgb(var(--v-theme-bg_white));
|
||||
}
|
||||
|
||||
.day-cell.selected .day-number {
|
||||
color: rgb(var(--v-theme-bg_white));
|
||||
}
|
||||
|
||||
.day-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
@@ -426,6 +547,7 @@ onMounted(async () => {
|
||||
.event-time {
|
||||
font-size: 0.8rem;
|
||||
font-weight: 600;
|
||||
color: #302f2f;
|
||||
color: rgb(var(--v-theme-text_carous));
|
||||
margin-bottom: 2px;
|
||||
}
|
||||
@@ -451,17 +573,17 @@ onMounted(async () => {
|
||||
}
|
||||
|
||||
.day-schedule::-webkit-scrollbar-track {
|
||||
background: rgba(var(--v-theme-on-surface), 0.05);
|
||||
background: #f1f1f1;
|
||||
border-radius: 0 8px 8px 0;
|
||||
}
|
||||
|
||||
.day-schedule::-webkit-scrollbar-thumb {
|
||||
background: rgba(var(--v-theme-on-surface), 0.25);
|
||||
background: #c1c1c1;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.day-schedule::-webkit-scrollbar-thumb:hover {
|
||||
background: rgba(var(--v-theme-on-surface), 0.4);
|
||||
background: #a8a8a8;
|
||||
}
|
||||
|
||||
.non-working-day {
|
||||
@@ -476,15 +598,4 @@ onMounted(async () => {
|
||||
.day-cell:not(.current-month).non-working-day {
|
||||
color: inherit !important;
|
||||
}
|
||||
|
||||
.day-cell.selected,
|
||||
.day-cell.selected.grey-background,
|
||||
.day-cell.selected.non-working-day {
|
||||
background-color: rgb(var(--v-theme-btn_text)) !important;
|
||||
color: rgb(var(--v-theme-bg_white)) !important;
|
||||
}
|
||||
|
||||
.day-cell.selected .day-number {
|
||||
color: rgb(var(--v-theme-bg_white)) !important;
|
||||
}
|
||||
</style>
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<v-card class="h-100 rounded-0 d-flex flex-colmn">
|
||||
<v-card class="h-100 rounded-0 d-flex flex-column">
|
||||
<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 } from 'vue';
|
||||
import { onMounted, watch, nextTick, ref, onBeforeUnmount } from 'vue';
|
||||
import { storeToRefs } from 'pinia';
|
||||
|
||||
export default {
|
||||
@@ -67,14 +67,10 @@ 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);
|
||||
@@ -89,12 +85,6 @@ export default {
|
||||
calendarStore.loadCalendars();
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
loadCalendars();
|
||||
|
||||
updateCalendarDays();
|
||||
});
|
||||
|
||||
// Реакция на изменения пользователя
|
||||
watch(user, (newUser) => {
|
||||
if (newUser) {
|
||||
@@ -192,25 +182,24 @@ 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,
|
||||
@@ -225,16 +214,7 @@ export default {
|
||||
};
|
||||
</script>
|
||||
<style scoped>
|
||||
/* .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 {
|
||||
.minCal .v-date-picker-month__day {
|
||||
height: 31px;
|
||||
width: 31px;
|
||||
}
|
||||
@@ -255,23 +235,24 @@ export default {
|
||||
/* СТИЛИ ДЛЯ ВЫХОДНЫХ И ПРАЗДНИКОВ */
|
||||
|
||||
.minCal:deep(.weekend-day .v-btn__content) {
|
||||
color: #666 !important;
|
||||
color: rgb(var(--v-theme-weekend_text)) !important;
|
||||
}
|
||||
|
||||
.minCal:deep(.holiday-day .v-btn__content) {
|
||||
color: #ff4444 !important;
|
||||
font-weight: bold !important;
|
||||
color: rgb(var(--v-theme-holiday_text)) !important;
|
||||
font-weight: 600 !important;
|
||||
}
|
||||
|
||||
.minCal:deep(.weekend-day.holiday-day) {
|
||||
background-color: #ffe0e0 !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 .v-btn__content) {
|
||||
color: #cc0000 !important;
|
||||
color: rgb(var(--v-theme-holiday_text)) !important;
|
||||
font-weight: 600 !important;
|
||||
}
|
||||
|
||||
search-dropdown {
|
||||
.search-dropdown {
|
||||
max-height: 300px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
import { axiosApiInstance } from "@/utils/axios-api";
|
||||
import { defineStore } from "pinia";
|
||||
import { ref } from "vue";
|
||||
|
||||
export const useWeekendsStore = defineStore("weekends", () => {
|
||||
|
||||
const week = ref({});
|
||||
|
||||
function getWeekend(year) {
|
||||
axiosApiInstance
|
||||
.get(`api/calendar_of_events/exclusion_dates/?year=${year}`, {})
|
||||
.then((data) => {
|
||||
week.value = data.data;
|
||||
});
|
||||
}
|
||||
return { week, getWeekend };
|
||||
});
|
||||
Executable → Regular
+41
-139
@@ -9,6 +9,8 @@ export const useCalendarStore = defineStore('calendarStore', () => {
|
||||
// State
|
||||
const selectedDate = ref(new Date());
|
||||
const events = ref([]);
|
||||
const selectedEvent = ref(null);
|
||||
const showEventDialog = ref(false);
|
||||
const currentView = ref('dayGridMonth'); // Текущий вид календаря
|
||||
const calendars = ref([]); // Список календарей пользователя
|
||||
const lastUpdatedBy = ref(null);
|
||||
@@ -18,11 +20,6 @@ export const useCalendarStore = defineStore('calendarStore', () => {
|
||||
const dictEmployeesLoaded = ref(false);
|
||||
const employees = ref([]);
|
||||
|
||||
const selectedEvent = ref(null);
|
||||
const selectedEventForView = ref(null);
|
||||
const showEventDialog = ref(false);
|
||||
const showViewDialog = ref(false);
|
||||
|
||||
// Массив ID скрытых календарей. Загружаем из localStorage при инициализации.
|
||||
const hiddenCalendarIds = ref([]);
|
||||
|
||||
@@ -178,156 +175,66 @@ export const useCalendarStore = defineStore('calendarStore', () => {
|
||||
return editableEvents.value.some((e) => e.id === id);
|
||||
};
|
||||
|
||||
const fetchHolidays = async (year) => {
|
||||
if (holidays.value[year] || loadingYears.value.has(year)) {
|
||||
return holidays.value[year];
|
||||
}
|
||||
loadingYears.value.add(year);
|
||||
try {
|
||||
const { data } = await axiosApiInstance.get(
|
||||
`api/calendar_of_events/exclusion_dates/?year=${year}`,
|
||||
);
|
||||
holidays.value = { ...holidays.value, ...data };
|
||||
return holidays.value[year];
|
||||
} catch (err) {
|
||||
console.error('Ошибка загрузки праздников:', err);
|
||||
throw err;
|
||||
} finally {
|
||||
loadingYears.value.delete(year);
|
||||
}
|
||||
};
|
||||
const fetchHolidays = async (year) => {
|
||||
if (holidays.value[year] || loadingYears.value.has(year)) {
|
||||
return holidays.value[year];
|
||||
}
|
||||
loadingYears.value.add(year);
|
||||
try {
|
||||
const { data } = await axiosApiInstance.get(
|
||||
`api/calendar_of_events/exclusion_dates/?year=${year}`,
|
||||
);
|
||||
holidays.value = { ...holidays.value, ...data };
|
||||
return holidays.value[year];
|
||||
} catch (err) {
|
||||
console.error('Ошибка загрузки праздников:', err);
|
||||
throw err;
|
||||
} finally {
|
||||
loadingYears.value.delete(year);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Метод для проверки, является ли день выходным или праздничным
|
||||
const isNonWorkingDay = (dateInput) => {
|
||||
const date = dateInput instanceof Date ? dateInput : new Date(dateInput);
|
||||
if (isNaN(date.getTime())) {
|
||||
return { isNonWorking: false, isWeekendForStyling: false, isHoliday: false };
|
||||
}
|
||||
const isNonWorkingDay = (dateInput) => {
|
||||
const date = dateInput instanceof Date ? dateInput : new Date(dateInput);
|
||||
if (isNaN(date.getTime())) {
|
||||
return { isNonWorking: false, isWeekendForStyling: false, isHoliday: false };
|
||||
}
|
||||
|
||||
const year = date.getFullYear();
|
||||
const month = date.getMonth() + 1;
|
||||
const iso = `${year}-${String(month).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`;
|
||||
const year = date.getFullYear();
|
||||
const month = date.getMonth() + 1;
|
||||
const iso = `${year}-${String(month).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`;
|
||||
|
||||
const day = date.getDay();
|
||||
const isWeekend = day === 0 || day === 6;
|
||||
const isHoliday = (holidays.value[year]?.[month] ?? []).includes(iso);
|
||||
const day = date.getDay();
|
||||
const isWeekend = day === 0 || day === 6;
|
||||
const isHoliday = (holidays.value[year]?.[month] ?? []).includes(iso);
|
||||
|
||||
return {
|
||||
isNonWorking: isWeekend || isHoliday,
|
||||
isWeekendForStyling: isWeekend,
|
||||
isHoliday,
|
||||
};
|
||||
};
|
||||
|
||||
const setSelectedEvent = (event) => {
|
||||
selectedEvent.value = event;
|
||||
};
|
||||
|
||||
// Шаблон пустого события (создание)
|
||||
const getEmptyEventWrapper = () => {
|
||||
const now = new Date();
|
||||
const inHour = new Date(now.getTime() + 60 * 60 * 1000);
|
||||
return {
|
||||
event: {
|
||||
name: '',
|
||||
description: '',
|
||||
date_start: now.toISOString(),
|
||||
date_end: inHour.toISOString(),
|
||||
allday: false,
|
||||
period: null,
|
||||
participant: [accountStore.user.is_idEmployee],
|
||||
calendar: null,
|
||||
files: [],
|
||||
},
|
||||
mycalendars: calendars.value,
|
||||
};
|
||||
};
|
||||
|
||||
// Шаблон обёртки для редактирования
|
||||
const buildEventWrapper = (fullEvent) => {
|
||||
return {
|
||||
event: {
|
||||
...fullEvent,
|
||||
participant: Array.isArray(fullEvent.participant)
|
||||
? fullEvent.participant.map((p) => (typeof p === 'object' ? p.id : p))
|
||||
: [],
|
||||
},
|
||||
mycalendars: calendars.value,
|
||||
};
|
||||
return {
|
||||
isNonWorking: isWeekend || isHoliday,
|
||||
isWeekendForStyling: isWeekend,
|
||||
isHoliday,
|
||||
};
|
||||
};
|
||||
|
||||
// Открыть диалог создания/редактирования
|
||||
const openEventDialog = async (eventOrInfo = null) => {
|
||||
if (eventOrInfo === null) {
|
||||
selectedEvent.value = getEmptyEventWrapper();
|
||||
showEventDialog.value = true;
|
||||
return;
|
||||
}
|
||||
|
||||
const id = eventOrInfo?.event?.id ?? eventOrInfo?.id;
|
||||
if (!id) {
|
||||
selectedEvent.value = getEmptyEventWrapper();
|
||||
showEventDialog.value = true;
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const { data } = await axiosApiInstance.get(`api/calendar_of_events/my_events/?id=${id}`);
|
||||
selectedEvent.value = data;
|
||||
showEventDialog.value = true;
|
||||
} catch (error) {
|
||||
console.error('Ошибка загрузки события:', error);
|
||||
}
|
||||
const openEventDialog = (event = null) => {
|
||||
selectedEvent.value = event;
|
||||
showEventDialog.value = true;
|
||||
};
|
||||
|
||||
// Закрыть диалог
|
||||
const closeEventDialog = () => {
|
||||
showEventDialog.value = false;
|
||||
selectedEvent.value = null;
|
||||
};
|
||||
|
||||
const openEventView = async (eventId) => {
|
||||
if (!eventId) return;
|
||||
|
||||
try {
|
||||
const { data } = await axiosApiInstance.get(
|
||||
`api/calendar_of_events/my_events/?id=${eventId}`,
|
||||
);
|
||||
selectedEventForView.value = data?.event ? data : { event: data };
|
||||
|
||||
showViewDialog.value = true;
|
||||
} catch (error) {
|
||||
console.error('Ошибка загрузки события:', error);
|
||||
}
|
||||
};
|
||||
|
||||
const closeEventView = () => {
|
||||
showViewDialog.value = false;
|
||||
selectedEventForView.value = null;
|
||||
};
|
||||
|
||||
const handleEventClick = (info) => {
|
||||
const id = info.event?.id ?? info.id;
|
||||
if (id) {
|
||||
openEventView(id);
|
||||
}
|
||||
};
|
||||
|
||||
const editFromView = () => {
|
||||
if (!selectedEventForView.value) return;
|
||||
selectedEvent.value = selectedEventForView.value;
|
||||
showViewDialog.value = false;
|
||||
selectedEventForView.value = null;
|
||||
showEventDialog.value = true;
|
||||
};
|
||||
|
||||
return {
|
||||
// State
|
||||
selectedDate,
|
||||
events,
|
||||
selectedEvent,
|
||||
selectedEventForView,
|
||||
showEventDialog,
|
||||
showViewDialog,
|
||||
currentView,
|
||||
calendars,
|
||||
lastUpdatedBy,
|
||||
@@ -355,9 +262,6 @@ export const useCalendarStore = defineStore('calendarStore', () => {
|
||||
loadCalendars,
|
||||
openEventDialog,
|
||||
closeEventDialog,
|
||||
openEventView,
|
||||
closeEventView,
|
||||
handleEventClick,
|
||||
setSelectedDateFromCalendar,
|
||||
setSelectedDateFromPicker,
|
||||
toggleCalendarVisibility,
|
||||
@@ -365,7 +269,5 @@ export const useCalendarStore = defineStore('calendarStore', () => {
|
||||
isNonWorkingDay,
|
||||
loadDictEmployees,
|
||||
loadEmployees,
|
||||
setSelectedEvent,
|
||||
editFromView,
|
||||
};
|
||||
});
|
||||
Reference in new issue
Block a user