fix [P-290]: исправлен виджет календаря на домашней странице
This commit is contained in:
1 parent
45f365f734
commit
76a6d0ae20
5 files changed
+115
-115
No files matched your search
@@ -59,7 +59,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { computed, ref } from 'vue';
|
import { computed, ref, watch } from 'vue';
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
files: {
|
files: {
|
||||||
@@ -75,10 +75,12 @@ export default {
|
|||||||
const MAX_FILE_SIZE = 2 * 1024 * 1024; // 2 МБ
|
const MAX_FILE_SIZE = 2 * 1024 * 1024; // 2 МБ
|
||||||
const MAX_NEW_FILES = 5;
|
const MAX_NEW_FILES = 5;
|
||||||
|
|
||||||
// const newFiles = computed({
|
watch(
|
||||||
// get: () => props.newFiles,
|
() => props.newFiles,
|
||||||
// set: (value) => emit('update:newFiles', value),
|
(newVal) => {
|
||||||
// });
|
localNewFiles.value = [...newVal];
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
const formatFileSize = (bytes) => {
|
const formatFileSize = (bytes) => {
|
||||||
if (bytes === 0) return '0 Б';
|
if (bytes === 0) return '0 Б';
|
||||||
@@ -190,6 +192,9 @@ export default {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
localNewFiles.value = [...validFiles];
|
||||||
|
|
||||||
|
emit('update:newFiles', validFiles);
|
||||||
emit('postFiles', validFiles);
|
emit('postFiles', validFiles);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -313,8 +313,8 @@ export default {
|
|||||||
end: new Date(event.date_end),
|
end: new Date(event.date_end),
|
||||||
allDay: event.all_day,
|
allDay: event.all_day,
|
||||||
textColor: '#ffffff',
|
textColor: '#ffffff',
|
||||||
backgroundColor: eventColor,
|
// backgroundColor: eventColor,
|
||||||
borderColor: eventColor,
|
// borderColor: eventColor,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!rruleOptions) {
|
if (!rruleOptions) {
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
</v-btn>
|
</v-btn>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<v-table density="compact" class="month-table">
|
<v-table class="month-table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th v-for="day in russianWeekdays" :key="day" class="weekday-header">
|
<th v-for="day in russianWeekdays" :key="day" class="weekday-header">
|
||||||
@@ -56,9 +56,9 @@
|
|||||||
<v-col cols="5" class="pl-2">
|
<v-col cols="5" class="pl-2">
|
||||||
<div class="schedule-header">
|
<div class="schedule-header">
|
||||||
<h3 class="day-title">{{ formattedSelectedDate }}</h3>
|
<h3 class="day-title">{{ formattedSelectedDate }}</h3>
|
||||||
<v-chip size="small" color="primary" variant="outlined" v-if="isToday(selectedDate)">
|
<!-- <v-chip size="small" color="primary" variant="outlined" v-if="isToday(selectedDate)">
|
||||||
Сегодня
|
Сегодня
|
||||||
</v-chip>
|
</v-chip> -->
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<v-card variant="outlined" class="day-schedule" elevation="0">
|
<v-card variant="outlined" class="day-schedule" elevation="0">
|
||||||
@@ -96,56 +96,56 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { ref, computed, onMounted } from 'vue';
|
import { ref, computed, onMounted } from 'vue';
|
||||||
|
import { storeToRefs } from 'pinia';
|
||||||
|
import { useCalendarStore } from '@/store/calendarStore';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'HomeCalendarWidget',
|
name: 'HomeCalendarWidget',
|
||||||
|
|
||||||
setup() {
|
setup() {
|
||||||
|
// Реактивные данные
|
||||||
const currentDate = ref(new Date());
|
const currentDate = ref(new Date());
|
||||||
const selectedDate = ref(new Date().toISOString().split('T')[0]);
|
const selectedDate = ref(''); // Будет установлено в формате YYYY-MM-DD
|
||||||
|
|
||||||
// Тестовые события
|
// Работа с хранилищем
|
||||||
const events = ref([
|
const calendarStore = useCalendarStore();
|
||||||
{
|
const { allEvents } = storeToRefs(calendarStore);
|
||||||
id: 1,
|
|
||||||
title: 'Еженедельное совещание команды',
|
|
||||||
start: new Date(new Date().setHours(10, 0)).toISOString(),
|
|
||||||
end: new Date(new Date().setHours(11, 30)).toISOString(),
|
|
||||||
color: '#2196F3',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 2,
|
|
||||||
title: 'Обед с клиентом',
|
|
||||||
start: new Date(new Date().setHours(13, 0)).toISOString(),
|
|
||||||
end: new Date(new Date().setHours(14, 0)).toISOString(),
|
|
||||||
color: '#4CAF50',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 3,
|
|
||||||
title: 'Презентация проекта',
|
|
||||||
start: new Date(
|
|
||||||
new Date(new Date().setDate(new Date().getDate() + 1)).setHours(15, 0),
|
|
||||||
).toISOString(),
|
|
||||||
end: new Date(
|
|
||||||
new Date(new Date().setDate(new Date().getDate() + 1)).setHours(16, 0),
|
|
||||||
).toISOString(),
|
|
||||||
color: '#FF9800',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 4,
|
|
||||||
title: 'Планерка отдела',
|
|
||||||
start: new Date(
|
|
||||||
new Date(new Date().setDate(new Date().getDate() + 3)).setHours(9, 30),
|
|
||||||
).toISOString(),
|
|
||||||
end: new Date(
|
|
||||||
new Date(new Date().setDate(new Date().getDate() + 3)).setHours(10, 30),
|
|
||||||
).toISOString(),
|
|
||||||
color: '#9C27B0',
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
const russianWeekdays = computed(() => ['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс']);
|
// Утилиты для работы с датами (главный источник проблем!)
|
||||||
|
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 getStartOfDay = (date) => {
|
||||||
|
const newDate = new Date(date);
|
||||||
|
newDate.setHours(0, 0, 0, 0);
|
||||||
|
return newDate;
|
||||||
|
};
|
||||||
|
|
||||||
|
const areDatesEqual = (date1, date2) => {
|
||||||
|
return getStartOfDay(date1).getTime() === getStartOfDay(date2).getTime();
|
||||||
|
};
|
||||||
|
|
||||||
|
// Преобразование событий с защитой от ошибок
|
||||||
|
const events = computed(() => {
|
||||||
|
return allEvents.value.map((event) => {
|
||||||
|
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',
|
||||||
|
};
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const russianWeekdays = ['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс'];
|
||||||
|
|
||||||
|
// Генерация календаря
|
||||||
const calendarWeeks = computed(() => {
|
const calendarWeeks = computed(() => {
|
||||||
const year = currentDate.value.getFullYear();
|
const year = currentDate.value.getFullYear();
|
||||||
const month = currentDate.value.getMonth();
|
const month = currentDate.value.getMonth();
|
||||||
@@ -156,24 +156,19 @@ export default {
|
|||||||
const weeks = [];
|
const weeks = [];
|
||||||
let week = [];
|
let week = [];
|
||||||
|
|
||||||
// Заполняем пустые дни предыдущего месяца
|
// Находим понедельник первой недели
|
||||||
const firstDayOfWeek = (firstDay.getDay() + 6) % 7; // Пн = 0, Вс = 6
|
const startDay = new Date(firstDay);
|
||||||
for (let i = 0; i < firstDayOfWeek; i++) {
|
startDay.setDate(startDay.getDate() - ((startDay.getDay() + 6) % 7));
|
||||||
const prevMonthDay = new Date(year, month, -i);
|
|
||||||
week.unshift({
|
// Генерируем 6 недель (фиксированное количество для стабильности)
|
||||||
day: prevMonthDay.getDate(),
|
for (let i = 0; i < 42; i++) {
|
||||||
date: prevMonthDay.toISOString().split('T')[0],
|
const currentDay = new Date(startDay);
|
||||||
isCurrentMonth: false,
|
currentDay.setDate(startDay.getDate() + i);
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Текущий месяц
|
|
||||||
for (let day = 1; day <= lastDay.getDate(); day++) {
|
|
||||||
const date = new Date(year, month, day);
|
|
||||||
week.push({
|
week.push({
|
||||||
day: day,
|
day: currentDay.getDate(),
|
||||||
date: date.toISOString().split('T')[0],
|
date: formatToLocalDate(currentDay),
|
||||||
isCurrentMonth: true,
|
isCurrentMonth: currentDay.getMonth() === month,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (week.length === 7) {
|
if (week.length === 7) {
|
||||||
@@ -182,33 +177,22 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Заполняем оставшиеся дни следующего месяца
|
|
||||||
if (week.length > 0) {
|
|
||||||
let nextMonthDay = 1;
|
|
||||||
while (week.length < 7) {
|
|
||||||
const date = new Date(year, month + 1, nextMonthDay);
|
|
||||||
week.push({
|
|
||||||
day: nextMonthDay,
|
|
||||||
date: date.toISOString().split('T')[0],
|
|
||||||
isCurrentMonth: false,
|
|
||||||
});
|
|
||||||
nextMonthDay++;
|
|
||||||
}
|
|
||||||
weeks.push(week);
|
|
||||||
}
|
|
||||||
|
|
||||||
return weeks;
|
return weeks;
|
||||||
});
|
});
|
||||||
|
|
||||||
const currentMonth = computed(() => {
|
const currentMonth = computed(() => {
|
||||||
return new Date(currentDate.value).toLocaleDateString('ru-RU', {
|
return currentDate.value.toLocaleDateString('ru-RU', {
|
||||||
month: 'long',
|
month: 'long',
|
||||||
year: 'numeric',
|
year: 'numeric',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
const formattedSelectedDate = computed(() => {
|
const formattedSelectedDate = computed(() => {
|
||||||
return new Date(selectedDate.value).toLocaleDateString('ru-RU', {
|
if (!selectedDate.value) return '';
|
||||||
|
|
||||||
|
// Добавляем время для избежания смещения часовых поясов
|
||||||
|
const date = new Date(selectedDate.value + 'T12:00:00');
|
||||||
|
return date.toLocaleDateString('ru-RU', {
|
||||||
day: 'numeric',
|
day: 'numeric',
|
||||||
month: 'long',
|
month: 'long',
|
||||||
year: 'numeric',
|
year: 'numeric',
|
||||||
@@ -216,18 +200,23 @@ export default {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const dayEvents = computed(() => {
|
const dayEvents = computed(() => {
|
||||||
|
if (!selectedDate.value) return [];
|
||||||
|
|
||||||
|
const selected = new Date(selectedDate.value + 'T12:00:00');
|
||||||
|
|
||||||
return events.value
|
return events.value
|
||||||
.filter((event) => {
|
.filter((event) => {
|
||||||
const eventDate = new Date(event.start).toISOString().split('T')[0];
|
const eventDate = new Date(event.start);
|
||||||
return eventDate === selectedDate.value;
|
return areDatesEqual(eventDate, selected);
|
||||||
})
|
})
|
||||||
.sort((a, b) => new Date(a.start) - new Date(b.start));
|
.sort((a, b) => new Date(a.start).getTime() - new Date(b.start).getTime());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Методы
|
||||||
const isToday = (date) => {
|
const isToday = (date) => {
|
||||||
const today = new Date().toISOString().split('T')[0];
|
const today = new Date();
|
||||||
const checkDate = new Date(date).toISOString().split('T')[0];
|
const checkDate = new Date(date + 'T12:00:00');
|
||||||
return today === checkDate;
|
return areDatesEqual(today, checkDate);
|
||||||
};
|
};
|
||||||
|
|
||||||
const isSelected = (date) => {
|
const isSelected = (date) => {
|
||||||
@@ -235,10 +224,11 @@ export default {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getDayEvents = (date) => {
|
const getDayEvents = (date) => {
|
||||||
const dateStr = new Date(date).toISOString().split('T')[0];
|
const checkDate = new Date(date + 'T12:00:00');
|
||||||
|
|
||||||
return events.value.filter((event) => {
|
return events.value.filter((event) => {
|
||||||
const eventDate = new Date(event.start).toISOString().split('T')[0];
|
const eventDate = new Date(event.start);
|
||||||
return eventDate === dateStr;
|
return areDatesEqual(eventDate, checkDate);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -273,18 +263,23 @@ export default {
|
|||||||
};
|
};
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
selectedDate.value = new Date().toISOString().split('T')[0];
|
selectedDate.value = formatToLocalDate(new Date());
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
// Реактивные данные
|
||||||
currentDate,
|
currentDate,
|
||||||
selectedDate,
|
selectedDate,
|
||||||
|
|
||||||
|
// Вычисляемые свойства
|
||||||
events,
|
events,
|
||||||
russianWeekdays,
|
russianWeekdays,
|
||||||
calendarWeeks,
|
calendarWeeks,
|
||||||
currentMonth,
|
currentMonth,
|
||||||
formattedSelectedDate,
|
formattedSelectedDate,
|
||||||
dayEvents,
|
dayEvents,
|
||||||
|
|
||||||
|
// Методы
|
||||||
isToday,
|
isToday,
|
||||||
isSelected,
|
isSelected,
|
||||||
getDayEvents,
|
getDayEvents,
|
||||||
@@ -293,6 +288,9 @@ export default {
|
|||||||
onDateClick,
|
onDateClick,
|
||||||
prevMonth,
|
prevMonth,
|
||||||
nextMonth,
|
nextMonth,
|
||||||
|
|
||||||
|
calendarStore,
|
||||||
|
allEvents,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -300,8 +298,9 @@ export default {
|
|||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.home-calendar-widget {
|
.home-calendar-widget {
|
||||||
width: 700px;
|
width: 100%;
|
||||||
height: 300px;
|
/* width: 700px; */
|
||||||
|
height: 100%;
|
||||||
font-family: 'Roboto', sans-serif;
|
font-family: 'Roboto', sans-serif;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -332,6 +331,7 @@ export default {
|
|||||||
|
|
||||||
.month-table {
|
.month-table {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.weekday-header {
|
.weekday-header {
|
||||||
@@ -345,7 +345,8 @@ export default {
|
|||||||
|
|
||||||
.day-cell {
|
.day-cell {
|
||||||
width: 14.28%;
|
width: 14.28%;
|
||||||
height: 40px;
|
height: 15%;
|
||||||
|
/* height: 50px; */
|
||||||
text-align: center;
|
text-align: center;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
border: 1px solid transparent;
|
border: 1px solid transparent;
|
||||||
@@ -409,7 +410,7 @@ export default {
|
|||||||
.schedule-header {
|
.schedule-header {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: space-between;
|
justify-content: center;
|
||||||
margin-bottom: 12px;
|
margin-bottom: 12px;
|
||||||
padding: 0 4px;
|
padding: 0 4px;
|
||||||
}
|
}
|
||||||
@@ -422,7 +423,7 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.day-schedule {
|
.day-schedule {
|
||||||
height: 220px;
|
height: 90%;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
border: 1px solid #e0e0e0;
|
border: 1px solid #e0e0e0;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
|
|||||||
@@ -153,10 +153,10 @@
|
|||||||
<v-col class="text-body-2 text-text_grey pb-5 pt-3" lg="2"> Файлы </v-col>
|
<v-col class="text-body-2 text-text_grey pb-5 pt-3" lg="2"> Файлы </v-col>
|
||||||
|
|
||||||
<uploading-file
|
<uploading-file
|
||||||
|
v-model:new-files="newFiles"
|
||||||
|
@update:model-value="newFiles = $event"
|
||||||
:files="propsEvent.event.files"
|
:files="propsEvent.event.files"
|
||||||
:new-files="newFiles"
|
|
||||||
@update:files="propsEvent.event.files = $event"
|
@update:files="propsEvent.event.files = $event"
|
||||||
@update:new-files="newFiles = $event"
|
|
||||||
@postFiles="postFiles"
|
@postFiles="postFiles"
|
||||||
/>
|
/>
|
||||||
</v-row>
|
</v-row>
|
||||||
@@ -234,7 +234,7 @@ export default {
|
|||||||
],
|
],
|
||||||
calendar: [(val) => !!val || 'Выберите календарь'],
|
calendar: [(val) => !!val || 'Выберите календарь'],
|
||||||
};
|
};
|
||||||
|
console.log(propsEvent.value);
|
||||||
const repeatRules = [
|
const repeatRules = [
|
||||||
{ type: 'Не повторять', rule: null, id: 1 },
|
{ type: 'Не повторять', rule: null, id: 1 },
|
||||||
{
|
{
|
||||||
@@ -485,17 +485,10 @@ export default {
|
|||||||
|
|
||||||
let postEvent = new FormData();
|
let postEvent = new FormData();
|
||||||
postEvent.append('event', JSON.stringify({ ...propsEvent.value.event, files: [] }));
|
postEvent.append('event', JSON.stringify({ ...propsEvent.value.event, files: [] }));
|
||||||
// if (propsEvent.value.event.files !== null) {
|
if (propsEvent.value.event.files !== null) {
|
||||||
// files.value.forEach((e) => postEvent.append('files', e));
|
newFiles.value.forEach((e) => postEvent.append('files', e));
|
||||||
// }
|
|
||||||
if (newFiles.value.length > 0) {
|
|
||||||
newFiles.value.forEach((file) => {
|
|
||||||
postEvent.append('files', file);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Отправляемые файлы:', newFiles.value);
|
|
||||||
|
|
||||||
axiosApiInstance.post('api/calendar_of_events/my_events/', postEvent).then((result) => {
|
axiosApiInstance.post('api/calendar_of_events/my_events/', postEvent).then((result) => {
|
||||||
feedalert.alert = true;
|
feedalert.alert = true;
|
||||||
feedalert.text = result.data.mess;
|
feedalert.text = result.data.mess;
|
||||||
@@ -574,7 +567,7 @@ export default {
|
|||||||
initializeRule();
|
initializeRule();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ immediate: true }, // Вызовется сразу при создании watch
|
{ immediate: true },
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -602,6 +595,7 @@ export default {
|
|||||||
|
|
||||||
createDialog,
|
createDialog,
|
||||||
handleAutoAdjustEnd,
|
handleAutoAdjustEnd,
|
||||||
|
newFiles,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -8,9 +8,9 @@
|
|||||||
</v-col>
|
</v-col>
|
||||||
</v-row>
|
</v-row>
|
||||||
|
|
||||||
<v-row class="flex-grow-0" style="min-height: 300px; max-height: 300px">
|
<v-row class="flex-grow-0" style="min-height: 300px">
|
||||||
<v-col class="pa-1 d-flex align-stretch" style="height: 100%">
|
<v-col class="pa-1 d-flex align-stretch">
|
||||||
<HomeCalendarWidget class="h-100" />
|
<HomeCalendarWidget />
|
||||||
</v-col>
|
</v-col>
|
||||||
</v-row>
|
</v-row>
|
||||||
<!-- <v-row style="height: 250px">
|
<!-- <v-row style="height: 250px">
|
||||||
|
|||||||
Reference in new issue
Block a user