fix: calendar component optimization
This commit is contained in:
parent
01a0ed8420
commit
36f7389b22
@ -1,13 +1,13 @@
|
|||||||
import { LeftOutlined, RightOutlined } from '@ant-design/icons';
|
import { LeftOutlined, RightOutlined } from '@ant-design/icons';
|
||||||
import { createForm } from '@formily/core';
|
import { createForm } from '@formily/core';
|
||||||
import { observer, RecursionField, Schema, useFieldSchema } from '@formily/react';
|
import { observer, RecursionField, Schema, useFieldSchema } from '@formily/react';
|
||||||
|
import { parseExpression } from 'cron-parser';
|
||||||
import get from 'lodash/get';
|
import get from 'lodash/get';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import React, { useMemo, useState } from 'react';
|
import React, { useMemo, useState } from 'react';
|
||||||
import { Calendar as BigCalendar, momentLocalizer } from 'react-big-calendar';
|
import { Calendar as BigCalendar, momentLocalizer } from 'react-big-calendar';
|
||||||
import * as dates from 'react-big-calendar/lib/utils/dates';
|
import * as dates from 'react-big-calendar/lib/utils/dates';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { parseExpression } from 'cron-parser';
|
|
||||||
import { RecordProvider } from '../../../';
|
import { RecordProvider } from '../../../';
|
||||||
import { i18n } from '../../../i18n';
|
import { i18n } from '../../../i18n';
|
||||||
import { useProps } from '../../hooks/useProps';
|
import { useProps } from '../../hooks/useProps';
|
||||||
@ -187,6 +187,18 @@ export const Calendar: any = observer((props: any) => {
|
|||||||
const [visible, setVisible] = useState(false);
|
const [visible, setVisible] = useState(false);
|
||||||
const [record, setRecord] = useState<any>({});
|
const [record, setRecord] = useState<any>({});
|
||||||
|
|
||||||
|
const components = useMemo(() => {
|
||||||
|
return {
|
||||||
|
toolbar: (props) => <Toolbar {...props} showLunar={showLunar}></Toolbar>,
|
||||||
|
week: {
|
||||||
|
header: (props) => <Header {...props} type="week" showLunar={showLunar}></Header>,
|
||||||
|
},
|
||||||
|
month: {
|
||||||
|
dateHeader: (props) => <Header {...props} showLunar={showLunar}></Header>,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}, [showLunar]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{ height: 700 }}>
|
<div style={{ height: 700 }}>
|
||||||
<CalendarRecordViewer visible={visible} setVisible={setVisible} record={record} />
|
<CalendarRecordViewer visible={visible} setVisible={setVisible} record={record} />
|
||||||
@ -228,15 +240,7 @@ export const Calendar: any = observer((props: any) => {
|
|||||||
return `${local.format(start, 'Y-M', culture)} - ${local.format(end, 'Y-M', culture)}`;
|
return `${local.format(start, 'Y-M', culture)} - ${local.format(end, 'Y-M', culture)}`;
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
components={{
|
components={components}
|
||||||
toolbar: (props) => <Toolbar {...props} showLunar={showLunar}></Toolbar>,
|
|
||||||
week: {
|
|
||||||
header: (props) => <Header {...props} type="week" showLunar={showLunar}></Header>,
|
|
||||||
},
|
|
||||||
month: {
|
|
||||||
dateHeader: (props) => <Header {...props} showLunar={showLunar}></Header>,
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
localizer={localizer}
|
localizer={localizer}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
import { observer } from '@formily/react';
|
import { observer } from '@formily/react';
|
||||||
import moment from 'moment';
|
|
||||||
import React, { useContext, useMemo } from 'react';
|
import React, { useContext, useMemo } from 'react';
|
||||||
import solarLunar from 'solarlunar-es';
|
|
||||||
import { useDesignable } from '../../hooks';
|
import { useDesignable } from '../../hooks';
|
||||||
import { CalendarToolbarContext } from './context';
|
import { CalendarToolbarContext } from './context';
|
||||||
import { getLunarDay } from './utils';
|
import { getLunarDay } from './utils';
|
||||||
|
Loading…
Reference in New Issue
Block a user