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:
parent
4ad13abfc9
commit
ba011e2df6
@ -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>
|
||||
);
|
||||
|
@ -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)) {
|
||||
|
Loading…
Reference in New Issue
Block a user