fix [P-290]: фикс событий в виджете календаря
This commit is contained in:
1 parent
3f0f1e8f1a
commit
0d404e533b
11 files changed
+333
-140
No files matched your search
@@ -199,26 +199,37 @@ export default {
|
||||
|
||||
// Получаем имя файла из объекта файла
|
||||
const getFileName = (fileData) => {
|
||||
// Для новых файлов (File object) - берем оригинальное имя
|
||||
if (fileData instanceof File) {
|
||||
return cleanFileName(fileData.name);
|
||||
return fileData.name;
|
||||
}
|
||||
// Для существующих файлов с бэка - извлекаем имя из пути
|
||||
|
||||
// Для существующих файлов с бэкенда - извлекаем из URL
|
||||
if (fileData.file) {
|
||||
try {
|
||||
const filePath = fileData.file.split('?')[0]; // Убираем параметры
|
||||
const fileName = filePath.split('/').pop(); // Берем последнюю часть пути
|
||||
return cleanFileName(fileName) || 'Файл';
|
||||
} catch {
|
||||
const filePath = fileData.file.startsWith('http')
|
||||
? new URL(fileData.file).pathname
|
||||
: fileData.file;
|
||||
|
||||
// Извлекаем имя файла
|
||||
let fileName = filePath.split('/').pop();
|
||||
|
||||
// Декодируем URL-encoded символы, но НЕ изменяем имя
|
||||
fileName = decodeURIComponent(fileName);
|
||||
|
||||
return fileName || 'Файл';
|
||||
} catch (error) {
|
||||
console.warn('Ошибка извлечения имени файла:', error, fileData);
|
||||
return 'Файл';
|
||||
}
|
||||
}
|
||||
|
||||
return cleanFileName(fileData.name || 'Файл');
|
||||
};
|
||||
// Если есть name в данных - используем как есть
|
||||
if (fileData.name) {
|
||||
return fileData.name;
|
||||
}
|
||||
|
||||
const cleanFileName = (fileName) => {
|
||||
// Убираем суффиксы в скобках (1), (2) и т.д.
|
||||
return fileName.replace(/\s*\(\d+\)(?=\.\w+$|$)/, '');
|
||||
return 'Файл';
|
||||
};
|
||||
|
||||
// Иконка в зависимости от типа файла
|
||||
@@ -306,27 +317,25 @@ export default {
|
||||
|
||||
const downloadExistingFile = async (file) => {
|
||||
try {
|
||||
const getOriginalFileName = (filePath) => {
|
||||
try {
|
||||
const pathParts = filePath.split('/');
|
||||
return pathParts[pathParts.length - 1];
|
||||
} catch {
|
||||
return 'file';
|
||||
}
|
||||
};
|
||||
const fileName = getFileName(file); // Теперь будет работать правильно!
|
||||
const fileUrl = file.file.startsWith('http')
|
||||
? file.file
|
||||
: `${window.location.origin}${file.file}`; // Для относительных путей
|
||||
|
||||
const fileName = getOriginalFileName(file.file);
|
||||
const fileUrl = file.file;
|
||||
// Создаем временную ссылку для скачивания
|
||||
const link = document.createElement('a');
|
||||
link.href = fileUrl;
|
||||
link.download = fileName; // Указываем имя файла при скачивании
|
||||
link.download = fileName;
|
||||
link.style.display = 'none';
|
||||
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
|
||||
setTimeout(() => {
|
||||
document.body.removeChild(link);
|
||||
}, 100);
|
||||
} catch (error) {
|
||||
console.error('Ошибка при скачивании файла:', error);
|
||||
errorMessages.value = ['Ошибка скачивания файла'];
|
||||
}
|
||||
};
|
||||
|
||||
@@ -360,7 +369,6 @@ export default {
|
||||
handleFileSelect,
|
||||
triggerFileInput,
|
||||
handleDrop,
|
||||
cleanFileName,
|
||||
downloadExistingFile,
|
||||
truncateFileName,
|
||||
};
|
||||
|
||||
@@ -59,6 +59,10 @@ export default {
|
||||
calendarStore.loadCalendars();
|
||||
};
|
||||
|
||||
const getDictEmployee = () => {
|
||||
calendarStore.loadEmployees();
|
||||
};
|
||||
|
||||
const getEvent = (idEvent) => {
|
||||
if (!idEvent) {
|
||||
eventFromCalendar.value = createEmptyEvent();
|
||||
@@ -98,6 +102,8 @@ export default {
|
||||
onMounted(() => {
|
||||
getEvent();
|
||||
week.getWeekend(MyYear.value);
|
||||
getDictEmployee();
|
||||
getCalendar();
|
||||
});
|
||||
|
||||
const closeEventDialog = () => {
|
||||
@@ -151,6 +157,7 @@ export default {
|
||||
openEventDialog,
|
||||
createEmptyEvent,
|
||||
eventKey,
|
||||
getDictEmployee,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
@@ -113,7 +113,7 @@ export default {
|
||||
const handleEventClick = (info) => {
|
||||
if (calendarStore.canEditEvent(info.event.id)) {
|
||||
emit('openEventDialog', info);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const calendarOptions = ref({
|
||||
@@ -310,6 +310,36 @@ export default {
|
||||
selectedDate.value = dateStr;
|
||||
};
|
||||
|
||||
// const updateCalendarEvents = () => {
|
||||
// if (!calendarRef.value) return;
|
||||
|
||||
// const api = calendarApi.value;
|
||||
// api.removeAllEvents();
|
||||
|
||||
// allEvents.value.forEach((event) => {
|
||||
// const eventColor = calendarColorMap.value.get(event.calendar) || '#3788d8';
|
||||
|
||||
// api.addEvent({
|
||||
// id: event.id,
|
||||
// title: event.name || event.title,
|
||||
// start: event.date_start || event.start,
|
||||
// end: event.date_end || event.end,
|
||||
// allDay: event.allday || event.all_day,
|
||||
// textColor: '#ffffff',
|
||||
// backgroundColor: eventColor,
|
||||
// borderColor: eventColor,
|
||||
// extendedProps: {
|
||||
// originalEventId: event.id,
|
||||
// description: event.description,
|
||||
// participant: event.participant,
|
||||
// calendar: event.calendar,
|
||||
// files: event.files,
|
||||
// isRecurringInstance: event.isRecurringInstance || false,
|
||||
// },
|
||||
// });
|
||||
// });
|
||||
// };
|
||||
|
||||
// Обновление событий в календаре
|
||||
const updateCalendarEvents = () => {
|
||||
if (!calendarRef.value) return;
|
||||
|
||||
@@ -37,8 +37,6 @@
|
||||
}"
|
||||
@click="onDateClick(day.date)"
|
||||
>
|
||||
|
||||
|
||||
<div class="day-content">
|
||||
<span class="day-number">{{ day.day }}</span>
|
||||
<div class="day-events">
|
||||
@@ -59,7 +57,9 @@
|
||||
<!-- Дневное расписание -->
|
||||
<v-col cols="5" class="pl-2">
|
||||
<div class="schedule-header">
|
||||
<h3 class="day-title"> <span v-if="isToday(selectedDate)">Сегодня, </span>{{formattedSelectedDate }}</h3>
|
||||
<h3 class="day-title">
|
||||
<span v-if="isToday(selectedDate)">Сегодня, </span>{{ formattedSelectedDate }}
|
||||
</h3>
|
||||
</div>
|
||||
|
||||
<v-card variant="outlined" class="day-schedule" elevation="0">
|
||||
@@ -102,6 +102,7 @@
|
||||
import { ref, computed, onMounted, watch } from 'vue';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { useCalendarStore } from '@/store/calendarStore';
|
||||
import { useRecurrence } from '@/components/calendar_of_events/composables/useReccurrence';
|
||||
|
||||
export default {
|
||||
name: 'HomeCalendarWidget',
|
||||
@@ -115,6 +116,7 @@ export default {
|
||||
// Работа с хранилищем
|
||||
const calendarStore = useCalendarStore();
|
||||
const { allEvents, calendarColorMap } = storeToRefs(calendarStore);
|
||||
const { generateRecurringInstances, isRecurringEvent } = useRecurrence();
|
||||
|
||||
// Утилиты для работы с датами (главный источник проблем!)
|
||||
const formatToLocalDate = (date) => {
|
||||
@@ -134,25 +136,92 @@ export default {
|
||||
return getStartOfDay(date1).getTime() === getStartOfDay(date2).getTime();
|
||||
};
|
||||
|
||||
// Преобразование событий с защитой от ошибок
|
||||
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: eventColor || '#1976d2',
|
||||
calendar: event.calendar,
|
||||
isHoliday: false,
|
||||
};
|
||||
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';
|
||||
|
||||
// 1. Периодичное + многодневное
|
||||
if (hasRecurrence && isMultiDay) {
|
||||
const instances = generateRecurringInstances(event, 12);
|
||||
return instances.flatMap((instance) => expandMultiDayInstance(event, instance));
|
||||
}
|
||||
|
||||
// 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,
|
||||
}));
|
||||
}
|
||||
|
||||
// 3. Непериодичное + многодневное
|
||||
if (!hasRecurrence && isMultiDay) {
|
||||
return expandMultiDayInstance(event, event);
|
||||
}
|
||||
|
||||
// 4. Непериодичное + однодневное
|
||||
return event;
|
||||
});
|
||||
|
||||
return [...userEvents];
|
||||
return expandedEvents.map((event) => formatForWidget(event));
|
||||
});
|
||||
|
||||
// Разбивает многодневный экземпляр на дни
|
||||
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);
|
||||
|
||||
while (currentDay < endDate) {
|
||||
const dayStart = new Date(currentDay);
|
||||
const dayEnd = new Date(currentDay);
|
||||
dayEnd.setDate(dayEnd.getDate() + 1);
|
||||
|
||||
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,
|
||||
});
|
||||
|
||||
currentDay.setDate(currentDay.getDate() + 1);
|
||||
}
|
||||
|
||||
return days;
|
||||
};
|
||||
|
||||
// Форматирование для виджета
|
||||
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 = ['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс'];
|
||||
|
||||
// Генерация календаря
|
||||
@@ -316,6 +385,8 @@ export default {
|
||||
|
||||
calendarStore,
|
||||
allEvents,
|
||||
expandMultiDayInstance,
|
||||
formatForWidget,
|
||||
};
|
||||
},
|
||||
};
|
||||
@@ -529,6 +600,6 @@ export default {
|
||||
}
|
||||
|
||||
.day-cell:not(.current-month).non-working-day {
|
||||
color: inherit !important;
|
||||
/* color: inherit !important; */
|
||||
}
|
||||
</style>
|
||||
@@ -86,7 +86,6 @@ export default {
|
||||
loadCalendars();
|
||||
|
||||
updateCalendarDays();
|
||||
setInterval(updateCalendarDays, 500);
|
||||
});
|
||||
|
||||
// Реакция на изменения пользователя
|
||||
@@ -96,6 +95,18 @@ export default {
|
||||
}
|
||||
});
|
||||
|
||||
watch(selectedDate, () => {
|
||||
updateCalendarDays();
|
||||
});
|
||||
|
||||
watch(
|
||||
[myCalendars, subscribedCalendars],
|
||||
() => {
|
||||
updateCalendarDays();
|
||||
},
|
||||
{ deep: true },
|
||||
);
|
||||
|
||||
// Функция для добавления классов дням
|
||||
const updateCalendarDays = () => {
|
||||
nextTick(() => {
|
||||
|
||||
@@ -22,23 +22,14 @@
|
||||
size="36px"
|
||||
@click="$emit('delObject')"
|
||||
/>
|
||||
<!-- <v-btn
|
||||
class="text-subtitle-1"
|
||||
elevation="0"
|
||||
width="150"
|
||||
@click="clearValidation"
|
||||
color="btn_gray"
|
||||
variant="flat"
|
||||
>резет</v-btn
|
||||
> -->
|
||||
<!-- <v-btn @click="clearFormValidation"></v-btn> -->
|
||||
<v-btn
|
||||
<v-btn
|
||||
class="text-subtitle-1"
|
||||
elevation="0"
|
||||
width="150"
|
||||
@click="$emit('closeDialog')"
|
||||
color="btn_gray"
|
||||
variant="flat"
|
||||
type="button"
|
||||
>Отменить</v-btn
|
||||
>
|
||||
|
||||
@@ -48,7 +39,7 @@
|
||||
variant="flat"
|
||||
elevation="0"
|
||||
width="150"
|
||||
type="transformation"
|
||||
type="submit"
|
||||
>
|
||||
{{ newOrOld ? "Создать" : "Сохранить" }}
|
||||
</v-btn>
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
<v-chip class="me-2" color="teal-darken-3" size="small" label>
|
||||
<span> {{ item.title }}</span>
|
||||
<v-icon
|
||||
v-if="item.value != accountStore.user.is_idEmployee"
|
||||
v-if="item.value != accountStore.user.is_idEmployee && !isAuthor(item.raw)"
|
||||
icon="mdi-close-circle"
|
||||
size="x-small"
|
||||
class="ml-3"
|
||||
@@ -46,7 +46,35 @@
|
||||
></v-checkbox-btn>
|
||||
</template>
|
||||
</v-list-item>
|
||||
<!-- ВСЕ НАЧАЛЬНИКИ -->
|
||||
<v-list-item
|
||||
:disabled="!hasBossesInStaff"
|
||||
class="text-body-2"
|
||||
@click.stop="toggleByPosition('начальник')"
|
||||
>
|
||||
<span class="text-body-2"> ВСЕ НАЧАЛЬНИКИ </span>
|
||||
<template v-slot:prepend>
|
||||
<v-checkbox-btn
|
||||
:model-value="hasBossesSelected"
|
||||
:disabled="!hasBossesInStaff"
|
||||
></v-checkbox-btn>
|
||||
</template>
|
||||
</v-list-item>
|
||||
|
||||
<!-- ВСЕ ЗАМЕСТИТЕЛИ -->
|
||||
<v-list-item
|
||||
:disabled="!hasDeputiesInStaff"
|
||||
class="text-body-2"
|
||||
@click.stop="toggleByPosition('заместитель')"
|
||||
>
|
||||
<span class="text-body-2"> ВСЕ ЗАМЕСТИТЕЛИ </span>
|
||||
<template v-slot:prepend>
|
||||
<v-checkbox-btn
|
||||
:model-value="hasDeputiesSelected"
|
||||
:disabled="!hasDeputiesInStaff"
|
||||
></v-checkbox-btn>
|
||||
</template>
|
||||
</v-list-item>
|
||||
<v-divider class="mt-2"></v-divider>
|
||||
</template>
|
||||
|
||||
@@ -60,7 +88,7 @@
|
||||
:color="'indigo-darken-4'"
|
||||
:true-value="true"
|
||||
:false-value="false"
|
||||
:disabled="disable(item.raw)"
|
||||
:disabled="disable(item.raw) || isAuthor(item.raw)"
|
||||
:indeterminate="
|
||||
item.raw.employees.some((e) => e[okey] == true) &&
|
||||
!item.raw.employees.every((e) => e[okey] == true)
|
||||
@@ -78,12 +106,12 @@
|
||||
:key="x.id"
|
||||
:value="x.title"
|
||||
@click.stop="selectedStaff = x"
|
||||
:disabled="x.id == accountStore.user.is_idEmployee"
|
||||
:disabled="x.id == accountStore.user.is_idEmployee || isAuthor(x)"
|
||||
density="compact"
|
||||
>
|
||||
<template v-slot:prepend>
|
||||
<v-checkbox-btn
|
||||
:disabled="x.id == accountStore.user.is_idEmployee"
|
||||
:disabled="x.id == accountStore.user.is_idEmployee || isAuthor(x)"
|
||||
color="indigo-darken-4"
|
||||
:model-value="x[okey]"
|
||||
></v-checkbox-btn>
|
||||
@@ -94,7 +122,7 @@
|
||||
</template>
|
||||
</v-autocomplete>
|
||||
<!-- Кнопки быстрого выбора -->
|
||||
<div class="quick-filters mb-3">
|
||||
<!-- <div class="quick-filters mb-3">
|
||||
<v-btn
|
||||
size="small"
|
||||
:variant="hasBossesSelected ? 'tonal' : 'outlined'"
|
||||
@@ -103,7 +131,7 @@
|
||||
@click="toggleByPosition('начальник')"
|
||||
:disabled="!dictEmployeesLoaded || !hasBossesInStaff"
|
||||
>
|
||||
{{ hasBossesSelected ? 'Снять начальников' : 'Выбрать всех начальников' }}
|
||||
{{ hasBossesSelected ? 'Отменить выбор начальников' : 'Выбрать всех начальников' }}
|
||||
</v-btn>
|
||||
|
||||
<v-btn
|
||||
@@ -113,17 +141,18 @@
|
||||
@click="toggleByPosition('заместитель')"
|
||||
:disabled="!dictEmployeesLoaded || !hasDeputiesInStaff"
|
||||
>
|
||||
{{ hasDeputiesSelected ? 'Снять заместителей' : 'Выбрать всех заместителей' }}
|
||||
{{ hasDeputiesSelected ? 'Отменить выбор заместителей' : 'Выбрать всех заместителей' }}
|
||||
</v-btn>
|
||||
</div>
|
||||
</div> -->
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { ref, computed } from 'vue';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { splitname } from '@/utils/universal_functions';
|
||||
import { useAccountStore } from '@/store/AccountStore';
|
||||
import { axiosApiInstance } from '@/utils/axios-api';
|
||||
import { useCalendarStore } from '@/store/calendarStore';
|
||||
|
||||
export default {
|
||||
props: {
|
||||
@@ -135,11 +164,19 @@ export default {
|
||||
type: String,
|
||||
default: 'selected',
|
||||
},
|
||||
authorID: {
|
||||
type: Number,
|
||||
default: null,
|
||||
},
|
||||
},
|
||||
|
||||
setup(props, { emit }) {
|
||||
const filtered = ref('');
|
||||
|
||||
const accountStore = useAccountStore();
|
||||
const calendarStore = useCalendarStore();
|
||||
const { dictEmployeesLoaded } = storeToRefs(calendarStore);
|
||||
|
||||
const back = ref([]);
|
||||
|
||||
const staffed = computed({
|
||||
@@ -284,27 +321,23 @@ export default {
|
||||
: false;
|
||||
};
|
||||
|
||||
// Функция проверки является ли сотрудник создателем
|
||||
const isAuthor = (item) => {
|
||||
if (!props.authorID) return false;
|
||||
|
||||
// Если это отдел - проверяем всех сотрудников
|
||||
if ('employees' in item) {
|
||||
return item.employees.some((emp) => emp.id === props.authorID);
|
||||
}
|
||||
|
||||
// Если это сотрудник - проверяем напрямую
|
||||
return item.id === props.authorID;
|
||||
};
|
||||
|
||||
const allUser = () => {
|
||||
emitUp(staffed.value);
|
||||
};
|
||||
|
||||
const dictEmployees = ref([]);
|
||||
const dictEmployeesLoaded = ref(false);
|
||||
|
||||
// Загружаем данные с должностями
|
||||
const loadDictEmployees = async () => {
|
||||
try {
|
||||
const response = await axiosApiInstance.get('api/vote/getdictemployee/');
|
||||
dictEmployees.value = response.data;
|
||||
dictEmployeesLoaded.value = true;
|
||||
} catch (error) {
|
||||
console.error('Ошибка загрузки должностей:', error);
|
||||
dictEmployeesLoaded.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
loadDictEmployees();
|
||||
|
||||
// Проверяем выбраны ли все начальники (с исключениями)
|
||||
const hasBossesSelected = computed(() => {
|
||||
const bosses = findEmployeesByPosition(['начальник', 'и.о'], ['заместитель', 'зам.']);
|
||||
@@ -333,12 +366,27 @@ export default {
|
||||
const employeesToToggle = findEmployeesByPosition(keywords, excludeKeywords);
|
||||
const shouldSelect = !employeesToToggle.every((emp) => emp[props.okey] === true);
|
||||
|
||||
// if (employeesToToggle.length > 0) {
|
||||
// employeesToToggle.forEach((employee) => {
|
||||
// if (employee[props.okey] !== shouldSelect) {
|
||||
// emitUp(employee);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
if (employeesToToggle.length > 0) {
|
||||
employeesToToggle.forEach((employee) => {
|
||||
if (employee[props.okey] !== shouldSelect) {
|
||||
emitUp(employee);
|
||||
}
|
||||
});
|
||||
// ФИЛЬТРУЕМ - убираем создателя события из массовых операций
|
||||
const filteredEmployees = employeesToToggle.filter(
|
||||
(employee) => employee.id !== props.authorID, //
|
||||
);
|
||||
|
||||
if (filteredEmployees.length > 0) {
|
||||
filteredEmployees.forEach((employee) => {
|
||||
if (employee[props.okey] !== shouldSelect) {
|
||||
selectedStaff.value = employee;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -346,12 +394,11 @@ export default {
|
||||
const findEmployeesByPosition = (positionKeywords, excludeKeywords = []) => {
|
||||
const foundEmployees = [];
|
||||
|
||||
if (!dictEmployeesLoaded.value) {
|
||||
return foundEmployees;
|
||||
}
|
||||
|
||||
props.staff.forEach((department) => {
|
||||
department.employees.forEach((employee) => {
|
||||
if (department.id == 1) {
|
||||
return;
|
||||
}
|
||||
if (employee.id === accountStore.user.is_idEmployee) {
|
||||
return;
|
||||
}
|
||||
@@ -360,7 +407,7 @@ export default {
|
||||
return;
|
||||
}
|
||||
|
||||
const employeeData = dictEmployees.value.find((de) => de.id === employee.id);
|
||||
const employeeData = calendarStore.dictEmployees.find((de) => de.id === employee.id);
|
||||
|
||||
if (employeeData && employeeData.post) {
|
||||
const post = employeeData.post.toLowerCase();
|
||||
@@ -384,7 +431,10 @@ export default {
|
||||
};
|
||||
// Проверяем есть ли начальники в staff
|
||||
const hasBossesInStaff = computed(() => {
|
||||
return findEmployeesByPosition(['начальник', 'и.о. начальника']).length > 0;
|
||||
return (
|
||||
findEmployeesByPosition(['начальник', 'и.о. начальника'], ['заместитель', 'зам.']).length >
|
||||
0
|
||||
);
|
||||
});
|
||||
|
||||
// Проверяем есть ли заместители в staff
|
||||
@@ -396,6 +446,7 @@ export default {
|
||||
});
|
||||
|
||||
return {
|
||||
isAuthor,
|
||||
staffed,
|
||||
filtered,
|
||||
accountStore,
|
||||
@@ -406,11 +457,11 @@ export default {
|
||||
customFilterFn,
|
||||
findEmployeesByPosition,
|
||||
toggleByPosition,
|
||||
dictEmployeesLoaded,
|
||||
hasBossesInStaff,
|
||||
hasBossesSelected,
|
||||
hasDeputiesInStaff,
|
||||
hasDeputiesSelected,
|
||||
dictEmployeesLoaded,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
<calendar-create-select
|
||||
:staff="newStaff"
|
||||
@returnIdParticant="returnIdParticant"
|
||||
:authorID="calendarAuthorId"
|
||||
/> </v-col
|
||||
></v-row>
|
||||
</v-col>
|
||||
@@ -69,6 +70,7 @@
|
||||
:staff="newStaff"
|
||||
:okey="'editor'"
|
||||
@returnIdParticant="returnIdParticant"
|
||||
:authorID="calendarAuthorId"
|
||||
/>
|
||||
</v-col>
|
||||
<v-col lg="1" class="text-center">
|
||||
@@ -109,6 +111,15 @@ export default {
|
||||
setup(props, { emit }) {
|
||||
const accountStore = useAccountStore();
|
||||
|
||||
const calendarAuthorId = computed(() => {
|
||||
// Для нового календаря - текущий пользователь
|
||||
if (isNewCalendar.value) {
|
||||
return accountStore.user.is_idEmployee;
|
||||
}
|
||||
// Для существующего - автор из props
|
||||
return propsCalendar.value.author;
|
||||
});
|
||||
|
||||
const returnIdParticant = (idPart) => {
|
||||
idPart.staff.forEach((e) => {
|
||||
let indx = propsCalendar.value.participant.findIndex((l) => l.participant_calendar == e.id);
|
||||
@@ -206,40 +217,22 @@ export default {
|
||||
},
|
||||
});
|
||||
|
||||
// const color = [
|
||||
// '#3788d8', // Синий (аналог default FullCalendar)
|
||||
// '#4caf50', // Зеленый
|
||||
// '#ff9800', // Оранжевый
|
||||
// '#9c27b0', // Фиолетовый
|
||||
// '#2196f3', // Голубой
|
||||
// '#795548', // Коричневый
|
||||
// '#607d8b', // Серо-голубой
|
||||
// '#e91e63', // Розовый
|
||||
// '#00bcd4', // Бирюзовый
|
||||
// '#8bc34a', // Салатовый
|
||||
// '#ff5722', // Красно-оранжевый
|
||||
// '#673ab7', // Темно-фиолетовый
|
||||
// '#3f51b5', // Индиго
|
||||
// '#009688', // Зелено-бирюзовый
|
||||
// '#ffc107', // Янтарный
|
||||
// ];
|
||||
|
||||
const color = [
|
||||
'#4299e1', // Яркий синий
|
||||
'#48bb78', // Сочный зеленый
|
||||
'#ed8936', // Оранжевый
|
||||
'#9f7aea', // Фиолетовый
|
||||
'#38b2ac', // Бирюзовый
|
||||
'#f56565', // Коралловый
|
||||
'#667eea', // Голубой
|
||||
'#68d391', // Светло-зеленый
|
||||
'#f6ad55', // Персиковый
|
||||
'#b794f4', // Лавандовый
|
||||
'#4fd1c7', // Яркий бирюзовый
|
||||
'#fc8181', // Розово-коралловый
|
||||
'#5a67d8', // Индиго
|
||||
'#ecc94b', // Золотистый
|
||||
'#0bc5ea', // Голубой океан
|
||||
'#4f46e5', // Индиго (профессиональный синий)
|
||||
'#0ea5e9', // Яркий голубой
|
||||
'#10b981', // Изумрудно-зеленый
|
||||
'#f59e0b', // Теплый янтарный
|
||||
'#ef4444', // Акцентный красный
|
||||
'#8b5cf6', // Фиолетовый
|
||||
'#06b6d4', // Бирюзовый
|
||||
'#84cc16', // Лаймовый
|
||||
'#f97316', // Оранжевый
|
||||
'#ec4899', // Розовый
|
||||
'#6366f1', // Фиолетово-синий
|
||||
'#14b8a6', // Бирюзово-зеленый
|
||||
'#eab308', // Золотисто-желтый
|
||||
'#3b82f6', // Королевский синий
|
||||
'#22c55e', // Зеленый
|
||||
];
|
||||
|
||||
const colorPik = (col) => {
|
||||
@@ -279,6 +272,7 @@ export default {
|
||||
newCalendar,
|
||||
newStaff,
|
||||
isNewCalendar,
|
||||
calendarAuthorId,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
@@ -127,17 +127,11 @@ export default {
|
||||
toggleCalendarVisibility(cal.id);
|
||||
};
|
||||
|
||||
watch(
|
||||
hiddenCalendarIds,
|
||||
(newHiddenIds) => {
|
||||
},
|
||||
{ deep: true },
|
||||
);
|
||||
watch(hiddenCalendarIds, (newHiddenIds) => {}, { deep: true });
|
||||
|
||||
watch(
|
||||
() => props.calendars,
|
||||
(newCalendars) => {
|
||||
},
|
||||
(newCalendars) => {},
|
||||
{ deep: true },
|
||||
);
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
<calendar-create-select
|
||||
:staff="newStaff"
|
||||
@returnIdParticant="returnIdParticant"
|
||||
:authorID="currentCalendarAuthorId"
|
||||
/> </v-col
|
||||
></v-row>
|
||||
|
||||
@@ -228,6 +229,20 @@ export default {
|
||||
|
||||
const staff = ref([]);
|
||||
|
||||
const currentCalendarAuthorId = computed(() => {
|
||||
if (isNewEvent.value) {
|
||||
// Для нового события - автор текущего выбранного календаря
|
||||
return myCalendar.value?.author;
|
||||
} else {
|
||||
// Для существующего события - автор календаря события
|
||||
const eventCalendarId = propsEvent.value.event.calendar;
|
||||
const currentCalendar = propsEvent.value.mycalendars?.find(
|
||||
(cal) => parseInt(cal.id) === parseInt(eventCalendarId),
|
||||
);
|
||||
return currentCalendar?.author;
|
||||
}
|
||||
});
|
||||
|
||||
axiosApiInstance.get('api/calendar_of_events/get_employees/').then((res) => {
|
||||
staff.value = res.data.filter((e) => e.employees.length > 0);
|
||||
});
|
||||
@@ -235,6 +250,7 @@ export default {
|
||||
const newStaff = computed({
|
||||
get() {
|
||||
let filteredStaff = [];
|
||||
|
||||
if (isNewEvent.value) {
|
||||
if (myCalendar.value == null) return [];
|
||||
const participants = myCalendar.value.participant || [];
|
||||
@@ -562,9 +578,13 @@ export default {
|
||||
);
|
||||
|
||||
if (propsEvent.value.event.files !== null) {
|
||||
newFiles.value.forEach((e) => postEvent.append('files', e));
|
||||
// newFiles.value.forEach((e) => postEvent.append('files', e));
|
||||
newFiles.value.forEach((file) => {
|
||||
postEvent.append('files', file, file.name);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
axiosApiInstance.post('api/calendar_of_events/my_events/', postEvent).then((result) => {
|
||||
feedalert.alert = true;
|
||||
feedalert.text = result.data.mess;
|
||||
@@ -681,6 +701,7 @@ export default {
|
||||
safeCalendars,
|
||||
isCalendarsReady,
|
||||
isNewEvent,
|
||||
currentCalendarAuthorId,
|
||||
|
||||
repeatRules,
|
||||
updatePeriodRule,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { ref, computed, watch } from 'vue';
|
||||
import { axiosApiInstance, getEmployees } from '@/utils/axios-api';
|
||||
import { axiosApiInstance } from '@/utils/axios-api';
|
||||
import { useAccountStore } from '@/store/AccountStore';
|
||||
|
||||
export const useCalendarStore = defineStore('calendarStore', () => {
|
||||
@@ -15,6 +15,8 @@ export const useCalendarStore = defineStore('calendarStore', () => {
|
||||
const calendars = ref([]); // Список календарей пользователя
|
||||
const lastUpdatedBy = ref(null);
|
||||
const holidays = ref([]);
|
||||
const dictEmployees = ref([]);
|
||||
const dictEmployeesLoaded = ref(false);
|
||||
|
||||
// Массив ID скрытых календарей. Загружаем из localStorage при инициализации.
|
||||
const hiddenCalendarIds = ref([]);
|
||||
@@ -90,6 +92,17 @@ export const useCalendarStore = defineStore('calendarStore', () => {
|
||||
}
|
||||
};
|
||||
|
||||
const loadEmployees = async () => {
|
||||
try {
|
||||
const response = await axiosApiInstance.get(`api/vote/getdictemployee/`);
|
||||
dictEmployees.value = response.data;
|
||||
dictEmployeesLoaded.value = true;
|
||||
} catch (error) {
|
||||
console.error('Ошибка получения всех сотрудников:', error);
|
||||
dictEmployeesLoaded.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const toggleCalendarVisibility = (calendarId) => {
|
||||
const index = hiddenCalendarIds.value.indexOf(calendarId);
|
||||
if (index === -1) {
|
||||
@@ -210,7 +223,7 @@ export const useCalendarStore = defineStore('calendarStore', () => {
|
||||
return result;
|
||||
};
|
||||
|
||||
// Открыть диалог создания/редактирования
|
||||
// Открыть диалог создания/редактирования
|
||||
const openEventDialog = (event = null) => {
|
||||
selectedEvent.value = event;
|
||||
showEventDialog.value = true;
|
||||
@@ -233,6 +246,7 @@ export const useCalendarStore = defineStore('calendarStore', () => {
|
||||
lastUpdatedBy,
|
||||
hiddenCalendarIds,
|
||||
holidays,
|
||||
dictEmployeesLoaded,
|
||||
|
||||
// Getters
|
||||
formattedSelectedDate,
|
||||
@@ -243,6 +257,7 @@ export const useCalendarStore = defineStore('calendarStore', () => {
|
||||
allEvents,
|
||||
calendarColorMap,
|
||||
|
||||
dictEmployees,
|
||||
editableEvents,
|
||||
canEditEvent,
|
||||
|
||||
@@ -257,6 +272,6 @@ export const useCalendarStore = defineStore('calendarStore', () => {
|
||||
toggleCalendarVisibility,
|
||||
fetchHolidays,
|
||||
isNonWorkingDay,
|
||||
// loadEmployees,
|
||||
loadEmployees,
|
||||
};
|
||||
});
|
||||
Reference in new issue
Block a user