fix [P-304]: адаптация ширины FullCalendar при ресайзе контейнера
This commit is contained in:
1 parent
3c9c244dc7
commit
45922643c0
1 file changed
+232
-325
@@ -72,8 +72,7 @@
|
|||||||
</v-col>
|
</v-col>
|
||||||
</v-row>
|
</v-row>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex-grow-1 d-flex">
|
<div class="flex-grow-1 d-flex" ref="calWrap">
|
||||||
<!-- VCalendar -->
|
|
||||||
<FullCalendar
|
<FullCalendar
|
||||||
v-if="currentView !== 'listAllEvents'"
|
v-if="currentView !== 'listAllEvents'"
|
||||||
ref="calendarRef"
|
ref="calendarRef"
|
||||||
@@ -87,193 +86,153 @@
|
|||||||
</v-card>
|
</v-card>
|
||||||
</v-col>
|
</v-col>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script setup>
|
||||||
import { ref, watch, nextTick, computed } from 'vue';
|
import { ref, computed, watch, nextTick, onMounted, onBeforeUnmount } from 'vue';
|
||||||
import { storeToRefs } from 'pinia';
|
import { storeToRefs } from 'pinia';
|
||||||
|
import { useRoute } from 'vue-router';
|
||||||
|
|
||||||
import dayGridPlugin from '@fullcalendar/daygrid';
|
import dayGridPlugin from '@fullcalendar/daygrid';
|
||||||
import timeGridPlugin from '@fullcalendar/timegrid';
|
import timeGridPlugin from '@fullcalendar/timegrid';
|
||||||
import multiMonthPlugin from '@fullcalendar/multimonth';
|
import multiMonthPlugin from '@fullcalendar/multimonth';
|
||||||
import interactionPlugin from '@fullcalendar/interaction';
|
import interactionPlugin from '@fullcalendar/interaction';
|
||||||
import listPlugin from '@fullcalendar/list';
|
import listPlugin from '@fullcalendar/list';
|
||||||
import ruLocale from '@fullcalendar/core/locales/ru';
|
|
||||||
import rrulePlugin from '@fullcalendar/rrule';
|
import rrulePlugin from '@fullcalendar/rrule';
|
||||||
import { onMounted } from 'vue';
|
import ruLocale from '@fullcalendar/core/locales/ru';
|
||||||
|
|
||||||
import { useCalendarStore } from '@/store/calendarStore';
|
import { useCalendarStore } from '@/store/calendarStore';
|
||||||
import { useRecurrence } from '@/components/calendar_of_events/composables/useReccurrence';
|
|
||||||
import { useAccountStore } from '@/store/AccountStore';
|
import { useAccountStore } from '@/store/AccountStore';
|
||||||
|
import { useRecurrence } from '@/components/calendar_of_events/composables/useReccurrence';
|
||||||
|
import { useEventListFilters } from '../composables/useEventListFilters';
|
||||||
import EventsListView from './EventsListView.vue';
|
import EventsListView from './EventsListView.vue';
|
||||||
import EventListFilters from './EventListFilters.vue';
|
import EventListFilters from './EventListFilters.vue';
|
||||||
import { useEventListFilters } from '../composables/useEventListFilters';
|
|
||||||
import { useRoute } from 'vue-router';
|
|
||||||
|
|
||||||
export default {
|
defineOptions({ name: 'CustomCalendar' });
|
||||||
name: 'CustomCalendar',
|
|
||||||
components: {
|
|
||||||
EventsListView,
|
|
||||||
EventListFilters,
|
|
||||||
},
|
|
||||||
|
|
||||||
props: {
|
const props = defineProps({
|
||||||
forHomePage: { type: Boolean, default: false },
|
forHomePage: { type: Boolean, default: false },
|
||||||
view: { type: String, default: 'dayGridMonth' },
|
view: { type: String, default: 'dayGridMonth' },
|
||||||
},
|
});
|
||||||
|
|
||||||
setup(props) {
|
const calendarStore = useCalendarStore();
|
||||||
const currentView = ref('dayGridMonth');
|
const accountStore = useAccountStore();
|
||||||
const currentTitle = ref('Календарь');
|
const route = useRoute();
|
||||||
const calendarRef = ref(null);
|
const { selectedDate, lastUpdatedBy, allEvents, calendarColorMap } = storeToRefs(calendarStore);
|
||||||
const accountStore = useAccountStore();
|
const { isRecurringEvent, generateRecurringInstances } = useRecurrence();
|
||||||
|
const filters = useEventListFilters();
|
||||||
|
|
||||||
const calendarStore = useCalendarStore();
|
const currentView = ref('dayGridMonth');
|
||||||
const { selectedDate, lastUpdatedBy, allEvents, calendarColorMap } = storeToRefs(calendarStore);
|
const currentTitle = ref('Календарь');
|
||||||
const { isRecurringEvent, generateRecurringInstances } = useRecurrence();
|
const calendarRef = ref(null);
|
||||||
const route = useRoute();
|
const calWrap = ref(null);
|
||||||
|
|
||||||
const calendarApi = computed(() => {
|
const calendarApi = computed(() => calendarRef.value?.getApi?.() || null);
|
||||||
return calendarRef.value?.getApi?.() || null;
|
const unwrappedFilters = computed(() => ({
|
||||||
});
|
|
||||||
|
|
||||||
const filters = useEventListFilters();
|
|
||||||
|
|
||||||
// Создаем развернутую версию фильтров для передачи в EventsListView
|
|
||||||
const unwrappedFilters = computed(() => ({
|
|
||||||
dateRange: filters.dateRange.value,
|
dateRange: filters.dateRange.value,
|
||||||
sortOrder: filters.sortOrder.value,
|
sortOrder: filters.sortOrder.value,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const handleEventClick = (info) => {
|
const weekdayMap = {
|
||||||
calendarStore.handleEventClick(info);
|
воскресенье: 'воскресенье',
|
||||||
};
|
понедельник: 'понедельник',
|
||||||
|
вторник: 'вторник',
|
||||||
|
среда: 'среду',
|
||||||
|
четверг: 'четверг',
|
||||||
|
пятница: 'пятницу',
|
||||||
|
суббота: 'субботу',
|
||||||
|
};
|
||||||
|
|
||||||
const calendarOptions = ref({
|
const formatScheduleTitle = (dateValue) => {
|
||||||
plugins: [
|
const date = new Date(dateValue);
|
||||||
dayGridPlugin,
|
const weekdayRaw = date.toLocaleDateString('ru-RU', { weekday: 'long' });
|
||||||
timeGridPlugin,
|
const weekday = weekdayMap[weekdayRaw] || weekdayRaw;
|
||||||
multiMonthPlugin,
|
const rest = date.toLocaleDateString('ru-RU', { day: 'numeric', month: 'long', year: 'numeric' });
|
||||||
interactionPlugin,
|
return `Расписание на ${weekday}, ${rest}`;
|
||||||
listPlugin,
|
};
|
||||||
rrulePlugin,
|
|
||||||
],
|
const handleDateSelection = (dateStr) => {
|
||||||
initialView: props.forHomePage ? props.view : currentView.value,
|
document
|
||||||
locales: [ruLocale],
|
.querySelectorAll('.fc-day-selected-custom')
|
||||||
locale: 'ru',
|
.forEach((el) => el.classList.remove('fc-day-selected-custom'));
|
||||||
timeZone: 'Europe/Moscow',
|
document
|
||||||
firstDay: 1,
|
.querySelectorAll(`[data-date="${dateStr}"]`)
|
||||||
headerToolbar: false,
|
.forEach((el) => el.classList.add('fc-day-selected-custom'));
|
||||||
height: '80vh',
|
selectedDate.value = dateStr;
|
||||||
aspectRatio: 1.5,
|
};
|
||||||
weekNumbers: true,
|
|
||||||
eventDisplay: 'auto',
|
const updateSelectedDateFromCalendar = () => {
|
||||||
eventTimeFormat: {
|
const currentDate = calendarApi.value?.getDate();
|
||||||
hour: '2-digit',
|
if (currentDate) {
|
||||||
minute: '2-digit',
|
calendarStore.setSelectedDateFromCalendar({
|
||||||
hour12: false,
|
dateStr: currentDate.toISOString().split('T')[0],
|
||||||
meridiem: false,
|
});
|
||||||
},
|
}
|
||||||
weekNumberFormat: {
|
};
|
||||||
week: 'numeric',
|
|
||||||
},
|
const handleEventClick = (info) => calendarStore.handleEventClick(info);
|
||||||
weekNumberCalculation: 'ISO', // ISO стандарт (понедельник - первый день)
|
|
||||||
selectable: true,
|
const handleCalendarDateClick = (info) => {
|
||||||
unselectAuto: false,
|
calendarStore.setSelectedDateFromCalendar(info);
|
||||||
selectMirror: false,
|
currentTitle.value = info.view.title;
|
||||||
dayCellClassNames: (arg) => {
|
if (calendarApi.value) {
|
||||||
const dayInfo = calendarStore.isNonWorkingDay(arg.date);
|
calendarApi.value.gotoDate(info.date);
|
||||||
|
calendarApi.value.changeView('listWeek');
|
||||||
|
currentView.value = 'listWeek';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleToday = () => {
|
||||||
|
calendarApi.value?.today();
|
||||||
|
updateSelectedDateFromCalendar();
|
||||||
|
};
|
||||||
|
const handlePrev = () => {
|
||||||
|
calendarApi.value?.prev();
|
||||||
|
updateSelectedDateFromCalendar();
|
||||||
|
};
|
||||||
|
const handleNext = () => {
|
||||||
|
calendarApi.value?.next();
|
||||||
|
updateSelectedDateFromCalendar();
|
||||||
|
};
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleFiltersUpdate = (newFilters) => {
|
||||||
|
Object.keys(newFilters).forEach((key) => {
|
||||||
|
if (filters[key] !== undefined) filters[key].value = newFilters[key];
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Ресайз контейнера
|
||||||
|
let ro = null;
|
||||||
|
let rafId = null;
|
||||||
|
const updateSize = () => calendarRef.value?.getApi()?.updateSize();
|
||||||
|
const scheduleUpdate = () => {
|
||||||
|
cancelAnimationFrame(rafId);
|
||||||
|
rafId = requestAnimationFrame(updateSize);
|
||||||
|
};
|
||||||
|
|
||||||
|
const dayClassNames = (arg) => {
|
||||||
|
const info = calendarStore.isNonWorkingDay(arg.date);
|
||||||
const classes = [];
|
const classes = [];
|
||||||
if (dayInfo.isHoliday) classes.push('non-working-day');
|
if (info.isHoliday) classes.push('non-working-day');
|
||||||
if (dayInfo.isWeekendForStyling) classes.push('grey-background');
|
if (info.isWeekendForStyling) classes.push('grey-background');
|
||||||
return classes;
|
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: {
|
const buildEvents = (fetchInfo, successCallback) => {
|
||||||
timeGridDay: {
|
|
||||||
type: 'timeGrid',
|
|
||||||
duration: { days: 1 },
|
|
||||||
slotDuration: '01:00:00',
|
|
||||||
slotLabelInterval: '01:00:00',
|
|
||||||
slotLabelFormat: {
|
|
||||||
hour: '2-digit',
|
|
||||||
minute: '2-digit',
|
|
||||||
hour12: false,
|
|
||||||
meridiem: false,
|
|
||||||
},
|
|
||||||
allDaySlot: true,
|
|
||||||
slotMinTime: '07:00:00',
|
|
||||||
slotMaxTime: '22:00:00',
|
|
||||||
expandRows: true,
|
|
||||||
dayHeaderFormat: {
|
|
||||||
weekday: 'long',
|
|
||||||
day: 'numeric',
|
|
||||||
month: 'long',
|
|
||||||
omitCommas: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
timeGridWeek: {
|
|
||||||
type: 'timeGrid',
|
|
||||||
duration: { weeks: 1 },
|
|
||||||
slotDuration: '01:00:00',
|
|
||||||
slotMinTime: '07:00:00',
|
|
||||||
slotMaxTime: '22:00:00',
|
|
||||||
allDaySlot: true,
|
|
||||||
expandRows: true,
|
|
||||||
|
|
||||||
dayHeaderFormat: { weekday: 'short', day: 'numeric' },
|
|
||||||
titleFormat: {
|
|
||||||
day: 'numeric',
|
|
||||||
month: 'long',
|
|
||||||
omitCommas: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
dayGridMonth: {
|
|
||||||
type: 'dayGrid',
|
|
||||||
fixedWeekCount: false,
|
|
||||||
dayHeaderFormat: { weekday: 'short' },
|
|
||||||
weekNumbers: true,
|
|
||||||
|
|
||||||
weekNumberFormat: { week: 'numeric' },
|
|
||||||
weekNumberContent: (arg) => {
|
|
||||||
return arg.num;
|
|
||||||
},
|
|
||||||
weekText: 'Нед.',
|
|
||||||
eventTimeFormat: {
|
|
||||||
hour: '2-digit',
|
|
||||||
minute: '2-digit',
|
|
||||||
hour12: false,
|
|
||||||
omitZeroMinute: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
multiMonthYear: {
|
|
||||||
type: 'multiMonth',
|
|
||||||
duration: { years: 1 },
|
|
||||||
multiMonthMaxColumns: 4,
|
|
||||||
fixedWeekCount: false,
|
|
||||||
weekNumbers: false,
|
|
||||||
},
|
|
||||||
listWeek: {
|
|
||||||
type: 'list',
|
|
||||||
duration: { days: 1 },
|
|
||||||
listDayFormat: {
|
|
||||||
weekday: 'long',
|
|
||||||
day: 'numeric',
|
|
||||||
month: 'long',
|
|
||||||
},
|
|
||||||
listDaySideFormat: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
events: function (fetchInfo, successCallback) {
|
|
||||||
const events = allEvents.value.flatMap((event) => {
|
const events = allEvents.value.flatMap((event) => {
|
||||||
const eventColor = calendarColorMap.value.get(event.calendar) || '#3788d8';
|
const eventColor = calendarColorMap.value.get(event.calendar) || '#3788d8';
|
||||||
const startDate = new Date(event.date_start);
|
|
||||||
const endDate = new Date(event.date_end);
|
|
||||||
const isMultiDay = startDate.toDateString() !== endDate.toDateString();
|
|
||||||
|
|
||||||
if (isRecurringEvent(event)) {
|
if (isRecurringEvent(event)) {
|
||||||
return generateRecurringInstances(event, 52).map((instance) => ({
|
return generateRecurringInstances(event, 52).map((instance) => ({
|
||||||
@@ -290,7 +249,8 @@ export default {
|
|||||||
_userHash: accountStore.user?.id || 'anonymous',
|
_userHash: accountStore.user?.id || 'anonymous',
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
} else {
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
id: event.id,
|
id: event.id,
|
||||||
@@ -311,164 +271,128 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
successCallback(events);
|
successCallback(events);
|
||||||
},
|
};
|
||||||
eventClick: handleEventClick,
|
|
||||||
|
|
||||||
|
const calendarViews = {
|
||||||
|
timeGridDay: {
|
||||||
|
type: 'timeGrid',
|
||||||
|
duration: { days: 1 },
|
||||||
|
slotDuration: '01:00:00',
|
||||||
|
slotLabelInterval: '01:00:00',
|
||||||
|
slotLabelFormat: { hour: '2-digit', minute: '2-digit', hour12: false, meridiem: false },
|
||||||
|
allDaySlot: true,
|
||||||
|
slotMinTime: '07:00:00',
|
||||||
|
slotMaxTime: '22:00:00',
|
||||||
|
expandRows: true,
|
||||||
|
dayHeaderFormat: { weekday: 'long', day: 'numeric', month: 'long', omitCommas: true },
|
||||||
|
},
|
||||||
|
timeGridWeek: {
|
||||||
|
type: 'timeGrid',
|
||||||
|
duration: { weeks: 1 },
|
||||||
|
slotDuration: '01:00:00',
|
||||||
|
slotMinTime: '07:00:00',
|
||||||
|
slotMaxTime: '22:00:00',
|
||||||
|
allDaySlot: true,
|
||||||
|
expandRows: true,
|
||||||
|
dayHeaderFormat: { weekday: 'short', day: 'numeric' },
|
||||||
|
titleFormat: { day: 'numeric', month: 'long', omitCommas: true },
|
||||||
|
},
|
||||||
|
dayGridMonth: {
|
||||||
|
type: 'dayGrid',
|
||||||
|
fixedWeekCount: false,
|
||||||
|
dayHeaderFormat: { weekday: 'short' },
|
||||||
|
weekNumbers: true,
|
||||||
|
weekNumberFormat: { week: 'numeric' },
|
||||||
|
weekNumberContent: (arg) => arg.num,
|
||||||
|
weekText: 'Нед.',
|
||||||
|
eventTimeFormat: { hour: '2-digit', minute: '2-digit', hour12: false, omitZeroMinute: false },
|
||||||
|
},
|
||||||
|
multiMonthYear: {
|
||||||
|
type: 'multiMonth',
|
||||||
|
duration: { years: 1 },
|
||||||
|
multiMonthMaxColumns: 4,
|
||||||
|
fixedWeekCount: false,
|
||||||
|
weekNumbers: false,
|
||||||
|
},
|
||||||
|
listWeek: {
|
||||||
|
type: 'list',
|
||||||
|
duration: { days: 1 },
|
||||||
|
listDayFormat: { weekday: 'long', day: 'numeric', month: 'long' },
|
||||||
|
listDaySideFormat: false,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const calendarOptions = ref({
|
||||||
|
plugins: [
|
||||||
|
dayGridPlugin,
|
||||||
|
timeGridPlugin,
|
||||||
|
multiMonthPlugin,
|
||||||
|
interactionPlugin,
|
||||||
|
listPlugin,
|
||||||
|
rrulePlugin,
|
||||||
|
],
|
||||||
|
initialView: props.forHomePage ? props.view : currentView.value,
|
||||||
|
locales: [ruLocale],
|
||||||
|
locale: 'ru',
|
||||||
|
timeZone: 'Europe/Moscow',
|
||||||
|
firstDay: 1,
|
||||||
|
headerToolbar: false,
|
||||||
|
height: '80vh',
|
||||||
|
aspectRatio: 1.5,
|
||||||
|
weekNumbers: true,
|
||||||
|
eventDisplay: 'auto',
|
||||||
|
eventTimeFormat: { hour: '2-digit', minute: '2-digit', hour12: false, meridiem: false },
|
||||||
|
weekNumberFormat: { week: 'numeric' },
|
||||||
|
weekNumberCalculation: 'ISO',
|
||||||
|
selectable: true,
|
||||||
|
unselectAuto: false,
|
||||||
|
selectMirror: false,
|
||||||
|
dayCellClassNames: dayClassNames,
|
||||||
|
dayHeaderClassNames: dayClassNames,
|
||||||
|
views: calendarViews,
|
||||||
|
events: buildEvents,
|
||||||
|
eventClick: handleEventClick,
|
||||||
dateClick: (info) => {
|
dateClick: (info) => {
|
||||||
calendarStore.setSelectedDateFromCalendar(info);
|
calendarStore.setSelectedDateFromCalendar(info);
|
||||||
handleDateSelection(info.dateStr);
|
handleDateSelection(info.dateStr);
|
||||||
handleCalendarDateClick(info);
|
handleCalendarDateClick(info);
|
||||||
calendarApi.value?.unselect();
|
calendarApi.value?.unselect();
|
||||||
},
|
},
|
||||||
|
|
||||||
datesSet: (info) => {
|
datesSet: (info) => {
|
||||||
if (info.view.type === 'listWeek' && selectedDate.value) {
|
if (info.view.type === 'listWeek' && selectedDate.value) {
|
||||||
currentTitle.value = formatScheduleTitle(selectedDate.value);
|
currentTitle.value = formatScheduleTitle(selectedDate.value);
|
||||||
} else if (info.view.type !== 'listWeek') {
|
} else if (info.view.type !== 'listWeek') {
|
||||||
currentTitle.value = info.view.title;
|
currentTitle.value = info.view.title;
|
||||||
}
|
}
|
||||||
|
if (selectedDate?.value) handleDateSelection(selectedDate.value);
|
||||||
if (selectedDate?.value) {
|
|
||||||
handleDateSelection(selectedDate.value);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleCalendarDateClick = (info) => {
|
/* ──────────── Вотчеры ──────────── */
|
||||||
calendarStore.setSelectedDateFromCalendar(info);
|
watch(currentView, (newView, oldView) => {
|
||||||
currentTitle.value = info.view.title;
|
|
||||||
|
|
||||||
if (calendarApi.value) {
|
|
||||||
calendarApi.value.gotoDate(info.date);
|
|
||||||
calendarApi.value.changeView('listWeek');
|
|
||||||
currentView.value = 'listWeek';
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleToday = () => {
|
|
||||||
calendarApi.value?.today();
|
|
||||||
// Получаем текущую дату из календаря и передаем в стор
|
|
||||||
updateSelectedDateFromCalendar();
|
|
||||||
};
|
|
||||||
|
|
||||||
const handlePrev = () => {
|
|
||||||
calendarApi.value?.prev();
|
|
||||||
updateSelectedDateFromCalendar();
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleNext = () => {
|
|
||||||
calendarApi.value?.next();
|
|
||||||
updateSelectedDateFromCalendar();
|
|
||||||
};
|
|
||||||
|
|
||||||
const updateSelectedDateFromCalendar = () => {
|
|
||||||
const currentDate = calendarApi.value?.getDate();
|
|
||||||
if (currentDate) {
|
|
||||||
const todayInfo = {
|
|
||||||
dateStr: currentDate.toISOString().split('T')[0],
|
|
||||||
};
|
|
||||||
calendarStore.setSelectedDateFromCalendar(todayInfo);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Функция обновления выделения
|
|
||||||
const handleDateSelection = (dateStr) => {
|
|
||||||
// Убираем предыдущее выделение
|
|
||||||
const previousSelected = document.querySelectorAll('.fc-day-selected-custom');
|
|
||||||
previousSelected.forEach((el) => el.classList.remove('fc-day-selected-custom'));
|
|
||||||
|
|
||||||
// Добавляем новое выделение
|
|
||||||
const dayElements = document.querySelectorAll(`[data-date="${dateStr}"]`);
|
|
||||||
dayElements.forEach((el) => el.classList.add('fc-day-selected-custom'));
|
|
||||||
|
|
||||||
selectedDate.value = dateStr;
|
|
||||||
};
|
|
||||||
|
|
||||||
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 && currentView.value !== 'listAllEvents') {
|
|
||||||
calendarApi.value.refetchEvents();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (selectedDate.value && currentView.value !== 'listAllEvents') {
|
|
||||||
handleDateSelection(selectedDate.value);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
watch(currentView, (newView) => {
|
|
||||||
applyView(newView);
|
applyView(newView);
|
||||||
});
|
if (oldView === 'listAllEvents' && newView !== 'listAllEvents') filters.resetFilters();
|
||||||
|
});
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
[() => calendarStore.calendars, () => calendarStore.hiddenCalendarIds],
|
[() => calendarStore.calendars, () => calendarStore.hiddenCalendarIds],
|
||||||
() => {
|
() => {
|
||||||
// При изменении событий перезагружаем календарь
|
if (currentView.value !== 'listAllEvents') calendarApi.value?.refetchEvents();
|
||||||
if (currentView.value === 'listAllEvents') return;
|
|
||||||
calendarApi.value?.refetchEvents();
|
|
||||||
},
|
},
|
||||||
{ deep: true },
|
{ deep: true },
|
||||||
);
|
);
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
calendarColorMap,
|
calendarColorMap,
|
||||||
() => {
|
() => {
|
||||||
if (currentView.value === 'listAllEvents') return;
|
if (currentView.value !== 'listAllEvents') calendarApi.value?.refetchEvents();
|
||||||
calendarApi.value?.refetchEvents();
|
|
||||||
},
|
},
|
||||||
{ deep: true },
|
{ deep: true },
|
||||||
);
|
);
|
||||||
|
|
||||||
watch(selectedDate, (newDate) => {
|
watch(selectedDate, (newDate) => {
|
||||||
if (newDate && calendarApi.value && lastUpdatedBy.value !== 'calendar') {
|
if (newDate && calendarApi.value && lastUpdatedBy.value !== 'calendar') {
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
calendarApi.value.gotoDate(newDate);
|
calendarApi.value.gotoDate(newDate);
|
||||||
@@ -478,42 +402,25 @@ export default {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleFiltersUpdate = (newFilters) => {
|
onMounted(async () => {
|
||||||
Object.keys(newFilters).forEach((key) => {
|
ro = new ResizeObserver(scheduleUpdate);
|
||||||
if (filters[key] !== undefined) {
|
if (calWrap.value) ro.observe(calWrap.value);
|
||||||
filters[key].value = newFilters[key];
|
|
||||||
|
calendarStore.fetchHolidays(new Date().getFullYear());
|
||||||
|
await nextTick();
|
||||||
|
|
||||||
|
if (currentView.value !== 'listAllEvents') {
|
||||||
|
if (calendarApi.value) calendarApi.value.refetchEvents();
|
||||||
|
if (selectedDate.value) handleDateSelection(selectedDate.value);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
|
||||||
|
|
||||||
// Сброс фильтров при выходе из кастомного вида
|
onBeforeUnmount(() => {
|
||||||
watch(currentView, (newView, oldView) => {
|
cancelAnimationFrame(rafId);
|
||||||
if (oldView === 'listAllEvents' && newView !== 'listAllEvents') {
|
ro?.disconnect();
|
||||||
filters.resetFilters();
|
});
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
currentTitle,
|
|
||||||
calendarRef,
|
|
||||||
calendarApi,
|
|
||||||
currentView,
|
|
||||||
calendarOptions,
|
|
||||||
handleToday,
|
|
||||||
handleNext,
|
|
||||||
handlePrev,
|
|
||||||
handleCalendarDateClick,
|
|
||||||
handleDateSelection,
|
|
||||||
handleEventClick,
|
|
||||||
calendarStore,
|
|
||||||
filters,
|
|
||||||
handleFiltersUpdate,
|
|
||||||
unwrappedFilters,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
<style scoped>
|
<style scoped>
|
||||||
:deep(.fc-daygrid-day-number) {
|
:deep(.fc-daygrid-day-number) {
|
||||||
|
|||||||
Reference in new issue
Block a user