fix(calendar): render data of next month is incorrect (#2942)

* fix(calendar): render data of next month is
incorrect

* fix: start date is incorrect when start date field is association field Close T-2336
This commit is contained in:
Dunqing 2023-11-02 11:00:34 +08:00 committed by GitHub
parent 4ad13abfc9
commit ba011e2df6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 6 deletions

View File

@ -1,7 +1,7 @@
import { ArrayField } from '@formily/core';
import { useField } from '@formily/react';
import _ from 'lodash';
import React, { createContext, useContext, useEffect } from 'react';
import React, { createContext, useContext, useEffect, useMemo } from 'react';
import { useRecord } from '../record-provider';
import { FixedBlockWrapper } from '../schema-component';
import { BlockProvider, useBlockRequestContext } from './BlockProvider';
@ -47,8 +47,26 @@ const InternalCalendarBlockProvider = (props) => {
};
export const CalendarBlockProvider = (props) => {
const appends = useMemo(() => {
const arr: string[] = [];
const start = props.fieldNames?.start;
const end = props.fieldNames?.end;
if (Array.isArray(start) && start.length >= 2) {
arr.push(start[0]);
}
if (Array.isArray(end) && end.length >= 2) {
arr.push(end[0]);
}
return arr;
}, [props.fieldNames]);
return (
<BlockProvider name="calendar" {...props} params={{ ...props.params, paginate: false }}>
<BlockProvider
name="calendar"
{...props}
params={{ ...props.params, appends: [...appends, ...(props.params.appends || [])], paginate: false }}
>
<InternalCalendarBlockProvider {...props} />
</BlockProvider>
);

View File

@ -59,12 +59,20 @@ const useEvents = (dataSource: any, fieldNames: any, date: Date, view: (typeof W
const intervalTime = end.diff(start, 'millisecond', true);
const dateM = dayjs(date);
const startDate = dateM.clone().startOf('month');
const endDate = startDate.clone().endOf('month');
let startDate = dateM.clone().startOf('month');
let endDate = startDate.clone().endOf('month');
/**
* view === month
* 6w * 7d 42
* 10.1 9.25
* 10.31 10.5
*/
if (view === 'month') {
startDate.startOf('week');
endDate.endOf('week');
startDate = startDate.startOf('week');
endDate = endDate.endOf('week');
}
const push = (eventStart: Dayjs = start.clone()) => {
// 必须在这个月的开始时间和结束时间,且在日程的开始时间之后
if (eventStart.isBefore(start) || !eventStart.isBetween(startDate, endDate)) {