Skip to content

Conversation

@shumuuu
Copy link
Contributor

@shumuuu shumuuu commented Nov 1, 2025

🤔 这个 PR 的性质是?

  • 日常 bug 修复
  • 新特性提交
  • 文档改进
  • 演示代码改进
  • 组件样式/交互改进
  • CI/CD 改进
  • 重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 其他

🔗 相关 Issue

💡 需求背景和解决方案

代码缺陷

其一,组件源码中的月份禁用选项生成依据仅为先起始年份后终止年份的单侧判断

// src\calendar\calendar.tsx L540~546
if (year === beginYear) {
  const beginMon = parseInt(dayjs(this.rangeFromTo.from).format('M'), 10);
  disabled = month < beginMon;
} else if (year === endYear) {
  const endMon = parseInt(dayjs(this.rangeFromTo.to).format('M'), 10);
  disabled = month > endMon;
}

只有在切换年份时才会触发月份的禁用选项更新。当起止年份相同时(假定为2025年),若年份选中2025年,以上逻辑仅会判断当前选中项与起始年份相同然后禁用起始月份之前的月份选项,而忽略对终止月份之后的月份选项的禁用

这个问题在web端三个技术栈的仓库中均存在,应该是逻辑复用的问题
tdesign-vue-next #6045

其二,生成年份选项时多余且错误地调用了checkMonthAndYearSelectorDisabled函数来判断年份选项的禁用状态。年份选项生成一定在范围内,无需额外编写禁用状态逻辑;且checkMonthAndYearSelectorDisabled函数是用于月份选项禁用范围的判定,用于年份选项会导致实际可选择范围异常

// src\calendar\calendar.tsx L208~215
for (let i = begin; i <= end; i++) {
  const disabled = this.checkMonthAndYearSelectorDisabled(i, this.curSelectedMonth);
  re.push({
    value: i,
    label: this.t(this.global.yearSelection, { year: i }),
    disabled,
  });
}

解决方案

其一

// src\calendar\calendar.tsx L537~551
// 读取起止年份
const beginYear = dayjs(this.rangeFromTo.from).year();
const endYear = dayjs(this.rangeFromTo.to).year();
// 读取起止月份
const beginMon = parseInt(dayjs(this.rangeFromTo.from).format('M'), 10);
const endMon = parseInt(dayjs(this.rangeFromTo.to).format('M'), 10);

if (beginYear === endYear) {
  // 同一年内,禁用开始月份至结束月份之外的月份选项
  disabled = month < beginMon || month > endMon;
} else if (year === beginYear) {
  disabled = month < beginMon;
} else if (year === endYear) {
  disabled = month > endMon;
}

将可复用的月份处理逻辑提前,然后在单侧判断之前增加一个分支逻辑判断起止年份是否相同,相同的话将禁用的月份选项设定为在起止月份之外的即可

其二,删去多余的禁用状态逻辑,固定启用所有年份选项

3539221cda17773005408a756aa13f29

📝 更新日志

  • fix(calendar): 修复了当设定日历的range值为同一年内时,终止月份之后的月份选项没有正常禁用的问题

  • fix(calendar): 修复了年份选项错误地使用了月份选项禁用范围判定逻辑的问题

  • 本条 PR 不需要纳入 Changelog

☑️ 请求合并前的自查清单

⚠️ 请自检并全部勾选全部选项⚠️

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充
  • Changelog 已提供或无须提供

@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 6, 2025

tdesign-vue2-demo-compiler-2-6

npm i https://pkg.pr.new/tdesign-vue@3759

commit: 991a36f

@github-actions
Copy link
Contributor

github-actions bot commented Nov 6, 2025

完成

@uyarn uyarn merged commit a072b7e into Tencent:develop Nov 6, 2025
10 checks passed
@shumuuu shumuuu deleted the fix/calendar branch November 6, 2025 03:11
@github-actions github-actions bot mentioned this pull request Nov 7, 2025
16 tasks
uyarn pushed a commit that referenced this pull request Nov 10, 2025
* fix(calendar): 修复了当设定日历的range值为同一年内时,终止月份之后的月份选项没有正常禁用的问题

* fix(calendar): 修正了错误使用的rangeFromTo

* fix(calendar): 修复了年份选项错误地使用了月份选项禁用范围判定逻辑的问题

Co-Authored-By: 刘宇轩 (刘lyxAndy) <admin@liulyxandy.cn>

---------

Co-authored-by: 刘宇轩 (刘lyxAndy) <admin@liulyxandy.cn>
uyarn added a commit that referenced this pull request Nov 10, 2025
* feat(Watermark): support layout API (#3726)

* feat: support layout

* chore: update snapshot

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* chore: merge deploy mode (#3728)

* chore(submodule): update common (#3736)

* chore(submodule): update common

* chore: fix typos

---------

Co-authored-by: 黎伟杰 <674416404@qq.com>

* chore: add static prefix (#3737)

* fix(Tabs): disable drag event registration in non-drag scenarios (#3738)

* fix(textarea): add hide scrollbar when autosize is true (#3727)

* fix(textarea): 修复内容超长情况下,设置 autosize 没有完整自动撑开高度,存在有滚动条的问题

fix #5567

* chore: update snapshot

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* fix(tabs): 示例文档文案错误 (#3741)

* chore(submodule): update common (#3743)

* fix(calendar): fix calendar range issues (#3759)

* fix(calendar): 修复了当设定日历的range值为同一年内时,终止月份之后的月份选项没有正常禁用的问题

* fix(calendar): 修正了错误使用的rangeFromTo

* fix(calendar): 修复了年份选项错误地使用了月份选项禁用范围判定逻辑的问题

Co-Authored-By: 刘宇轩 (刘lyxAndy) <admin@liulyxandy.cn>

---------

Co-authored-by: 刘宇轩 (刘lyxAndy) <admin@liulyxandy.cn>

* fix(menu): fix menu item auto-flip failure (#3744)

* fix(popup): force update popper after animation completes

* fix(popup): 支持自定义 popper 内容元素类型

* fix(popup): 修复 popperContentElement 的类型处理逻辑

* fix(popup): 添加 popperContentElement 的类型定义

* fix(popup): 修复 popperContentElement 的类型处理,确保正确类型转换

* feat(cascader): support parent node filtering (#3763)

* feat(cascader): support parentnode filtering

* chore: demo

* chore: update snapshot

* chore: docs

* chore: docs

* chore: release 1.14.2 (#3764)

* chore: release 1.14.2

* chore: changelog's changes

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* chore: update snapshot

* chore: release 1.14.2-naruto

* chore: fix typo

* chore: update common

---------

Co-authored-by: Wesley <985189328@qq.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: TDesign bot <93915689+tdesign-bot@users.noreply.github.com>
Co-authored-by: 黎伟杰 <674416404@qq.com>
Co-authored-by: 阿菜 Cai <jimmyrss1102@gmail.com>
Co-authored-by: engvuchen <31369318+engvuchen@users.noreply.github.com>
Co-authored-by: 树林 <122286562+shumuuu@users.noreply.github.com>
Co-authored-by: 刘宇轩 (刘lyxAndy) <admin@liulyxandy.cn>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants