This commit is contained in:
ChenQiuYu 2025-05-23 10:55:49 +08:00
parent 16b5fec12a
commit 8d887ff36b
2 changed files with 43 additions and 16 deletions

View File

@ -138,7 +138,7 @@
start="00:00" start="00:00"
step="00:15" step="00:15"
end="23:45" end="23:45"
:min-time="getCurrentTime()" :min-time="getCurrentTime(edit_data.date)"
placeholder="选择时间" placeholder="选择时间"
style="width: 50%" style="width: 50%"
/> />

View File

@ -61,33 +61,48 @@ export const formatDateArray = (dates: Date[]): string[] => {
export const getToday = () => { export const getToday = () => {
const today = new Date(); const today = new Date();
return { start: formatDate(new Date(today.setHours(0, 0, 0, 0))), end: formatDate(new Date(today.setHours(23, 59, 59, 999))) }; return {
start: formatDate(new Date(today.setHours(0, 0, 0, 0))),
end: formatDate(new Date(today.setHours(23, 59, 59, 999)))
};
}; };
export const getYesterday = () => { export const getYesterday = () => {
const yesterday = new Date(); const yesterday = new Date();
yesterday.setDate(yesterday.getDate() - 1); yesterday.setDate(yesterday.getDate() - 1);
return { start: formatDate(new Date(yesterday.setHours(0, 0, 0, 0))), end: formatDate(new Date(yesterday.setHours(23, 59, 59, 999))) }; return {
start: formatDate(new Date(yesterday.setHours(0, 0, 0, 0))),
end: formatDate(new Date(yesterday.setHours(23, 59, 59, 999)))
};
}; };
export const getTomorrow = () => { export const getTomorrow = () => {
const tomorrow = new Date(); const tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1); tomorrow.setDate(tomorrow.getDate() + 1);
return { start: formatDate(new Date(tomorrow.setHours(0, 0, 0, 0))), end: formatDate(new Date(tomorrow.setHours(23, 59, 59, 999))) }; return {
start: formatDate(new Date(tomorrow.setHours(0, 0, 0, 0))),
end: formatDate(new Date(tomorrow.setHours(23, 59, 59, 999)))
};
}; };
export const getThisWeek = () => { export const getThisWeek = () => {
const today = new Date(); const today = new Date();
const startOfWeek = new Date(today.setDate(today.getDate() - today.getDay())); const startOfWeek = new Date(today.setDate(today.getDate() - today.getDay()));
const endOfWeek = new Date(today.setDate(today.getDate() - today.getDay() + 6)); const endOfWeek = new Date(today.setDate(today.getDate() - today.getDay() + 6));
return { start: formatDate(new Date(startOfWeek.setHours(0, 0, 0, 0))), end: formatDate(new Date(endOfWeek.setHours(23, 59, 59, 999))) }; return {
start: formatDate(new Date(startOfWeek.setHours(0, 0, 0, 0))),
end: formatDate(new Date(endOfWeek.setHours(23, 59, 59, 999)))
};
}; };
export const getThisMonth = () => { export const getThisMonth = () => {
const today = new Date(); const today = new Date();
const startOfMonth = new Date(today.getFullYear(), today.getMonth(), 1); const startOfMonth = new Date(today.getFullYear(), today.getMonth(), 1);
const endOfMonth = new Date(today.getFullYear(), today.getMonth() + 1, 0); const endOfMonth = new Date(today.getFullYear(), today.getMonth() + 1, 0);
return { start: formatDate(new Date(startOfMonth.setHours(0, 0, 0, 0))), end: formatDate(new Date(endOfMonth.setHours(23, 59, 59, 999))) }; return {
start: formatDate(new Date(startOfMonth.setHours(0, 0, 0, 0))),
end: formatDate(new Date(endOfMonth.setHours(23, 59, 59, 999)))
};
}; };
export const getDaysBetweenDates = (startDateStr: string, endDateStr: string): string[] => { export const getDaysBetweenDates = (startDateStr: string, endDateStr: string): string[] => {
@ -140,9 +155,21 @@ export const getPrevious30Days=()=> {
} }
//获取当前时间的时分 //获取当前时间的时分
export const getCurrentTime=()=> { export const getCurrentTime = (date:any) => {
const currentDate = new Date(); const today = new Date();
const hours = currentDate.getHours(); const selectedDate =date ? new Date(date) : today;
const minutes = currentDate.getMinutes();
return `${hours}:${minutes}`; // 判断是否是今天
const isToday =
selectedDate.getFullYear() === today.getFullYear() &&
selectedDate.getMonth() === today.getMonth() &&
selectedDate.getDate() === today.getDate();
if (isToday) {
// 如果是今天,返回当前时间如 "14:30"
return `${String(today.getHours()).padStart(2, '0')}:${String(today.getMinutes()).padStart(2, '0')}`;
} else {
// 如果不是今天,返回 null 或 undefined表示不设置 min-time
return undefined;
} }
};