import dayjs from 'dayjs'; import React, { useState } from 'react'; import { Text, View } from 'react-native'; import { DatePicker, Button, Space } from '@xrnjs/ui'; import Card from '_global/Card'; import styles from './style'; const DateRangeLimit: React.FC = () => { const [limitedDate, setLimitedDate] = useState(null); const [businessDate, setBusinessDate] = useState(null); const minDate = dayjs().subtract(1, 'year').toDate(); const maxDate = dayjs().add(1, 'year').toDate(); const defaultDate = dayjs().subtract(1, 'day').toDate(); const handleLimitedDatePick = () => { DatePicker({ title: '限制日期范围', mode: 'Y-D', min: minDate, max: maxDate, defaultValue: defaultDate, }).then(({ action, value }) => { if (action === 'confirm') { setLimitedDate(value); } }); }; const handleBusinessDatePick = () => { const today = new Date(); const businessMin = new Date( today.getFullYear(), today.getMonth(), today.getDate() + 1 ); const businessMax = new Date( today.getFullYear(), today.getMonth() + 3, today.getDate() ); DatePicker({ title: '业务日期选择', mode: 'Y-D', min: businessMin, max: businessMax, defaultValue: businessMin, }).then(({ action, value }) => { if (action === 'confirm') { setBusinessDate(value); } }); }; return ( 日期范围限制 自定义最大值和最小值 最小值:{dayjs(minDate).format('YYYY-MM-DD')} 最大值:{dayjs(maxDate).format('YYYY-MM-DD')} 默认值:{dayjs(defaultDate).format('YYYY-MM-DD')} {limitedDate && ( 选中:{dayjs(limitedDate).format('YYYY-MM-DD')} )} 业务场景示例 只能选择明天到三个月后的日期 {businessDate && ( 选中:{dayjs(businessDate).format('YYYY-MM-DD')} )} ); }; export default DateRangeLimit;