修改日历与弹出窗

This commit is contained in:
筱野
2025-11-14 20:50:20 +08:00
parent b13979c4ab
commit 95e17d19f8
8 changed files with 24 additions and 42 deletions

View File

@@ -133,7 +133,7 @@ const CommonPopup: React.FC<CommonPopupProps> = ({
</View>
{!hideFooter && (
<View className={styles['common-popup__footer']}>
<View className={`${styles['common-popup__footer']} custom_footer`}>
<Button className={`${styles['common-popup__btn']} ${styles['common-popup__btn-cancel']}`} type='default' size='small' onClick={handleCancel}>
{cancelText}
</Button>

View File

@@ -24,9 +24,6 @@ const DayDialog: React.FC<DayDialogProps> = ({
onChange,
}) => {
const [selected, setSelected] = useState<Date | Date[]>(value || new Date());
const [selectedBackup, setSelectedBackup] = useState<Date[]>(
Array.isArray(value) ? [...(value as Date[])] : [value as Date]
);
const calendarRef = useRef<CalendarUIRef>(null);
const [type, setType] = useState<"year" | "month" | "time">("year");
const [pendingJump, setPendingJump] = useState<{
@@ -47,26 +44,6 @@ const DayDialog: React.FC<DayDialogProps> = ({
}
const handleChange = (d: Date | Date[]) => {
if (searchType === "range") {
if (Array.isArray(d)) {
if (d.length === 2) {
return;
} else if (d.length === 1) {
if (selectedBackup.length === 0 || selectedBackup.length === 2) {
setSelected([...d]);
setSelectedBackup([...d]);
} else {
setSelected(
[...selectedBackup, d[0]].sort(
(a, b) => a.getTime() - b.getTime()
)
);
setSelectedBackup([]);
}
}
return;
}
}
if (Array.isArray(d)) {
setSelected(d[0]);
} else {

View File

@@ -25,7 +25,10 @@ const HourDialog: React.FC<HourDialogProps> = ({
const handleConfirm = () => {
const value = hourMinutePickerRef.current?.getValue();
if (onChange) {
onChange(value);
const [hour, minute] = value || [];
const hours = hour.toString().padStart(2, "0");
const minutes = minute.toString().padStart(2, "0");
onChange([hours, minutes]);
}
dialogClose();
};

View File

@@ -51,8 +51,6 @@ const CustomPicker = ({
Array.isArray(currentValue) &&
valuesList.length === currentValue.length &&
valuesList.every((v: any, idx: number) => v === currentValue[idx])
console.log(isSame,valuesList, 'isSameisSameisSameisSame');
if (!isSame) {
setCurrentValue(valuesList)
}

View File

@@ -10,7 +10,10 @@ import dayjs from 'dayjs'
const parseDate = (dateStr: string): Date => {
if (!dateStr) return new Date();
// 将 "yyyy-MM-dd HH:mm:ss" 转换为 "yyyy-MM-ddTHH:mm:ss"
console.log(dateStr, 'dateStrdateStrdateStr');
const isoStr = dateStr.replace(/^(\d{4}-\d{2}-\d{2})\s(\d{2}:\d{2}(?::\d{2})?)$/, '$1T$2');
console.log(isoStr, 'isoStr');
console.log(new Date(isoStr), 'new Date');
return new Date(isoStr);
};
@@ -43,11 +46,11 @@ const TimeSelector: React.FC<TimeSelectorProps> = ({
console.log('选择的日期:', date)
const start_time = currentTimeType === 'start' ? getDateStr(date) : value.start_time;
const end_time = currentTimeType === 'end' ? getDateStr(date) : value.end_time;
const isLater = dayjs(start_time).isAfter(dayjs(end_time));
if (isLater) {
if (onChange) onChange({start_time, end_time: getEndTime(start_time)})
return
}
// const isLater = dayjs(start_time).isAfter(dayjs(end_time));
// if (isLater) {
// if (onChange) onChange({start_time, end_time: getEndTime(start_time)})
// return
// }
if (onChange) onChange({start_time, end_time})
}
const onChangeDay = (years:any) => {
@@ -62,7 +65,7 @@ const TimeSelector: React.FC<TimeSelectorProps> = ({
}
}
const onChangeHour = (dates) => {
const [hour, minute] = dates;
const [hour, minute = '00'] = dates;
if (onChange){
if (currentTimeType === 'start') {
const year = dayjs(value.start_time).format('YYYY-MM-DD')