From 8d887ff36bbab70e3b31d5a18398e603b366406a Mon Sep 17 00:00:00 2001 From: ChenQiuYu Date: Fri, 23 May 2025 10:55:49 +0800 Subject: [PATCH] dev --- src/components/registration/Edit.vue | 2 +- src/utils/dateUtils.ts | 57 ++++++++++++++++++++-------- 2 files changed, 43 insertions(+), 16 deletions(-) diff --git a/src/components/registration/Edit.vue b/src/components/registration/Edit.vue index 561341b..d2acb07 100644 --- a/src/components/registration/Edit.vue +++ b/src/components/registration/Edit.vue @@ -138,7 +138,7 @@ start="00:00" step="00:15" end="23:45" - :min-time="getCurrentTime()" + :min-time="getCurrentTime(edit_data.date)" placeholder="选择时间" style="width: 50%" /> diff --git a/src/utils/dateUtils.ts b/src/utils/dateUtils.ts index 51095ef..a2bb005 100644 --- a/src/utils/dateUtils.ts +++ b/src/utils/dateUtils.ts @@ -1,4 +1,4 @@ -export const formatDate = (date: Date|string): any => { +export const formatDate = (date: Date | string): any => { if (date === undefined || date === null) { return '-'; } @@ -61,33 +61,48 @@ export const formatDateArray = (dates: Date[]): string[] => { export const getToday = () => { 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 = () => { const yesterday = new Date(); 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 = () => { const tomorrow = new Date(); 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 = () => { const today = new Date(); const startOfWeek = new Date(today.setDate(today.getDate() - today.getDay())); 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 = () => { const today = new Date(); const startOfMonth = new Date(today.getFullYear(), today.getMonth(), 1); 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[] => { @@ -119,7 +134,7 @@ export const getEndOfDay = (date: Date | string): string => { dateDetail.setHours(23, 59, 59, 0); // 设置为当天 23:59:00 return formatDate(dateDetail).slice(0, 19); // }; -export const getCurrentDate=()=> { +export const getCurrentDate = () => { const date = new Date(); const year = date.getFullYear(); // 月份从0开始,所以要加1 @@ -128,7 +143,7 @@ export const getCurrentDate=()=> { return `${year}-${month}-${day}`; } //帮我写个方法获取前30天日期并返回 -export const getPrevious30Days=()=> { +export const getPrevious30Days = () => { const dates = []; const currentDate = new Date(); for (let i = 0; i < 31; i++) { @@ -136,13 +151,25 @@ export const getPrevious30Days=()=> { date.setDate(currentDate.getDate() - i); dates.push(date.toISOString().slice(0, 10)); } - return dates[dates.length-1]; + return dates[dates.length - 1]; } //获取当前时间的时分 -export const getCurrentTime=()=> { - const currentDate = new Date(); - const hours = currentDate.getHours(); - const minutes = currentDate.getMinutes(); - return `${hours}:${minutes}`; -} \ No newline at end of file +export const getCurrentTime = (date:any) => { + const today = new Date(); + const selectedDate =date ? new Date(date) : today; + + // 判断是否是今天 + 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; + } +}; \ No newline at end of file