Skip to content

feat(calendar): 支持阴历、阳历类型 (#717)⁠#902

Merged
zflyluo merged 10 commits intoTencent:developfrom
jamesliauw8-rgb:feature/calendar-lunar-support
Mar 30, 2026
Merged

feat(calendar): 支持阴历、阳历类型 (#717)⁠#902
zflyluo merged 10 commits intoTencent:developfrom
jamesliauw8-rgb:feature/calendar-lunar-support

Conversation

@jamesliauw8-rgb
Copy link
Copy Markdown

@jamesliauw8-rgb jamesliauw8-rgb commented Mar 21, 2026

🤔 这个 PR 的性质是?

勾选规则:
1.只要有新增参数,就勾选”新特性提交“
2.只修改内部bug,未新增参数,才勾选”日常 bug 修复“
3.其他选项视具体改动判断

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

🔗 相关 Issue

Closes #717

💡 需求背景和解决方案

1. 新增参数(3个)

参数 类型 默认值 说明
dateType TDCalendarDateType solar 日历类型:阳历或农历
dataSource TDCalendarDataSource? null 外部数据源,提供农历转换等功能
showLunarInfo bool false 阳历模式下是否显示农历信息

2. 数据源接口

定义 TDCalendarDataSource 抽象接口,支持:

  • ✅ 农历转换(getLunarInfo
  • ✅ 日期格式化(formatDate
  • ✅ 节气查询(getSolarTerm,可选)
  • ✅ 节日查询(getFestival,可选)
  • ✅ 假期查询(getHolidayInfo,可选)

设计原则

  • ✅ 组件库只定义接口,不封装具体实现
  • ✅ 示例实现在 example 项目中
  • ✅ 用户可以自定义数据源(API、数据库等)

3. 示例实现

example/lib/lunar_data_source_example.dart 中提供基于 lunar: ^1.7.8 包的示例实现。

4. 显示效果

阳历模式(dateType = solar)

┌─────────┐
│    7    │  ← 主标题(阳历日期)
│ 三月初七 │  ← 副标题(农历信息)
└─────────┘

农历模式(dateType = lunar)

┌─────────┐
│  初七   │  ← 主标题(农历日期)
│2025-3-21│  ← 副标题(阳历日期)
└─────────┘

扩展信息显示优先级

  1. 节日(春节、国庆节等)
  2. 节气(春分、秋分等)
  3. 农历日期

📝 更新日志

使用示例

基础用法

// 1. 纯阳历(默认行为,向后兼容)
TDCalendar(
  title: '选择日期',
  type: CalendarType.single,
)

// 2. 阳历 + 农历副标题
TDCalendar(
  title: '选择日期',
  showLunarInfo: true,
  dataSource: LunarDataSourceExample(),
)

// 3. 纯农历
TDCalendar(
  title: '选择日期',
  dateType: TDCalendarDateType.lunar,
  dataSource: LunarDataSourceExample(),
)

自定义数据源

// 用户可以实现自定义数据源
class MyDataSource implements TDCalendarDataSource {
  @override
  TDLunarInfo? getLunarInfo(DateTime solarDate) {
    // 调用自己的 API 或使用自己的算法
    return _fetchFromMyApi(solarDate);
  }
  
  @override
  String formatDate(DateTime date, TDCalendarDateType type, [TDLunarInfo? lunarInfo]) {
    // 自定义格式化逻辑
  }
  
  // ... 其他方法
}

TDCalendar(
  showLunarInfo: true,
  dataSource: MyDataSource(),  // 使用自定义数据源
)

测试说明

运行示例

cd tdesign-component/example
flutter pub get
flutter run -d chrome

访问 http://localhost:9000,选择 "Calendar 日历",可以看到:

  1. 农历功能按钮(显示/隐藏农历)
  2. 日历类型切换(阳历/农历)
  3. 点击日期查看详细信息(阳历、农历、节气、节日、假期)
  • fix(组件名称): 处理问题或特性描述 ...

  • 本条 PR 不需要纳入 Changelog

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

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

  • pr目标分支为develop分支,请勿直接往main分支合并
  • 标题格式为:组件类名: 修改描述(示例:TDBottomTabBar: 修复iconText模式,底部溢出2.5像素)
  • ”相关issue“处带上修复的issue链接
  • 相关文档已补充或无须补充

williamliao added 6 commits March 21, 2026 11:07
- 新增 TDCalendarDateType 枚举支持阳历/农历切换
- 新增 TDCalendarDataSource 接口供外部实现农历转换
- 新增 showLunarInfo 参数支持阳历模式下显示农历副标题
- 完全向后兼容,不影响现有 API
- 包含完整测试用例和示例代码

Close Tencent#717
- 修改 TDCalendar 添加 dateType, dataSource, showLunarInfo 参数
- 修改 TDCalendarBody 支持数据源并注入农历信息到 TDate
- 修改 TDCalendarCell 实现农历显示逻辑
- TDate 新增 lunarInfo 字段存储农历信息
- 完全向后兼容,默认参数保持原有行为
修正 _buildDefaultCell 方法中的类型错误,使用正确的 TDCalendarStyle 类型
@tencent-adm
Copy link
Copy Markdown
Member

tencent-adm commented Mar 21, 2026

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 3 committers have signed the CLA.

✅ Luozf12345
❌ williamliao
❌ autofix-ci[bot]


williamliao seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 24, 2026

完成

📱 APK 下载

tdesign-flutter-0.2.7-425.apk

@zflyluo zflyluo merged commit 7f597ab into Tencent:develop Mar 30, 2026
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[TDCalendar] 支持阴历、阳历类型

4 participants