import { Col, Radio, Row, Select } from 'antd'; import { Dayjs } from 'dayjs'; import { Lunar } from 'lunar-typescript'; import { FC } from 'react'; const getYearLabel = (year: number) => { const d = Lunar.fromDate(new Date(year + 1, 0)); return `${d.getYearInChinese()}年(${d.getYearInGanZhi()}${d.getYearShengXiao()}年)`; }; const getMonthLabel = (month: number, value: Dayjs) => { const d = Lunar.fromDate(new Date(value.year(), month)); const lunar = d.getMonthInChinese(); return `${month + 1}月(${lunar}月)`; }; interface CustomHeaderProps { value: Dayjs; type: string; onChange: (date: Dayjs) => void; onTypeChange: (e: any) => void; } const CustomHeader: FC = ({ value, type, onChange, onTypeChange }) => { const start = 0; const end = 12; const monthOptions = []; let current = value.clone(); const localeDate = (value as any).localeData(); const months = []; for (let i = 0; i < 12; i++) { current = current.month(i); months.push(localeDate.monthsShort(current)); } for (let i = start; i < end; i++) { monthOptions.push({ label: getMonthLabel(i, value), value: i, }); } const year = value.year(); const month = value.month(); const options = []; for (let i = year - 10; i < year + 10; i += 1) { options.push({ label: getYearLabel(i), value: i, }); } return ( { const now = value.clone().month(newMonth); onChange(now); }} /> onTypeChange(e.target.value)} value={type} > ); }; export default CustomHeader;