fix [P-47]: фикс событий

This commit is contained in:
Inna committed 2025-09-30 12:07:58 +03:00
1 parent b56f5e3a27
commit b0b619288c
6 files changed
+111 -93

No files matched your search

@@ -102,7 +102,7 @@ export default {
const currentTitle = ref('Календарь');
const calendarStore = useCalendarStore();
const { selectedDate, lastUpdatedBy, allEvents } = storeToRefs(calendarStore);
const { selectedDate, lastUpdatedBy, allEvents, calendarColorMap } = storeToRefs(calendarStore);
const { parseRecurrenceOptions, isRecurringEvent } = useRecurrence();
const handleEventClick = (info) => {
@@ -314,6 +314,14 @@ export default {
selectedDate.value = dateStr;
};
// const calendarColorMap = computed(() => {
// const map = new Map();
// calendarStore.myCalendars.forEach((calendar) => {
// map.set(calendar.id, calendar.cl_color);
// });
// return map;
// });
// Обновление событий в календаре
const updateCalendarEvents = () => {
if (calendarRef.value) {
@@ -332,8 +340,8 @@ export default {
end: new Date(event.date_end),
allDay: event.all_day,
textColor: '#ffffff',
// backgroundColor: eventColor,
// borderColor: eventColor,
backgroundColor: eventColor,
borderColor: eventColor,
};
if (!rruleOptions) {
@@ -355,14 +363,6 @@ export default {
}
};
const calendarColorMap = computed(() => {
const map = new Map();
calendarStore.myCalendars.forEach((calendar) => {
map.set(calendar.id, calendar.cl_color);
});
return map;
});
onMounted(() => {
nextTick(() => {
if (calendarRef.value && calendarRef.value.getApi) {
@@ -397,11 +397,13 @@ export default {
});
watch(
allEvents,
(newEvents) => {
updateCalendarEvents();
[allEvents],
([newEvents]) => {
if (newEvents.length > 0) {
updateCalendarEvents();
}
},
{ deep: true },
{ deep: true, immediate: true },
);
watch(
@@ -427,7 +429,6 @@ export default {
handleDateSelection,
updateCalendarEvents,
handleEventClick,
calendarColorMap,
calendarStore,
};
},
@@ -540,24 +541,4 @@ export default {
:deep(.fc-day.grey-background) {
background-color: #f5f5f5 !important;
}
/* :deep(.fc-daygrid-day-frame) {
position: relative;
min-height: 50px;
}
:deep(.fc-daygrid-more-link) {
position: absolute;
bottom: -6px;
right: 2px;
font-size: 11px;
padding: 1px 3px;
background: rgba(0, 0, 0, 0.05);
border-radius: 3px;
z-index: 3;
}
:deep(.fc-popover) {
} */
</style>
@@ -37,6 +37,8 @@
}"
@click="onDateClick(day.date)"
>
<div class="day-content">
<span class="day-number">{{ day.day }}</span>
<div class="day-events">
@@ -58,9 +60,6 @@
<v-col cols="5" class="pl-2">
<div class="schedule-header">
<h3 class="day-title">Сегодня, {{ formattedSelectedDate }}</h3>
<!-- <v-chip size="small" color="primary" variant="outlined" v-if="isToday(selectedDate)">
Сегодня
</v-chip> -->
</div>
<v-card variant="outlined" class="day-schedule" elevation="0">
@@ -72,7 +71,10 @@
:class="{ 'current-event': isCurrentEvent(event) }"
>
<template #prepend>
<v-icon :color="event.color" size="small" class="mr-2"> mdi-circle-small </v-icon>
<div
class="event-color-indicator"
:style="{ backgroundColor: event.color }"
></div>
</template>
<v-list-item-title class="event-time">
@@ -97,7 +99,7 @@
</template>
<script>
import { ref, computed, onMounted } from 'vue';
import { ref, computed, onMounted, watch } from 'vue';
import { storeToRefs } from 'pinia';
import { useCalendarStore } from '@/store/calendarStore';
@@ -112,7 +114,7 @@ export default {
// Работа с хранилищем
const calendarStore = useCalendarStore();
const { allEvents } = storeToRefs(calendarStore);
const { allEvents, calendarColorMap } = storeToRefs(calendarStore);
// Утилиты для работы с датами (главный источник проблем!)
const formatToLocalDate = (date) => {
@@ -135,13 +137,15 @@ export default {
// Преобразование событий с защитой от ошибок
const events = computed(() => {
const userEvents = allEvents.value.map((event) => {
const eventColor = calendarColorMap.value.get(event.calendar) || event.color || '#1976d2';
return {
id: event.id,
title: event.name || event.title || 'Без названия',
start: event.date_start || event.start,
end: event.date_end || event.end,
description: event.description,
color: event.color || '#1976d2',
color: eventColor || '#1976d2',
calendar: event.calendar,
isHoliday: false,
};
});
@@ -278,6 +282,14 @@ export default {
calendarStore.fetchHolidays(currentYear);
});
watch(
calendarColorMap,
(newMap) => {
newMap.value;
},
{ deep: true },
);
return {
// Реактивные данные
currentDate,
@@ -353,7 +365,7 @@ export default {
color: #666;
text-align: center;
padding: 8px 4px;
border-bottom: 1px solid #e0e0e0;
border-bottom: 1px solid #afadad;
}
.day-cell {
@@ -383,7 +395,7 @@ export default {
}
.day-cell.selected {
background-color: #00897B;
background-color: #00897b;
color: white;
}
@@ -419,6 +431,15 @@ export default {
display: block;
}
.event-color-indicator {
width: 10px;
height: 10px;
border-radius: 50%;
margin-right: 12px;
flex-shrink: 0;
box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1);
}
/* Дневное расписание */
.schedule-header {
display: flex;
@@ -446,7 +467,7 @@ export default {
min-height: 48px;
padding: 8px 12px;
border-left: 4px solid transparent;
border-bottom: 1px solid #f5f5f5;
border-bottom: 1px solid #d3cecede;
}
.schedule-item:last-child {
@@ -461,16 +482,16 @@ export default {
.event-time {
font-size: 0.8rem;
font-weight: 600;
color: #666;
color: #302f2f;
margin-bottom: 2px;
}
.event-title {
font-size: 0.85rem;
font-size: 0.9rem;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
color: #333;
color: #1b1b1b;
}
.no-events {
@@ -125,7 +125,6 @@ export default {
new Date(propsDateEvent.value).getMinutes(),
).padStart(2, '0')}`;
},
set(newValue) {
createdDate(modelDate.value, newValue);
},
@@ -137,28 +136,21 @@ export default {
newDate.setHours(hours, minutes, 0, 0);
if (props.order[0] == 4) {
// Для окончания: проверяем чтобы не было раньше начала
const startDate = new Date(props.limitation);
if (newDate <= startDate) {
const correctedDate = new Date(startDate);
correctedDate.setHours(startDate.getHours() + 1);
propsDateEvent.value = newDate;
propsDateEvent.value = correctedDate;
} else {
propsDateEvent.value = newDate;
}
// propsDateEvent.value = newDate >= startDate ? newDate : startDate;
} else {
// Для начала: просто устанавливаем дату
propsDateEvent.value = newDate;
// Автоматически двигаем окончание, если оно стало раньше начала
const currentEnd = new Date(props.limitation);
if (newDate > currentEnd) {
// Ставим окончание на 1 час позже нового начала
const newEnd = new Date(newDate);
newEnd.setHours(newDate.getHours() + 1);
emit('adjustEndDate', newEnd.toISOString()); // Новый emit
emit('adjustEndDate', newEnd.toISOString());
}
}
@@ -148,7 +148,7 @@
<v-row
no-gutters
class="align-start d-flex pt-3 mb-3"
style=" height:auto; min-height: 200px; max-height: 400px"
style="height: auto; min-height: 200px; max-height: 400px"
>
<v-col class="text-body-2 text-text_grey pb-5 pt-3" lg="2"> Файлы </v-col>
@@ -329,25 +329,44 @@ export default {
const isCalendarsReady = computed(() => safeCalendars.value.length > 0);
// Автовыбор при появлении данных
watch(isCalendarsReady, (ready) => {
if (ready && !myCalendar.value && safeCalendars.value[0]) {
myCalendar.value = safeCalendars.value[0];
}
// Computed для календаря события
const eventCalendar = computed(() => {
if (!propsEvent.value?.event?.calendar || !safeCalendars.value.length) return null;
return safeCalendars.value.find((cal) => cal.id === propsEvent.value.event.calendar);
});
watch(
() => propsEvent.value,
(newEvent) => {
if (!newEvent || !safeCalendars.value.length) return;
// Единоразовая инициализация при монтировании/получении данных
const initializeCalendar = () => {
if (myCalendar.value) return; // Уже инициализирован
// РЕДАКТИРОВАНИЕ - календарь из события
const eventCalendar = safeCalendars.value.find((cal) => cal.id === newEvent.event.calendar);
myCalendar.value = eventCalendar || safeCalendars.value[0];
// Приоритет 1: календарь из события (редактирование)
if (eventCalendar.value) {
myCalendar.value = eventCalendar.value;
return;
}
// Приоритет 2: первый доступный календарь (создание)
if (safeCalendars.value.length > 0) {
myCalendar.value = safeCalendars.value[0];
}
};
// Инициализируем когда все готово
watch(
[() => safeCalendars.value.length, () => propsEvent.value],
() => {
initializeCalendar();
},
{ immediate: true, deep: true },
{ immediate: true },
);
// Дополнительная защита - вотчер только на смену самого календаря
watch(eventCalendar, (newCalendar) => {
if (newCalendar && newCalendar.id !== myCalendar.value?.id) {
myCalendar.value = newCalendar;
}
});
const staff = ref([]);
axiosApiInstance.get('api/calendar_of_events/get_employees/').then((res) => {
@@ -611,6 +630,7 @@ export default {
handleAutoAdjustEnd,
newFiles,
handleFilesUpdate,
initializeCalendar,
};
},
};
+17 -13
View File
@@ -118,6 +118,14 @@ export const useCalendarStore = defineStore('calendarStore', () => {
calendars.value.filter((calendar) => !hiddenCalendarIds.value.includes(calendar.id)),
);
const calendarColorMap = computed(() => {
const map = new Map();
myCalendars.value.forEach((calendar) => {
map.set(calendar.id, calendar.cl_color);
});
return map;
});
const allEvents = computed(() => {
return calendars.value
.filter((calendar) => !hiddenCalendarIds.value.includes(calendar.id))
@@ -130,25 +138,20 @@ export const useCalendarStore = defineStore('calendarStore', () => {
});
const editableEvents = computed(() => {
const calendarsMap = new Map(myCalendars.value.map((cal) => [cal.id, cal]));
const currentUserId = accountStore.user.is_idEmployee;
return allEvents.value.filter((event) => {
const calendar = myCalendars.value.find((cal) => cal.id == event.calendar);
if (!calendar) return false;
// Пользователь - автор календаря
if (calendar.author == accountStore.user.is_idEmployee) return true;
// Ищем участника с правами редактора
const participant = calendar.participant.find(
(p) => p.participant_calendar == accountStore.user.is_idEmployee,
);
return participant?.editor === true;
const calendar = calendarsMap.get(event.calendar);
// Автор календаря
if (calendar?.author == currentUserId) return true;
// Участник события
return event.participant?.includes(currentUserId);
});
});
const canEditEvent = (eventId) => {
const id = Number(eventId);
return editableEvents.value.some((e) => e.id === id);
};
@@ -244,6 +247,7 @@ export const useCalendarStore = defineStore('calendarStore', () => {
eventsForSelectedDate,
visibleCalendars,
allEvents,
calendarColorMap,
editableEvents,
canEditEvent,
+7 -7
View File
@@ -32,7 +32,7 @@ export function checking_for_entry(where, what) {
if (!where.includes(what)) {
where.push(what);
}
}
}
export function getfromserver(path, reactive) {
try {
@@ -63,7 +63,7 @@ export function checkremote(filecheck) {
export default str;
export function splitname(name) {
return name.familyname + " " + name.name[0] + "." + name.parentname[0] + ".";
}
@@ -71,7 +71,7 @@ export function pagecounter() {
// Функция записи посещения страницы сотрудникам.
// В случае, если в роуте присутствует ключ мета и в нем ико - тогда производится запись
const router = useRouter();
if('meta' in router.currentRoute.value && 'ico' in router.currentRoute.value.meta){
const accountStore = useAccountStore();
const appStore = useAppStore();
@@ -95,7 +95,7 @@ export function pagecounter() {
export function useICalReader(url) {
///
const events = ref([]);
const loadICalFile = async () => {
try {
const response = await fetch(url);
@@ -120,13 +120,13 @@ export function useICalReader(url) {
location: event.location,
}
})
return {
type: "calendar",
title: name,
calendar: calendarEvents,
}
// const vevents = comp.getAllSubcomponents('vevent')
// const eventsData = vevents.map(vevent => ({
// vevent: vevent,
@@ -173,4 +173,4 @@ export function useICalReader(url) {
export function declOfNum(value, titles) {
const cases = [2, 0, 1, 1, 1, 2];
return titles[(value % 100 > 4 && value % 100 < 20) ? 2 : cases[(value % 10 < 5) ? value % 10 : 5]];
}
}