hookehuyr

feat(日历): 禁用未来日期并添加样式

添加日期格式化函数中对未来日期的禁用逻辑,并设置对应的禁用样式
...@@ -429,6 +429,11 @@ const openImagePreview = (index, post) => { ...@@ -429,6 +429,11 @@ const openImagePreview = (index, post) => {
429 const onChange = (index) => { 429 const onChange = (index) => {
430 startPosition.value = index; 430 startPosition.value = index;
431 } 431 }
432 +/**
433 + * 日历日期格式化函数
434 + * @param {Object} day - 日期对象
435 + * @returns {Object} 格式化后的日期对象
436 + */
432 const formatter = (day) => { 437 const formatter = (day) => {
433 const year = day.date.getFullYear(); 438 const year = day.date.getFullYear();
434 const month = day.date.getMonth() + 1; 439 const month = day.date.getMonth() + 1;
...@@ -436,6 +441,13 @@ const formatter = (day) => { ...@@ -436,6 +441,13 @@ const formatter = (day) => {
436 441
437 let checkin_days = myCheckinDates.value; 442 let checkin_days = myCheckinDates.value;
438 443
444 + // 禁用未来日期
445 + if (dayjs(day.date).isAfter(new Date(), 'day')) {
446 + day.type = 'disabled';
447 + day.className = 'calendar-disabled';
448 + return day;
449 + }
450 +
439 // 检查当前日期是否在签到日期列表中 451 // 检查当前日期是否在签到日期列表中
440 if (checkin_days && checkin_days.length > 0) { 452 if (checkin_days && checkin_days.length > 0) {
441 // 格式化当前日期为YYYY-MM-DD格式,与checkin_days中的格式匹配 453 // 格式化当前日期为YYYY-MM-DD格式,与checkin_days中的格式匹配
...@@ -840,4 +852,15 @@ const formatData = (data) => { ...@@ -840,4 +852,15 @@ const formatData = (data) => {
840 :deep(.van-calendar__footer) { 852 :deep(.van-calendar__footer) {
841 display: none; 853 display: none;
842 } 854 }
855 +
856 +/* 禁用未来日期的样式 */
857 +:deep(.calendar-disabled) {
858 + color: #c8c9cc !important;
859 + background-color: #f7f8fa !important;
860 + cursor: not-allowed !important;
861 +}
862 +
863 +:deep(.calendar-disabled .van-calendar__day-text) {
864 + color: #c8c9cc !important;
865 +}
843 </style> 866 </style>
......