fix: 🐛 修复 Calendar 为周选择时跨年周的单元格值显示错误的问题#854
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
概述遍历在 变更
诗歌
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Deploying wot-design-uni with
|
| Latest commit: |
eb87219
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://c98acd0a.wot-design-uni.pages.dev |
| Branch Preview URL: | https://fix-calendar-week-error.wot-design-uni.pages.dev |
✅ Deploy Preview for wot-design-uni ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/uni_modules/wot-design-uni/components/wd-calendar/wd-calendar.vue (2)
155-163: 跨年周选择的年份计算逻辑正确!代码正确处理了跨年周的情况,通过比较周末日期的年份来确保显示正确的年份。
建议优化:可以使用 dayjs 来简化日期计算逻辑,减少重复的 Date 对象创建:
- const date = new Date(value as number) - const year = date.getFullYear() - const week = getWeekNumber(value as number) - const weekStart = new Date(date) - weekStart.setDate(date.getDate() - date.getDay() + 1) - const weekEnd = new Date(date) - weekEnd.setDate(date.getDate() + (7 - date.getDay())) - const adjustedYear = weekEnd.getFullYear() > year ? weekEnd.getFullYear() : year + const date = dayjs(value as number) + const year = date.year() + const week = getWeekNumber(value as number) + const weekEnd = date.endOf('week') + const adjustedYear = weekEnd.year() > year ? weekEnd.year() : year
166-184: 周范围选择的年份计算逻辑完善!代码正确处理了范围选择中的跨年周情况,对起始和结束日期分别进行了年份调整。
建议优化:同样可以使用 dayjs 来简化日期计算逻辑:
- const date1 = new Date((value as number[])[0]) - const date2 = new Date((value as number[])[1]) - const year1 = date1.getFullYear() - const year2 = date2.getFullYear() - const week1 = getWeekNumber((value as number[])[0]) - const week2 = getWeekNumber((value as number[])[1]) - const weekStart1 = new Date(date1) - weekStart1.setDate(date1.getDate() - date1.getDay() + 1) - const weekEnd1 = new Date(date1) - weekEnd1.setDate(date1.getDate() + (7 - date1.getDay())) - const weekStart2 = new Date(date2) - weekStart2.setDate(date2.getDate() - date2.getDay() + 1) - const weekEnd2 = new Date(date2) - weekEnd2.setDate(date2.getDate() + (7 - date2.getDay())) - const adjustedYear1 = weekEnd1.getFullYear() > year1 ? weekEnd1.getFullYear() : year1 - const adjustedYear2 = weekEnd2.getFullYear() > year2 ? weekEnd2.getFullYear() : year2 + const date1 = dayjs((value as number[])[0]) + const date2 = dayjs((value as number[])[1]) + const year1 = date1.year() + const year2 = date2.year() + const week1 = getWeekNumber((value as number[])[0]) + const week2 = getWeekNumber((value as number[])[1]) + const weekEnd1 = date1.endOf('week') + const weekEnd2 = date2.endOf('week') + const adjustedYear1 = weekEnd1.year() > year1 ? weekEnd1.year() : year1 + const adjustedYear2 = weekEnd2.year() > year2 ? weekEnd2.year() : year2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/uni_modules/wot-design-uni/components/wd-calendar/wd-calendar.vue(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Cloudflare Pages
🔇 Additional comments (1)
src/uni_modules/wot-design-uni/components/wd-calendar/wd-calendar.vue (1)
Line range hint
4-6: 建议添加跨年周选择的测试用例为确保跨年周选择的显示始终正确,建议添加以下测试场景:
- 单周选择跨年的情况(如:2024-12-29 到 2025-01-04)
- 周范围选择跨年的情况
- 边界情况测试(如:年末最后一周、年初第一周)
可以通过以下命令查找现有的测试文件:
🤔 这个 PR 的性质是?(至少选择一个)
🔗 相关 Issue
💡 需求背景和解决方案
Calendar 日历选择器,周选择时跨年周显示标题异常,例如2025年第一周,显示为了2024第一周,因为这一周的第一天在2024年
☑️ 请求合并前的自查清单
Summary by CodeRabbit