fix [P-290]: просмотр всех событий
This commit is contained in:
1 parent
1ea87f85cd
commit
77244f2d06
4 files changed
+457
-30
No files matched your search
@@ -7,7 +7,6 @@
|
||||
<v-row no-gutters class="mb-1" align="center" justify="space-between">
|
||||
<v-col md="4" class="flex-grow-0 d-flex align-center">
|
||||
<v-btn
|
||||
v-show="!forHomePage"
|
||||
variant="outlined"
|
||||
class="text-subtitle-2 mr-2"
|
||||
@click="handleToday"
|
||||
@@ -36,17 +35,13 @@
|
||||
>
|
||||
<v-icon size="large">mdi-chevron-right</v-icon>
|
||||
</v-btn>
|
||||
<span v-if="!forHomePage" class="text-h6 text-no-wrap ml-2">
|
||||
{{ currentTitle }}
|
||||
</span>
|
||||
<span v-else class="text-caption text-no-wrap ml-2">
|
||||
<span class="text-h6 text-no-wrap ml-2">
|
||||
{{ currentTitle }}
|
||||
</span>
|
||||
</v-col>
|
||||
|
||||
<v-col class="flex-grow-0 d-flex justify-end">
|
||||
<v-btn-toggle
|
||||
v-show="!forHomePage"
|
||||
v-model="currentView"
|
||||
mandatory
|
||||
divided
|
||||
@@ -58,13 +53,21 @@
|
||||
<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-toggle>
|
||||
</v-col>
|
||||
</v-row>
|
||||
</div>
|
||||
<div class="flex-grow-1 d-flex">
|
||||
<!-- VCalendar -->
|
||||
<FullCalendar ref="calendarRef" :options="calendarOptions" class="custom-calendar" />
|
||||
<FullCalendar
|
||||
v-if="currentView !== 'listAllEvents'"
|
||||
ref="calendarRef"
|
||||
:options="calendarOptions"
|
||||
class="custom-calendar"
|
||||
/>
|
||||
<!-- Кастомный список событий -->
|
||||
<EventsListView v-else @event-click="handleEventClick" />
|
||||
</div>
|
||||
</v-card-text>
|
||||
</v-card>
|
||||
@@ -84,6 +87,7 @@ import { onMounted } from 'vue';
|
||||
import { useCalendarStore } from '@/store/calendarStore';
|
||||
import { useRecurrence } from '@/components/calendar_of_events/composables/useReccurrence';
|
||||
import { useAccountStore } from '@/store/AccountStore';
|
||||
import EventsListView from './EventsListView.vue';
|
||||
|
||||
export default {
|
||||
name: 'CustomCalendar',
|
||||
@@ -92,12 +96,11 @@ export default {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
forHomePage: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
},
|
||||
emits: ['openEventDialog', 'openEventView'],
|
||||
components: {
|
||||
EventsListView,
|
||||
},
|
||||
setup(props, { emit }) {
|
||||
const currentView = ref('dayGridMonth');
|
||||
const currentTitle = ref('Календарь');
|
||||
@@ -403,9 +406,25 @@ export default {
|
||||
}
|
||||
});
|
||||
|
||||
watch(currentView, (newView) => {
|
||||
if (calendarApi.value) {
|
||||
calendarApi.value.changeView(newView);
|
||||
// Обработчик переключения видов
|
||||
watch(currentView, async (newView, oldView) => {
|
||||
if (newView === 'listAllEvents') {
|
||||
// Переход в кастомный список
|
||||
currentTitle.value = 'Все события';
|
||||
} else {
|
||||
await nextTick(); // Ждем перерендера FullCalendar
|
||||
// Переход обратно в FullCalendar
|
||||
if (calendarApi.value) {
|
||||
calendarApi.value.changeView(newView);
|
||||
currentTitle.value = calendarApi.value.view.title;
|
||||
|
||||
// Принудительно перерисовываем события при возврате из кастомного списка
|
||||
if (oldView === 'listAllEvents') {
|
||||
await nextTick();
|
||||
calendarApi.value.refetchEvents();
|
||||
updateCalendarEvents(); // Вызываем функцию рендера событий
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,297 @@
|
||||
<template>
|
||||
<div class="list-all-events d-flex flex-column" style="height: 100%">
|
||||
<!-- Фильтры - растянуты на всю ширину -->
|
||||
<div class="filters pa-6 flex-grow-0">
|
||||
<v-row class="flex-nowrap" style="gap: 16px">
|
||||
<v-col class="flex-grow-1 pa-0">
|
||||
<v-select
|
||||
v-model="selectedCalendar"
|
||||
:items="calendarOptions"
|
||||
density="compact"
|
||||
label="Календарь"
|
||||
variant="outlined"
|
||||
hide-details
|
||||
class="w-100"
|
||||
/>
|
||||
</v-col>
|
||||
</v-row>
|
||||
</div>
|
||||
|
||||
<!-- Статистика -->
|
||||
<div class="px-3 pb-2 text-body-2 text-medium-emphasis flex-grow-0">
|
||||
Найдено событий: {{ filteredEvents.length }}
|
||||
</div>
|
||||
|
||||
<!-- Список событий - растянут на всю оставшуюся высоту -->
|
||||
<div class="events-list flex-grow-1" style="overflow-y: auto">
|
||||
<div
|
||||
v-for="event in filteredEvents"
|
||||
:key="event.id"
|
||||
class="event-item pa-3 mb-3"
|
||||
:style="{ borderLeft: `4px solid ${getEventColor(event)}` }"
|
||||
@click="handleItemClick(event)"
|
||||
style="cursor: pointer; border-bottom: 1px solid #e0e0e0; width: 100%"
|
||||
>
|
||||
<div class="event-date text-subtitle-2 pb-3">
|
||||
{{ formatEventDate(event) }}
|
||||
</div>
|
||||
|
||||
<div class="event-content">
|
||||
<div class="event-title d-flex align-center">
|
||||
<span class="font-weight-medium">{{ event.name }}</span>
|
||||
<v-chip
|
||||
v-if="isRecurringEvent(event)"
|
||||
:prepend-icon="getRecurrenceIcon(event.period)"
|
||||
size="x-small"
|
||||
color="primary"
|
||||
class="ml-2"
|
||||
variant="outlined"
|
||||
>
|
||||
{{ getRecurrenceText(event) }}
|
||||
</v-chip>
|
||||
</div>
|
||||
|
||||
<div class="event-meta text-subtitle-2 text-medium-emphasis">
|
||||
<span class="calendar-badge" :style="{ color: getEventColor(event) }">
|
||||
{{ getCalendarName(event.calendar) }}
|
||||
</span>
|
||||
•
|
||||
{{ formatEventTime(event) }}
|
||||
•
|
||||
{{ formatDuration(event) }}
|
||||
|
||||
<span v-if="isRecurringEvent(event)" class="ml-1">
|
||||
• {{ getRecurrenceDetails(event) }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div v-if="event.description" class="event-description text-subtitle-1 mt-1">
|
||||
{{ truncateDescription(event.description) }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="filteredEvents.length === 0" class="text-center pa-8 text-medium-emphasis">
|
||||
{{ getEmptyStateMessage() }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, computed } from 'vue';
|
||||
import { useCalendarStore } from '@/store/calendarStore';
|
||||
import { RRule } from 'rrule';
|
||||
import { useRecurrence } from '@/components/calendar_of_events/composables/useReccurrence.js';
|
||||
|
||||
const { isRecurringEvent, formatRecurrenceText, getRecurrenceIcon } = useRecurrence();
|
||||
|
||||
const calendarStore = useCalendarStore();
|
||||
|
||||
const emit = defineEmits(['event-click']);
|
||||
|
||||
// Локальное состояние для фильтров
|
||||
const searchQuery = ref('');
|
||||
const selectedCalendar = ref(null);
|
||||
|
||||
// Подготовка данных
|
||||
const flattenedEvents = computed(() => {
|
||||
return calendarStore.allEvents
|
||||
.map((event) => ({
|
||||
...event,
|
||||
startDate: new Date(event.date_start),
|
||||
endDate: new Date(event.date_end),
|
||||
}))
|
||||
.sort((a, b) => a.startDate - b.startDate);
|
||||
});
|
||||
|
||||
// Опции для селекта календарей
|
||||
const calendarOptions = computed(() => [
|
||||
{ title: 'Все календари', value: null },
|
||||
...calendarStore.calendars
|
||||
.filter((calendar) => !calendarStore.hiddenCalendarIds.includes(calendar.id))
|
||||
.map((calendar) => ({
|
||||
title: calendar.cl_name,
|
||||
value: calendar.id,
|
||||
})),
|
||||
]);
|
||||
|
||||
// Фильтрация событий
|
||||
const filteredEvents = computed(() => {
|
||||
let filtered = flattenedEvents.value;
|
||||
|
||||
// Поиск по названию и описанию
|
||||
if (searchQuery.value) {
|
||||
const query = searchQuery.value.toLowerCase();
|
||||
filtered = filtered.filter(
|
||||
(event) =>
|
||||
event.name.toLowerCase().includes(query) ||
|
||||
event.description?.toLowerCase().includes(query),
|
||||
);
|
||||
}
|
||||
|
||||
// Фильтр по календарю
|
||||
if (selectedCalendar.value) {
|
||||
filtered = filtered.filter((event) => event.calendar === selectedCalendar.value);
|
||||
}
|
||||
|
||||
return filtered;
|
||||
});
|
||||
|
||||
// Вспомогательные функции
|
||||
const getEventColor = (event) => {
|
||||
return calendarStore.calendarColorMap.get(event.calendar) || '#3788d8';
|
||||
};
|
||||
|
||||
const getCalendarName = (calendarId) => {
|
||||
const calendar = calendarStore.calendars.find((c) => c.id === calendarId);
|
||||
return calendar?.cl_name || 'Неизвестно';
|
||||
};
|
||||
|
||||
const formatEventDate = (event) => {
|
||||
const start = event.startDate;
|
||||
const end = event.endDate;
|
||||
|
||||
// Если событие в один день
|
||||
if (start.toDateString() === end.toDateString()) {
|
||||
return start.toLocaleDateString('ru-RU', {
|
||||
day: 'numeric',
|
||||
month: 'long',
|
||||
year: 'numeric',
|
||||
weekday: 'short',
|
||||
});
|
||||
}
|
||||
|
||||
// Если событие跨天 (диапазон)
|
||||
const startFormatted = start.toLocaleDateString('ru-RU', {
|
||||
day: 'numeric',
|
||||
month: 'long',
|
||||
weekday: 'short',
|
||||
});
|
||||
|
||||
const endFormatted = end.toLocaleDateString('ru-RU', {
|
||||
day: 'numeric',
|
||||
month: 'long',
|
||||
year: 'numeric',
|
||||
weekday: 'short',
|
||||
});
|
||||
|
||||
return `${startFormatted} – ${endFormatted}`;
|
||||
};
|
||||
|
||||
const formatEventTime = (event) => {
|
||||
if (event.allday) return 'Весь день';
|
||||
|
||||
const start = event.startDate.toLocaleTimeString('ru-RU', {
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
});
|
||||
|
||||
const end = event.endDate.toLocaleTimeString('ru-RU', {
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
});
|
||||
|
||||
return `${start} - ${end}`;
|
||||
};
|
||||
|
||||
const formatDuration = (event) => {
|
||||
const diff = event.endDate - event.startDate;
|
||||
const hours = Math.floor(diff / (1000 * 60 * 60));
|
||||
const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60));
|
||||
|
||||
if (hours === 0) return `${minutes} мин`;
|
||||
if (minutes === 0) return `${hours} ч`;
|
||||
return `${hours} ч ${minutes} мин`;
|
||||
};
|
||||
|
||||
const truncateDescription = (desc) => {
|
||||
if (!desc) return '';
|
||||
return desc.length > 150 ? desc.substring(0, 150) + '...' : desc;
|
||||
};
|
||||
|
||||
const getEmptyStateMessage = () => {
|
||||
if (searchQuery.value) {
|
||||
return 'События по вашему запросу не найдены';
|
||||
}
|
||||
if (selectedCalendar.value) {
|
||||
return 'В выбранном календаре нет событий';
|
||||
}
|
||||
return 'Нет событий для отображения';
|
||||
};
|
||||
|
||||
// Получаем текст повторения
|
||||
const getRecurrenceText = (event) => {
|
||||
return formatRecurrenceText(event.period, event.date_start) || '';
|
||||
};
|
||||
|
||||
// Дополнительные детали о повторении
|
||||
const getRecurrenceDetails = (event) => {
|
||||
if (!isRecurringEvent(event)) return '';
|
||||
|
||||
try {
|
||||
let rrule;
|
||||
|
||||
if (event.period.includes('RRULE:')) {
|
||||
rrule = RRule.fromString(event.period);
|
||||
} else {
|
||||
const periodData = JSON.parse(event.period);
|
||||
if (periodData?.origOptions) {
|
||||
rrule = new RRule(periodData.origOptions);
|
||||
}
|
||||
}
|
||||
|
||||
if (!rrule || !rrule.origOptions.until) return '';
|
||||
|
||||
const untilDate = new Date(rrule.origOptions.until);
|
||||
return `до ${untilDate.toLocaleDateString('ru-RU')}`;
|
||||
} catch (error) {
|
||||
return '';
|
||||
}
|
||||
};
|
||||
|
||||
const handleItemClick = (event) => {
|
||||
// Создаем объект похожий на FullCalendar info
|
||||
const eventInfo = {
|
||||
event: {
|
||||
id: event.id,
|
||||
},
|
||||
};
|
||||
emit('event-click', eventInfo);
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.list-all-events {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.filters {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.events-list {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.event-item {
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.event-item:hover {
|
||||
background-color: #f5f5f5;
|
||||
transition: background-color 0.2s;
|
||||
}
|
||||
|
||||
/* Убедимся, что все элементы занимают всю ширину */
|
||||
.v-col.pa-0 {
|
||||
min-width: 0; /* Для правильного flexbox поведения */
|
||||
}
|
||||
|
||||
.v-text-field,
|
||||
.v-select {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
@@ -26,6 +26,7 @@
|
||||
hide-header
|
||||
show-adjacent-months
|
||||
@update:modelValue="handleDateClick"
|
||||
@update:display="currentDisplay = $event"
|
||||
>
|
||||
</v-date-picker>
|
||||
</v-locale-provider>
|
||||
@@ -55,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 } from 'vue';
|
||||
import { onMounted, watch, nextTick, ref } from 'vue';
|
||||
import { storeToRefs } from 'pinia';
|
||||
|
||||
export default {
|
||||
@@ -69,6 +70,8 @@ export default {
|
||||
|
||||
const { user } = storeToRefs(accountStore);
|
||||
|
||||
const currentDisplay = ref(null);
|
||||
|
||||
const handleDateClick = (date) => {
|
||||
calendarStore.setSelectedDateFromPicker(date);
|
||||
setTimeout(updateCalendarDays, 200);
|
||||
@@ -95,18 +98,6 @@ export default {
|
||||
}
|
||||
});
|
||||
|
||||
watch(selectedDate, () => {
|
||||
updateCalendarDays();
|
||||
});
|
||||
|
||||
watch(
|
||||
[myCalendars, subscribedCalendars],
|
||||
() => {
|
||||
updateCalendarDays();
|
||||
},
|
||||
{ deep: true },
|
||||
);
|
||||
|
||||
// Функция для добавления классов дням
|
||||
const updateCalendarDays = () => {
|
||||
nextTick(() => {
|
||||
@@ -119,8 +110,6 @@ export default {
|
||||
|
||||
if (ariaLabel) {
|
||||
try {
|
||||
// Парсим дату из aria-label "воскресенье, 28 сентября 2025 г."
|
||||
|
||||
const dayDate = parseDateFromAriaLabel(ariaLabel);
|
||||
if (dayDate) {
|
||||
const dayInfo = calendarStore.isNonWorkingDay(dayDate);
|
||||
@@ -141,7 +130,7 @@ export default {
|
||||
}
|
||||
}
|
||||
});
|
||||
}, 100);
|
||||
}, 50);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -183,6 +172,39 @@ export default {
|
||||
}
|
||||
};
|
||||
|
||||
watch(
|
||||
[selectedDate, currentDisplay],
|
||||
() => {
|
||||
updateCalendarDays();
|
||||
},
|
||||
{ deep: true, immediate: true },
|
||||
);
|
||||
|
||||
watch(
|
||||
[myCalendars, subscribedCalendars],
|
||||
() => {
|
||||
updateCalendarDays();
|
||||
},
|
||||
{ deep: true },
|
||||
);
|
||||
|
||||
// При смене месяца через кнопки навигации
|
||||
const observer = new MutationObserver((mutations) => {
|
||||
mutations.forEach((mutation) => {
|
||||
if (mutation.type === 'childList') {
|
||||
updateCalendarDays();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
// Наблюдаем за изменениями в DOM date-picker
|
||||
const datePicker = document.querySelector('.minCal');
|
||||
if (datePicker) {
|
||||
observer.observe(datePicker, { childList: true, subtree: true });
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
accountStore,
|
||||
user,
|
||||
@@ -193,6 +215,7 @@ export default {
|
||||
loadCalendars,
|
||||
handleDateClick,
|
||||
updateCalendarDays,
|
||||
currentDisplay,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
@@ -87,9 +87,97 @@ export function useRecurrence() {
|
||||
}
|
||||
};
|
||||
|
||||
const formatRecurrenceText = (periodString, eventDateStart) => {
|
||||
if (!periodString || periodString === 'null') return null;
|
||||
|
||||
try {
|
||||
let interval = 1;
|
||||
|
||||
if (periodString.includes('RRULE:')) {
|
||||
// Парсим RRULE строку чтобы достать FREQ и INTERVAL
|
||||
const rrulePart = periodString.split('RRULE:')[1];
|
||||
if (rrulePart) {
|
||||
const params = rrulePart.split(';');
|
||||
|
||||
// Достаем FREQ
|
||||
const freqParam = params.find((p) => p.startsWith('FREQ='));
|
||||
const freq = freqParam ? freqParam.split('=')[1] : '';
|
||||
|
||||
// Достаем INTERVAL
|
||||
const intervalParam = params.find((p) => p.startsWith('INTERVAL='));
|
||||
interval = intervalParam ? parseInt(intervalParam.split('=')[1]) : 1;
|
||||
|
||||
// Форматируем по частоте
|
||||
switch (freq) {
|
||||
case 'DAILY':
|
||||
return interval === 1 ? 'Ежедневно' : `Каждый ${interval} день`;
|
||||
case 'WEEKLY':
|
||||
return interval === 1 ? 'Еженедельно' : `Каждую ${interval} неделю`;
|
||||
case 'MONTHLY':
|
||||
return interval === 1
|
||||
? 'Каждый месяц'
|
||||
: interval === 3
|
||||
? 'Ежеквартально'
|
||||
: `Каждый ${interval} месяц`;
|
||||
case 'YEARLY':
|
||||
return interval === 1 ? 'Ежегодно' : `Каждый ${interval} год`;
|
||||
default:
|
||||
return 'Повторяется';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 'Повторяется';
|
||||
} catch (error) {
|
||||
console.error('Error formatting recurrence:', error);
|
||||
return 'Повторяется';
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Получает иконку для типа повторения
|
||||
*/
|
||||
const getRecurrenceIcon = (periodString) => {
|
||||
if (!periodString) return 'mdi-repeat';
|
||||
|
||||
try {
|
||||
let rrule;
|
||||
|
||||
if (periodString.includes('RRULE:')) {
|
||||
rrule = RRule.fromString(periodString);
|
||||
} else {
|
||||
const periodData = JSON.parse(periodString);
|
||||
if (periodData?.origOptions) {
|
||||
rrule = new RRule(periodData.origOptions);
|
||||
}
|
||||
}
|
||||
|
||||
if (!rrule) return 'mdi-repeat';
|
||||
|
||||
const options = rrule.origOptions;
|
||||
|
||||
switch (options.freq) {
|
||||
case RRule.DAILY:
|
||||
return 'mdi-calendar-today';
|
||||
case RRule.WEEKLY:
|
||||
return 'mdi-calendar-week';
|
||||
case RRule.MONTHLY:
|
||||
return 'mdi-calendar-month';
|
||||
case RRule.YEARLY:
|
||||
return 'mdi-calendar-star';
|
||||
default:
|
||||
return 'mdi-repeat';
|
||||
}
|
||||
} catch (error) {
|
||||
return 'mdi-repeat';
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
isRecurringEvent,
|
||||
generateRecurringInstances,
|
||||
parseRecurrenceOptions,
|
||||
formatRecurrenceText,
|
||||
getRecurrenceIcon,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user