feat(签到页面): 为已选中的已签到日期添加特殊样式
添加 selectedDate 响应式变量来跟踪当前选中日期 修改日历日期格式化逻辑,对当前选中的已签到日期应用不同样式 更新路由导航逻辑以同步选中日期状态
Showing
1 changed file
with
25 additions
and
4 deletions
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2025-05-29 15:34:17 | 2 | * @Date: 2025-05-29 15:34:17 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2025-06-15 22:49:42 | 4 | + * @LastEditTime: 2025-06-19 14:23:17 |
| 5 | * @FilePath: /mlaj/src/views/checkin/IndexCheckInPage.vue | 5 | * @FilePath: /mlaj/src/views/checkin/IndexCheckInPage.vue |
| 6 | * @Description: 文件描述 | 6 | * @Description: 文件描述 |
| 7 | --> | 7 | --> |
| ... | @@ -165,7 +165,7 @@ | ... | @@ -165,7 +165,7 @@ |
| 165 | </template> | 165 | </template> |
| 166 | 166 | ||
| 167 | <script setup> | 167 | <script setup> |
| 168 | -import { ref, onBeforeUnmount, onMounted, computed } from 'vue' | 168 | +import { ref, onBeforeUnmount, onMounted, computed, nextTick, getCurrentInstance } from 'vue' |
| 169 | import { useRoute, useRouter } from 'vue-router' | 169 | import { useRoute, useRouter } from 'vue-router' |
| 170 | import { showConfirmDialog, showSuccessToast, showFailToast, showLoadingToast } from 'vant'; | 170 | import { showConfirmDialog, showSuccessToast, showFailToast, showLoadingToast } from 'vant'; |
| 171 | import AppLayout from "@/components/layout/AppLayout.vue"; | 171 | import AppLayout from "@/components/layout/AppLayout.vue"; |
| ... | @@ -442,11 +442,18 @@ const formatter = (day) => { | ... | @@ -442,11 +442,18 @@ const formatter = (day) => { |
| 442 | 442 | ||
| 443 | // 检查是否已签到 | 443 | // 检查是否已签到 |
| 444 | if (checkin_days.includes(formattedDate)) { | 444 | if (checkin_days.includes(formattedDate)) { |
| 445 | + // 如果是当前选中的已签到日期,使用特殊样式 | ||
| 446 | + if (selectedDate.value === formattedDate) { | ||
| 447 | + day.className = 'calendar-selected'; | ||
| 448 | + day.type = 'selected'; | ||
| 449 | + day.bottomInfo = '已签到'; | ||
| 450 | + } else { | ||
| 445 | day.className = 'calendar-checkin'; | 451 | day.className = 'calendar-checkin'; |
| 446 | day.type = 'selected'; | 452 | day.type = 'selected'; |
| 447 | day.bottomInfo = '已签到'; | 453 | day.bottomInfo = '已签到'; |
| 448 | } | 454 | } |
| 449 | } | 455 | } |
| 456 | + } | ||
| 450 | 457 | ||
| 451 | // 选中今天的日期 | 458 | // 选中今天的日期 |
| 452 | if (dayjs(day.date).isSame(new Date(), 'day')) { | 459 | if (dayjs(day.date).isSame(new Date(), 'day')) { |
| ... | @@ -458,14 +465,22 @@ const formatter = (day) => { | ... | @@ -458,14 +465,22 @@ const formatter = (day) => { |
| 458 | return day; | 465 | return day; |
| 459 | } | 466 | } |
| 460 | 467 | ||
| 468 | +// 添加一个响应式变量来存储当前选中的日期 | ||
| 469 | +const selectedDate = ref(''); | ||
| 470 | + | ||
| 461 | const onSelectDay = (day) => { | 471 | const onSelectDay = (day) => { |
| 462 | getTaskDetail(dayjs(day).format('YYYY-MM')); | 472 | getTaskDetail(dayjs(day).format('YYYY-MM')); |
| 473 | + | ||
| 474 | + // 更新当前选中的日期 | ||
| 475 | + const currentSelectedDate = dayjs(day).format('YYYY-MM-DD'); | ||
| 476 | + selectedDate.value = currentSelectedDate; | ||
| 477 | + | ||
| 463 | // 修改浏览器地址把当前的date加入地址栏, 页面不刷新 | 478 | // 修改浏览器地址把当前的date加入地址栏, 页面不刷新 |
| 464 | router.push({ | 479 | router.push({ |
| 465 | path: route.path, | 480 | path: route.path, |
| 466 | query: { | 481 | query: { |
| 467 | ...route.query, | 482 | ...route.query, |
| 468 | - date: dayjs(day).format('YYYY-MM-DD') | 483 | + date: currentSelectedDate |
| 469 | } | 484 | } |
| 470 | }) | 485 | }) |
| 471 | // 重置分页参数 | 486 | // 重置分页参数 |
| ... | @@ -473,7 +488,7 @@ const onSelectDay = (day) => { | ... | @@ -473,7 +488,7 @@ const onSelectDay = (day) => { |
| 473 | checkinDataList.value = [] | 488 | checkinDataList.value = [] |
| 474 | finished.value = false | 489 | finished.value = false |
| 475 | // 重新加载数据 | 490 | // 重新加载数据 |
| 476 | - onLoad(dayjs(day).format('YYYY-MM-DD')) | 491 | + onLoad(currentSelectedDate) |
| 477 | } | 492 | } |
| 478 | 493 | ||
| 479 | const onClickSubtitle = (evt) => { | 494 | const onClickSubtitle = (evt) => { |
| ... | @@ -692,6 +707,12 @@ const formatData = (data) => { | ... | @@ -692,6 +707,12 @@ const formatData = (data) => { |
| 692 | </script> | 707 | </script> |
| 693 | 708 | ||
| 694 | <style lang="less"> | 709 | <style lang="less"> |
| 710 | +.calendar-selected { | ||
| 711 | + .van-calendar__selected-day { | ||
| 712 | + background: #4caf50 !important; | ||
| 713 | + } | ||
| 714 | +} | ||
| 715 | + | ||
| 695 | .calendar-checkin { | 716 | .calendar-checkin { |
| 696 | .van-calendar__selected-day { | 717 | .van-calendar__selected-day { |
| 697 | background: #a2d8a3 !important; | 718 | background: #a2d8a3 !important; | ... | ... |
-
Please register or login to post a comment