feat: Dynamically adjust dashboard period start and end dates based on the current day of the month.
This commit is contained in:
@@ -49,18 +49,45 @@ const nextMonth = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const currentStartDate = computed(() => {
|
const currentStartDate = computed(() => {
|
||||||
|
const currentDay = currentBaseDate.value.date();
|
||||||
|
|
||||||
|
// Если текущая дата от 1 до 9, период начинается с 10-го числа предыдущего месяца
|
||||||
|
if (currentDay >= 1 && currentDay <= 9) {
|
||||||
|
return currentBaseDate.value.subtract(1, 'month').date(10).toDate();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Если текущая дата от 10 до конца месяца, период начинается с 10-го числа текущего месяца
|
||||||
return currentBaseDate.value.date(10).toDate();
|
return currentBaseDate.value.date(10).toDate();
|
||||||
});
|
});
|
||||||
|
|
||||||
const currentEndDate = computed(() => {
|
const currentEndDate = computed(() => {
|
||||||
|
const currentDay = currentBaseDate.value.date();
|
||||||
|
|
||||||
|
// Если текущая дата от 1 до 9, период заканчивается 9-го числа текущего месяца
|
||||||
|
if (currentDay >= 1 && currentDay <= 9) {
|
||||||
|
return currentBaseDate.value.date(9).toDate();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Если текущая дата от 10 до конца месяца, период заканчивается 9-го числа следующего месяца
|
||||||
return currentBaseDate.value.add(1, 'month').date(9).toDate();
|
return currentBaseDate.value.add(1, 'month').date(9).toDate();
|
||||||
});
|
});
|
||||||
|
|
||||||
const fetchDashboardData = async () => {
|
const fetchDashboardData = async () => {
|
||||||
if (!spaceStore.selectedSpaceId) return;
|
if (!spaceStore.selectedSpaceId) return;
|
||||||
|
|
||||||
const startDate = currentBaseDate.value.date(10).toDate();
|
const currentDay = currentBaseDate.value.date();
|
||||||
const endDate = currentBaseDate.value.add(1, 'month').date(9).toDate();
|
let startDate: Date;
|
||||||
|
let endDate: Date;
|
||||||
|
|
||||||
|
// Если текущая дата от 1 до 9, период: с 10-го предыдущего месяца до 9-го текущего месяца
|
||||||
|
if (currentDay >= 1 && currentDay <= 9) {
|
||||||
|
startDate = currentBaseDate.value.subtract(1, 'month').date(10).toDate();
|
||||||
|
endDate = currentBaseDate.value.date(9).toDate();
|
||||||
|
} else {
|
||||||
|
// Если текущая дата от 10 до конца месяца, период: с 10-го текущего месяца до 9-го следующего месяца
|
||||||
|
startDate = currentBaseDate.value.date(10).toDate();
|
||||||
|
endDate = currentBaseDate.value.add(1, 'month').date(9).toDate();
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
dashboardData.value = await dashboardService.fetchDashboardData(spaceStore.selectedSpaceId, startDate, endDate)
|
dashboardData.value = await dashboardService.fetchDashboardData(spaceStore.selectedSpaceId, startDate, endDate)
|
||||||
|
|||||||
Reference in New Issue
Block a user