Skip to content

Conversation

@lin-qingying
Copy link

@lin-qingying lin-qingying commented Aug 27, 2025

为Calendar和CalendarView增加季度选择

BREAKING CHANGE: 🧨 季度选择器

Closes: #1247

🤔 这个 PR 的性质是?(至少选择一个)

  • 日常 bug 修复
  • 新特性提交
  • 站点、文档改进
  • 演示代码改进
  • 组件样式/交互改进
  • TypeScript 定义更新
  • CI/CD 改进
  • 包体积优化
  • 性能优化
  • 功能增强
  • 国际化改进
  • 代码重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 其他改动(是关于什么的改动?)

🔗 相关 Issue

1247

💡 需求背景和解决方案

<wd-calendar type="quarter" v-model="value" @confirm="handleConfirm" />

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

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

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

Summary by CodeRabbit

  • 新功能
    • 日历与日历视图支持“季度/季度范围”选择,并提供新的季度面板与显示格式;示例页新增对应交互。
  • 国际化
    • 多语言新增季度相关文案与格式化(包含中英及多语种)。
  • 文档
    • 新增“季度选择”章节;范围类型新增 quarterrange;标注 use-default-slot、use-label-slot 为弃用。
  • 样式
    • 新增季度视图样式与可配置的季度宽度变量。

为Calendar和CalendarView增加季度选择

BREAKING CHANGE: 🧨 季度选择器

✅ Closes: Moonofweisheng#1247
@vercel
Copy link

vercel bot commented Aug 27, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
wot-design-uni Ready Ready Preview Comment Aug 27, 2025 7:01am

@netlify
Copy link

netlify bot commented Aug 27, 2025

Deploy Preview for wot-design-uni ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit ed4bd49
🔍 Latest deploy log https://app.netlify.com/projects/wot-design-uni/deploys/68aeacff0324670008e97a3c
😎 Deploy Preview https://deploy-preview-1248--wot-design-uni.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link

coderabbitai bot commented Aug 27, 2025

Walkthrough

本次变更为日历与日历视图新增“季度/季度范围”类型与展示:扩展类型定义与工具函数;引入 Quarter/QuarterPanel 组件与样式;在 wd-calendar-view 中注册新面板并路由;wd-calendar 增加季度与季度范围的显示格式;新增多语言文案;更新示例与文档。

Changes

Cohort / File(s) Summary
Docs: Calendar & CalendarView (ZH/EN)
docs/component/calendar.md, docs/component/calendar-view.md, docs/en-US/component/calendar.md, docs/en-US/component/calendar-view.md
文档新增 type="quarter"/"quarterrange" 说明与示例;属性表扩充;范围类型加入 quarterrange;标记 use-default-slot、use-label-slot 为弃用(文档)。
Demo Pages
src/subPages/calendar/Index.vue, src/subPages/calendarView/Index.vue
示例页新增季度与季度范围控件与对应状态值;在选择器中加入 quarter/quarterrange 选项。
Calendar View: Types & Utils & Integration
src/uni_modules/wot-design-uni/components/wd-calendar-view/types.ts, .../utils.ts, .../wd-calendar-view.vue
扩展 CalendarType 加入 'quarter'/'quarterrange';新增季度比较/偏移/差值工具;在视图中集成 QuarterPanel 并按类型路由到对应面板。
Calendar View: Quarter Feature
.../wd-calendar-view/quarter/quarter.vue, .../wd-calendar-view/quarter/types.ts, .../wd-calendar-view/quarter/index.scss, .../wd-calendar-view/quarterPanel/quarter-panel.vue, .../wd-calendar-view/quarterPanel/types.ts, .../wd-calendar-view/quarterPanel/index.scss
新增季度单选/范围选择组件与季度面板组件、对应 props、交互与样式(含区间 start/end/middle/same 状态、深色主题)。
Calendar Component Display
src/uni_modules/wot-design-uni/components/wd-calendar/wd-calendar.vue
defaultDisplayFormat 支持 'quarter' 与 'quarterrange' 的显示格式与区间占位处理。
Dayjs Extension
src/uni_modules/wot-design-uni/dayjs/index.js, .../index.d.ts
新增 Dayjs.prototype.quarter(quarter?) API 及类型声明;其余为样式化与组织调整。
Locales (runtime)
src/uni_modules/wot-design-uni/locale/lang/*.ts
各语言新增 calendar.quarter、quarterFormat、startQuarter、endQuarter(zh-CN 另新增 endMonth)。
Locales (docs demo)
src/locale/en-US.json, src/locale/zh-CN.json
新增“季度选择/季度范围选择”文案键。
Styles: Tokens
src/uni_modules/wot-design-uni/components/common/abstracts/variable.scss
新增 $-calendar-quarter-width 及对应 CSS 自定义属性。

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User as 用户
  participant Cal as wd-calendar
  participant View as wd-calendar-view
  participant QP as QuarterPanel
  participant Q as Quarter
  participant I18n as Locale

  User->>Cal: 设置 type="quarter"/"quarterrange"\n(v-model)
  Cal->>View: 传递 type/value/minDate/maxDate/formatter...
  View->>QP: 当 type 含 quarter 时渲染 QuarterPanel
  QP->>Q: 渲染年度季度列表(四季度单元)
  User->>Q: 点击季度(或区间起止)
  Q-->>QP: emit change({ value })
  QP-->>View: 转发 change({ value })
  View-->>Cal: 转发 change/confirm 流程
  Cal->>I18n: defaultDisplayFormat 获取 quarter 文案
  I18n-->>Cal: 格式化 "YYYY Qn"/区间文案
  Cal-->>User: 更新显示/回调
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Assessment against linked issues

Objective Addressed Explanation
为 Calendar 与 CalendarView 增加季度选择(#1247
提供 <wd-calendar type="quarter" v-model="value" @confirm="handleConfirm" /> 形式的 API(#1247 wd-calendar-view 与显示格式已支持 quarter/quarterrange,但未见本次变更中对 @confirm 的专门调整;推测复用既有 confirm。

Assessment against linked issues: Out-of-scope changes

Code Change Explanation
标记文档属性 use-default-slot、use-label-slot 为弃用(docs/component/calendar.md L…) 该弃用与“新增季度选择”无直接关联,属于文档范围的独立变更。
新增 zh-CN 本地化键 calendar.endMonth(src/uni_modules/wot-design-uni/locale/lang/zh-CN.ts L…) endMonth 与季度功能无直接关系,可能是顺带补充,不在本议题目标内。

Possibly related PRs

Suggested reviewers

  • Moonofweisheng

Poem

小兔跃上时光梭,蹦到季度的枝头多~
Q1 Q2 连成河,Q3 Q4 风吹过。
面板翻页如清波,范围起止不啰嗦。
今日打卡新选择,咔嗒一按喜乐多! 🐰📅

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 7

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (5)
src/uni_modules/wot-design-uni/locale/lang/vi-VN.ts (1)

41-44: 补充 rangePromptQuarter 本地化提示

经脚本验证,所有 src/uni_modules/wot-design-uni/locale/lang 下的语言文件在 calendarView 均缺少 rangePromptQuarter,会导致选择“季度范围”时回退或显示空文案。请在各语言文件的 calendarView 中按以下示例添加对应提示。

待更新位置:

  • src/uni_modules/wot-design-uni/locale/lang/vi-VN.ts(第 41–44 行附近)
  • 其他所有 locale/lang/*.ts 文件中的 calendarView 区块

示例 diff(以 vi-VN.ts 为例):

   calendarView: {
     startTime: 'Bắt đầu',
     endTime: 'Kết thúc',
     weeks: { sun: 'CN', mon: 'T2', tue: 'T3', wed: 'T4', thu: 'T5', fri: 'T6', sat: 'T7' },
     rangePrompt: (maxRange: number) => `Không thể chọn quá ${maxRange} ngày`,
     rangePromptWeek: (maxRange: number) => `Không thể chọn quá ${maxRange} tuần`,
     rangePromptMonth: (maxRange: number) => `Không thể chọn quá ${maxRange} tháng`,
+    rangePromptQuarter: (maxRange: number) => `Không thể chọn quá ${maxRange} quý`,
     monthTitle: 'Tháng YYYY M',

请同步更新所有语言文件,确保多语言体验一致。

docs/component/calendar-view.md (1)

248-265: Attributes 表的 type 可选值未同步新增 quarter/quarterrange

文档与新增能力不一致,属于对外文档准确性问题,请尽快修正。

建议改动(第 251 行):

-| type              | 日期类型                                                                                                                                                                                           | string                | date / dates / datetime / week / month / daterange / datetimerange / weekrange / monthrange | date                  | -        |
+| type              | 日期类型                                                                                                                                                                                           | string                | date / dates / datetime / week / month / quarter / daterange / datetimerange / weekrange / monthrange / quarterrange | date                  | -        |
src/uni_modules/wot-design-uni/components/wd-calendar/wd-calendar.vue (2)

221-247: formatRange 未处理 quarterrange,导致占位文案显示为 undefined

currentType==='quarterrange' 且起止为空时,formatRange 返回 undefined,UI 会直出 “undefined”。需补齐分支。

建议补丁:

   case 'monthrange':
     if (!value) {
       return rangeType === 'end' ? translate('endMonth') : translate('startMonth')
     }
     return dayjs(value).format(translate('monthFormat'))
+  case 'quarterrange': {
+    if (!value) {
+      return rangeType === 'end' ? translate('endQuarter') : translate('startQuarter')
+    }
+    const date = new Date(value)
+    const year = date.getFullYear()
+    const quarter = Math.floor(date.getMonth() / 3) + 1
+    return translate('quarterFormat', year, quarter)
+  }

303-316: showTypeSwitch 与季度类型的索引回退不健壮(quarter/quarterrange 会得到 -1)

当外部传入 type='quarter'|'quarterrange' 且开启 showTypeSwitch,当前索引可能为 -1,造成 Tabs 高亮与线条计算异常。建议对未命中类型回退到 0。

建议补丁:

-    if (props.showTypeSwitch) {
-      const tabs = ['date', 'week', 'month']
-      const rangeTabs = ['daterange', 'weekrange', 'monthrange']
-
-      const index = newValue.indexOf('range') > -1 ? rangeTabs.indexOf(newValue) || 0 : tabs.indexOf(newValue)
-      currentTab.value = index
-    }
+    if (props.showTypeSwitch) {
+      const tabs = ['date', 'week', 'month']
+      const rangeTabs = ['daterange', 'weekrange', 'monthrange']
+      const rawIndex = newValue.indexOf('range') > -1 ? rangeTabs.indexOf(newValue) : tabs.indexOf(newValue)
+      currentTab.value = rawIndex >= 0 ? rawIndex : 0
+    }

如需完全支持季度在 Tab 切换中出现,可另行扩展 UI 与 tabs 列表,这里先保证健壮性。

src/subPages/calendar/Index.vue (1)

24-25: 模板里出现孤立的 const 语句,属于语法错误,需移除

这两行在模板中无效且会造成编译错误,请删除。

-          const
+          
...
-          const
+          

Also applies to: 31-32

🧹 Nitpick comments (44)
src/uni_modules/wot-design-uni/locale/lang/vi-VN.ts (1)

28-28: quarterFormat 语义与 weekFormat 对齐,输出自然

Quý ${quarter} năm ${year} 符合越南语表述,参数顺序与 weekFormat(year, week) 一致。若后续需要短格式(如“Q1 2025”),建议新增独立键(如 quarterShortFormat)以避免破坏现有用法。

src/uni_modules/wot-design-uni/locale/lang/th-TH.ts (1)

21-22: 文案语序不一致,建议与“周”保持动词在前的一致风格

当前为「ไตรมาสเริ่มต้น」(名词在前) 与「สิ้นสุดไตรมาส」(动词在前),建议统一为动词在前:

-    startQuarter: 'ไตรมาสเริ่มต้น',
+    startQuarter: 'เริ่มต้นไตรมาส',
src/uni_modules/wot-design-uni/locale/lang/ug-CN.ts (3)

12-12: 术语校正建议:将“quarter”译为“چەرەك”而非“چوڭ پەسىل”。

“پەسىل”更接近“季节”,易与“季度”混淆;常见用法为“چەرەك”。请与维语母语者或既有术语库核实。

可选改动:

-    quarter: 'چوڭ پەسىل',
+    quarter: 'چەرەك',

20-20: 格式一致性:quarterFormat 建议与 week/month 对齐。

当前为“${year}يىلى ${quarter}چوڭ پەسىل”。建议使用“چەرەك”,或采用“Q${quarter}”样式,与其他语言保持统一。

两种候选(择一):

-    quarterFormat: (year: number, quarter: number) => `${year}يىلى ${quarter}چوڭ پەسىل`,
+    quarterFormat: (year: number, quarter: number) => `${year}يىلى ${quarter}چەرەك`,
-    quarterFormat: (year: number, quarter: number) => `${year}يىلى ${quarter}چوڭ پەسىل`,
+    quarterFormat: (year: number, quarter: number) => `${year}يىلى Q${quarter}`,

25-26: 词形/命名一致性:startQuarter/endQuarter 建议与 week/month 保持后缀用法一致。

建议采用“چەرەكى”作后缀(对应 startWeek 的“…ھەپتىسى”、startMonth 的“…ئېيى”风格)。

-    startQuarter: 'باشلىنىش چوڭ پەسىلى',
-    endQuarter: 'ئاخىرلىشىش چوڭ پەسىلى',
+    startQuarter: 'باشلىنىش چەرەكى',
+    endQuarter: 'ئاخىرلىشىش چەرەكى',
src/uni_modules/wot-design-uni/components/common/abstracts/variable.scss (1)

223-224: 可选:季度宽度默认回落到月份宽度,避免双处维护

让季度宽度的默认值继承月份宽度,保持一致性与可控性。

-$-calendar-quarter-width: var(--wot-calendar-quarter-width, 50px) !default;
+$-calendar-quarter-width: var(--wot-calendar-quarter-width, $-calendar-month-width) !default;
src/uni_modules/wot-design-uni/components/wd-calendar-view/types.ts (1)

4-15: 补充 rangePromptQuarter 到各语言 locale

  • 已确认 quarter.vue 在超出 maxRange 时,优先调用 translate('rangePromptQuarter', props.maxRange),并正确接入了基于 maxRange 的校验逻辑
  • allowSameDay 在季度范围(quarterrange)场景中并未暴露,也不会影响当前逻辑,保持忽略状态符合预期
  • 请在 src/uni_modules/wot-design-uni/locale/lang/*.tscalendarView 下,为每种语言新增如下键值,并与已有的 rangePromptWeek/rangePromptMonth 文案风格保持一致:
    rangePromptQuarter: (maxRange: number) => `选择季度不能超过 ${maxRange} 个季度`,
  • 补齐以上多语言文案后,运行时即可自动使用该键,缺失时才回退到通用 rangePrompt
src/uni_modules/wot-design-uni/locale/lang/ko-KR.ts (1)

8-22: 韩语本地化新增项对齐到位;建议补充季度范围提示键

已新增 quarter/quarterFormat/startQuarter/endQuarter,建议在 calendarView 增加季度范围提示以与周/月保持一致:

// 建议在 calendarView 中与 rangePromptWeek/Month 同级新增
rangePromptQuarter: (maxRange: number) => `최대 ${maxRange}분기까지 선택할 수 있습니다`,

需要的话我可以批量为所有语言包追加该键并提交补丁。

src/uni_modules/wot-design-uni/locale/lang/ru-RU.ts (1)

8-22: 俄语本地化新增项完善;建议同步季度范围提示键

quarter/quarterFormat/startQuarter/endQuarter 已补充。为与周/月一致,建议在 calendarView 增加:

rangePromptQuarter: (maxRange: number) => `Выбор не должен превышать ${maxRange} квартала`,

(与现有 “месяца/недели” 的用法保持同一风格)

src/uni_modules/wot-design-uni/locale/lang/pt-PT.ts (2)

16-16: quarterFormat 更贴近葡语表达的小改动

葡语常见写法为“第 N 季度(N.º trimestre) de YYYY”。建议微调:

-    quarterFormat: (year: number, quarter: number) => `${year} Trimestre ${quarter}`,
+    quarterFormat: (year: number, quarter: number) => `${quarter}.º trimestre de ${year}`,

8-22: 补充季度范围提示键以与周/月一致

在 calendarView 与 rangePromptWeek/Month 同级增加:

rangePromptQuarter: (maxRange: number) => `Não pode selecionar mais que ${maxRange} trimestres`,
src/uni_modules/wot-design-uni/locale/lang/zh-TW.ts (2)

16-16: 臺灣在地化用詞微調建議(「季度」→「季」)

繁体中文(臺灣)更常用「季」。建议如下:

-    quarter: '季度',
+    quarter: '季',
-    quarterFormat: (year: number, quarter: number) => `${year} 第 ${quarter} 季度`,
+    quarterFormat: (year: number, quarter: number) => `${year} 第 ${quarter} 季`,
-    startQuarter: '開始季度',
-    endQuarter: '結束季度',
+    startQuarter: '開始季',
+    endQuarter: '結束季',

Also applies to: 24-24, 29-30


33-46: 补充季度范围提示键以与周/月一致

建议在 calendarView 与 “選擇月份不能超過…” 同级增加:

rangePromptQuarter: (maxRange: number) => `選擇季度不能超過${maxRange} 個季度`,

如采纳上文“季”的用词,可相应调整为「不能超過${maxRange} 個季」。

src/uni_modules/wot-design-uni/locale/lang/tr-TR.ts (2)

21-27: 为季度范围补充提示文案,保持与周/月一致

当前仅有天/周/月的范围越界提示,建议新增季度范围提示键以便 quarterrange 复用。

   rangePromptMonth: (maxRange: number) => `Seçilen ay sayısı ${maxRange} ayı geçemez`,
+  rangePromptQuarter: (maxRange: number) => `Seçilen çeyrek sayısı ${maxRange} çeyreği geçemez`,

26-27: 土耳其语属格更自然的表述(可选)

“Başlangıç çeyrek / Bitiş çeyrek”直译略生硬,可考虑“Başlangıç Çeyreği / Bitiş Çeyreği”。与既有“Başlangıç hafta”保持一致也可不改。

src/uni_modules/wot-design-uni/locale/lang/zh-CN.ts (1)

20-27: 为季度范围补充提示文案,保持与周/月一致

新增 quarter/quarterrange 后建议同步提供“rangePromptQuarter”以统一交互提示。

   rangePromptMonth: (maxRange: number) => `选择月份不能超过${maxRange}个月`,
+  rangePromptQuarter: (maxRange: number) => `选择季度不能超过${maxRange}个季度`,
src/uni_modules/wot-design-uni/locale/lang/es-ES.ts (1)

16-22: 添加“范围-季度”提示以覆盖 quarterrange 用例

与 días/semanas/meses 一致,建议补充 trimestres 的范围提示。

   rangePromptMonth: (maxRange: number) => `No se puede seleccionar más de ${maxRange} meses`,
+  rangePromptQuarter: (maxRange: number) => `No se puede seleccionar más de ${maxRange} trimestres`,
src/uni_modules/wot-design-uni/dayjs/index.js (4)

341-426: (可选)为格式化增加 Q token

若有“YYYY-[Q]Q”等格式化需求,可增加匹配 'Q' 返回当前季度。若无此需求可忽略。

       switch (match) {
+        case 'Q':
+          return String(_this3.quarter())

498-504: quarter(quarter) 建议做入参校验与限制

避免传入 <1 或 >4 时跨年溢出月值导致意外行为。可夹取到 [1,4] 或抛错;下方示例为夹取。

-_proto.quarter = function (quarter) {
-  if (!this.$utils().u(quarter)) {
-    return this.month((this.month() % 3) + (quarter - 1) * 3)
-  }
+_proto.quarter = function (quarter) {
+  if (!this.$utils().u(quarter)) {
+    const q = Math.min(4, Math.max(1, Number(quarter)))
+    return this.month((this.month() % 3) + (q - 1) * 3)
+  }
   return Math.ceil((this.month() + 1) / 3)
 }

160-164: Biome 命名告警:valueOf 重名(建议抑制)

此处与原生 API 同名属预期设计。为满足 Biome,可局部忽略。

-_proto.valueOf = function valueOf() {
+/* biome-ignore lint/suspicious/noShadowRestrictedNames: 同名以对齐原生 API */
+_proto.valueOf = function valueOf() {

531-534: Biome 命名告警:toString 重名(建议抑制)

同上,建议加忽略注释以消除 Biome 报警。

-_proto.toString = function toString() {
+/* biome-ignore lint/suspicious/noShadowRestrictedNames: 同名以对齐原生 API */
+_proto.toString = function toString() {
src/uni_modules/wot-design-uni/locale/lang/zh-HK.ts (1)

20-26: 为季度范围补充提示文案,保持与週/月一致

支持 quarterrange 时建议新增“rangePromptQuarter”键。

   rangePromptMonth: (maxRange: number) => `選擇月份不能超過${maxRange}個月`,
+  rangePromptQuarter: (maxRange: number) => `選擇季度不能超過${maxRange}個季度`,
src/uni_modules/wot-design-uni/locale/lang/de-DE.ts (1)

8-8: 德语季度文案小幅本地化优化建议

  • 更自然的德语季度格式通常写作“{季度}. Quartal {年}”。建议微调 quarterFormat。其余新增键无功能性问题。
-    quarterFormat: (year: number, quarter: number) => `Quartal ${quarter} ${year}`,
+    quarterFormat: (year: number, quarter: number) => `${quarter}. Quartal ${year}`,

备注:Start/End 可保留为 “Startquartal/Endquartal” 以与其他语言键一致;若追求更地道,可考虑 “Beginn des Quartals/Ende des Quartals”(仅风格建议)。

Also applies to: 16-16, 21-22

src/uni_modules/wot-design-uni/locale/lang/fr-FR.ts (1)

8-8: 法语季度格式更贴近惯例

  • 常见写法为 “{year} T{quarter}” 或 “{quarter}e trimestre {year}”。当前实现可读但略不典型。

任选其一(推荐 A 与 en 保持一致的紧凑格式):

-    quarterFormat: (year: number, quarter: number) => `Trimestre ${quarter}, ${year}`,
+    quarterFormat: (year: number, quarter: number) => `${year} T${quarter}`,

-    quarterFormat: (year: number, quarter: number) => `Trimestre ${quarter}, ${year}`,
+    quarterFormat: (year: number, quarter: number) => `${quarter}e trimestre ${year}`,

Also applies to: 16-16, 21-22

src/uni_modules/wot-design-uni/components/wd-calendar-view/utils.ts (4)

75-96: compareQuarter 可直接使用 dayjs.quarter() 简化并与全局扩展保持一致

  • 逻辑正确,但既已引入 dayjs 的 quarter 扩展,建议复用以减少重复实现与潜在偏差。
-export function compareQuarter(date1: number, date2: number): number {
-  const getQuarter = (date: Date): number => Math.floor(date.getMonth() / 3) + 1
-
-  const d1 = new Date(date1)
-  const d2 = new Date(date2)
-
-  const year1 = d1.getFullYear()
-  const year2 = d2.getFullYear()
-  const quarter1 = getQuarter(d1)
-  const quarter2 = getQuarter(d2)
-
-  if (year1 === year2 && quarter1 === quarter2) return 0
-
-  // 先比较年份,再比较季度
-  return year1 > year2 || (year1 === year2 && quarter1 > quarter2) ? 1 : -1
-}
+export function compareQuarter(date1: number, date2: number): number {
+  const y1 = dayjs(date1).year()
+  const y2 = dayjs(date2).year()
+  const q1 = dayjs(date1).quarter()
+  const q2 = dayjs(date2).quarter()
+  if (y1 === y2 && q1 === q2) return 0
+  return y1 > y2 || (y1 === y2 && q1 > q2) ? 1 : -1
+}

251-267: 季度偏移在月底存在溢出风险,建议先归一到月初

  • 直接 setMonth 在 31 日等边界可能“溢出”至目标季度的下下个月(与 getMonths 中先 setDate(1) 的做法不一致)。
 export function getQuarterByOffset(date: number, offset: number): number {
   const dateValue = new Date(date)
-  // 计算要增加的月份数(每个季度3个月)
-  const monthsToAdd = offset * 3
-  // 设置新的月份
-  dateValue.setMonth(dateValue.getMonth() + monthsToAdd)
+  // 规避月底溢出:先归一到月初再偏移
+  dateValue.setDate(1)
+  dateValue.setHours(0, 0, 0, 0)
+  const monthsToAdd = offset * 3
+  dateValue.setMonth(dateValue.getMonth() + monthsToAdd)
   return dateValue.getTime()
 }

若设计上需要保留“同日”语义,请确认所有调用方是否已考虑溢出导致的季度错位。


268-293: getQuarterOffset 的“是否包含端点”语义与 getMonthOffset 不一致,需统一或注明

  • getMonthOffset 返回含端点的偏移(+1),而 getQuarterOffset 为纯差值,易引发范围长度计算偏差。

请确认调用场景需要:

  • 纯差值(当前实现),还是
  • 含端点差值(与月份保持一致)。

如需含端点,可如下调整:

-  const totalQuarterOffset = (year1 - year2) * 4 + (quarter1 - quarter2)
-  return totalQuarterOffset
+  const totalQuarterOffset = (year1 - year2) * 4 + (quarter1 - quarter2) + 1
+  return totalQuarterOffset

为避免二义性,也可在 JSDoc 明确“是否包含端点”的定义,并在命名上区分(如 getQuarterDelta vs getQuarterSpan)。


268-293: 补充边界单测建议(跨年/负偏移/同季度)

  • 建议为 compareQuarter/getQuarterByOffset/getQuarterOffset 增加跨年(Q4→Q1)、负偏移(-1/-4)、同季度(返回 0)及月底(1/31)用例,覆盖闰年与 DST。

如需,我可基于现有测试框架补一组最小单测。

src/uni_modules/wot-design-uni/locale/lang/ar-SA.ts (1)

8-8: 阿拉伯语季度键新增正确;可选改进:混排方向性与数词本地化

  • 当前格式 ${year} الربع ${quarter} 可用。若需更地道,可考虑使用序数词(如 “الربع الأول/الثاني...”)或在混合 LTR 数字时加方向性控制(UI 侧处理)。

示例(可选):

-    quarterFormat: (year: number, quarter: number) => `${year} الربع ${quarter}`,
+    quarterFormat: (year: number, quarter: number) => `الربع ${quarter} ${year}`,

或在渲染层统一数字本地化。

Also applies to: 16-16, 21-22

docs/component/calendar-view.md (2)

70-84: 季度选择文档新增清晰,但建议补充 quarterrange 示例与约定说明

  • 在“范围选择”处追加一个 quarterrange 的最小示例,便于用户快速上手。
  • 请在本节或“基本使用”处显式说明:quarter/quarterrange 的 v-model 仍为 13 位时间戳(季度取该季度第一天),避免歧义。

补充示例建议(供参考):

<wd-calendar-view type="quarterrange" v-model="value" @change="handleChange" />
const value = ref<number[]>([])
function handleChange({ value }) { console.log(value) }

87-88: 范围类型已包含 quarterrange,但其他章节未完全对齐

“范围选择允许选中同一日期”章节未包含“同一季度”的表述,建议同步补齐,避免用户误解。

应用差异(在第 144 行附近):

-设置 `allow-same-day` 属性,范围选择允许用户选择同一天、同一周、同一个月。
+设置 `allow-same-day` 属性,范围选择允许用户选择同一天、同一周、同一个月、同一季度。
docs/en-US/component/calendar-view.md (2)

87-88: Add a minimal quarterrange example

范围类型说明已包含 quarterrange,建议补充示例,提升可发现性。

示例建议:

<wd-calendar-view type="quarterrange" v-model="value" @change="handleChange" />
const value = ref<number[]>([])
function handleChange({ value }) { console.log(value) }

144-148: Clarify allow-same-day also applies to quarters

为与新能力一致,建议加入 “same quarter”。

建议修正:

-Set the `allow-same-day` property to allow users to select the same day, same week, or same month in range selection.
+Set the `allow-same-day` property to allow users to select the same day, same week, same month, or same quarter in range selection.
src/uni_modules/wot-design-uni/components/wd-calendar/wd-calendar.vue (1)

390-395: handleTypeChange 缺少越界保护

为防止异常索引导致 type 赋值为 undefined,建议增加防御。

建议补丁:

-  const type = props.type.indexOf('range') > -1 ? rangeTabs[index] : tabs[index]
-  currentTab.value = index
-  currentType.value = type as CalendarType
+  const list = props.type.indexOf('range') > -1 ? rangeTabs : tabs
+  const next = list[index]
+  if (!next) return
+  currentTab.value = index
+  currentType.value = next as CalendarType
src/uni_modules/wot-design-uni/components/wd-calendar-view/quarterPanel/index.scss (1)

1-24: 样式实现基本到位;建议微调 rgba 空格书写以统一代码风格

rgba(255, 255,255, 0.02) 中第二个逗号后缺少空格。

建议补丁:

-      box-shadow: 0px 4px 8px 0 rgba(255, 255,255, 0.02);
+      box-shadow: 0px 4px 8px 0 rgba(255, 255, 255, 0.02);
src/subPages/calendar/Index.vue (1)

102-104: 初始化值更贴合“季度语义”

value19value20 当前以日差估算(如 33*4 天),与季度边界不对齐。建议使用 dayjs 的 quarter 能力,直接定位到当季/上一季首日,避免跨月天数差异导致的误差。

应用如下修改:

-const value19 = ref<number>(Date.now())
-const value20 = ref<number>([Date.now() - 24 * 60 * 60 * 1000 * 33 * 4, Date.now()])
+const value19 = ref<number>(dayjs().startOf('quarter').valueOf())
+const value20 = ref<number>([
+  dayjs().subtract(1, 'quarter').startOf('quarter').valueOf(),
+  dayjs().startOf('quarter').valueOf()
+])
src/uni_modules/wot-design-uni/components/wd-calendar-view/wd-calendar-view.vue (2)

3-19: 季度面板集成方向正确;建议补充 pickstart/pickend 事件透传

若季度范围(quarterrange)存在分步选择(开始/结束)的交互,建议与 month 面板对齐,向外透传 pickstartpickend,以保持 API 一致性。

     <quarter-panel
       v-if="type === 'quarter' || type === 'quarterrange'"
       ref="quarterPanelRef"
       :type="type"
       :value="modelValue"
       :min-date="minDate"
       :max-date="maxDate"
       :formatter="formatter"
       :max-range="maxRange"
       :range-prompt="rangePrompt"
       :allow-same-day="allowSameDay"
       :show-panel-title="showPanelTitle"
       :default-time="formatDefauleTime"
       :panel-height="panelHeight"
-      @change="handleChange"
+      @change="handleChange"
+      @pickstart="handlePickStart"
+      @pickend="handlePickEnd"
     />

107-113: 更简洁的字符串匹配写法

indexOf('quarter') > -1 可用 includes('quarter') 提升可读性;同理对 month 分支也可调整。

-  if (props.type.indexOf('quarter') > -1) {
+  if (props.type.includes('quarter')) {
     return quarterPanelRef.value
-  } else if (props.type.indexOf('month') > -1) {
+  } else if (props.type.includes('month')) {
     return yearPanelRef.value
   } else {
     return monthPanelRef.value
   }
docs/en-US/component/calendar.md (1)

80-94: 建议补充 quarterrange 示例

在 Range 章节中新增一个 quarterrange 的示例,便于用户快速上手。

 ```html
 <wd-calendar type="daterange" v-model="value" @confirm="handleConfirm" />
const value = ref<number[]>([])
function handleConfirm({ value }) {
  console.log(value)
}

+html +<wd-calendar type="quarterrange" v-model="value" @confirm="handleConfirm" /> +
+
+```typescript
+const value = ref<number[]>([])
+function handleConfirm({ value }) {

  • console.log(value)
    +}
    +```

</blockquote></details>
<details>
<summary>src/uni_modules/wot-design-uni/components/wd-calendar-view/quarterPanel/types.ts (1)</summary><blockquote>

`1-1`: **移除未使用的 monthPanelProps 导入**

当前文件未使用该导入,建议删除以避免 lint 报警。

```diff
-import { monthPanelProps } from '@/uni_modules/wot-design-uni/components/wd-calendar-view/monthPanel/types'
src/uni_modules/wot-design-uni/components/wd-calendar-view/quarterPanel/quarter-panel.vue (2)

52-58: 优化建议:考虑可配置的年份块高度

第一年高度设为 200px,其余年份为 245px 的硬编码值可能会影响组件的灵活性。建议将这些高度值提取为 props 或常量配置。

+const FIRST_YEAR_HEIGHT = 200
+const OTHER_YEAR_HEIGHT = 245
+
 const years = computed<YearInfo[]>(() => {
   return getYears(props.minDate, props.maxDate).map((year, index) => {
     return {
       date: year,
-      height: index === 0 ? 200 : 245
+      height: index === 0 ? FIRST_YEAR_HEIGHT : OTHER_YEAR_HEIGHT
     }
   })
 })

59-65: 边界条件处理不足

当滚动事件触发时,虽然对 scrollTop 做了 Math.max(0, ...) 处理,但没有处理最大值边界,可能导致滚动超出内容高度时的计算异常。

 const yearScroll = (event: { detail: { scrollTop: number } }) => {
   if (years.value.length <= 1) {
     return
   }
   const scrollTop = Math.max(0, event.detail.scrollTop)
+  const maxScrollTop = years.value.reduce((sum, year) => sum + year.height, 0) - scrollHeight.value
+  const clampedScrollTop = Math.min(scrollTop, maxScrollTop)
-  doSetSubtitle(scrollTop)
+  doSetSubtitle(clampedScrollTop)
 }
docs/component/calendar.md (1)

67-81: 文档示例代码需要完善

季度选择的示例中,handleConfirm 函数仅打印值,建议添加更实用的示例,如格式化显示选中的季度。

 function handleConfirm({ value }) {
   console.log(value)
+  // 格式化显示选中的季度
+  const date = new Date(value)
+  const quarter = Math.floor(date.getMonth() / 3) + 1
+  const year = date.getFullYear()
+  console.log(`选中了 ${year} 年第 ${quarter} 季度`)
 }
src/uni_modules/wot-design-uni/components/wd-calendar-view/quarter/index.scss (1)

123-125: 样式优化:避免魔法数字

is-last-row 类中直接设置 margin-bottom: 0,建议使用已定义的变量或明确注释其用途。

     @include when(last-row){
+      // 最后一行的季度不需要底部间距
       margin-bottom: 0;
     }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between bdf279d and ed4bd49.

📒 Files selected for processing (37)
  • docs/component/calendar-view.md (1 hunks)
  • docs/component/calendar.md (2 hunks)
  • docs/en-US/component/calendar-view.md (1 hunks)
  • docs/en-US/component/calendar.md (2 hunks)
  • src/locale/en-US.json (1 hunks)
  • src/locale/zh-CN.json (1 hunks)
  • src/subPages/calendar/Index.vue (3 hunks)
  • src/subPages/calendarView/Index.vue (2 hunks)
  • src/uni_modules/wot-design-uni/components/common/abstracts/variable.scss (1 hunks)
  • src/uni_modules/wot-design-uni/components/wd-calendar-view/quarter/index.scss (1 hunks)
  • src/uni_modules/wot-design-uni/components/wd-calendar-view/quarter/quarter.vue (1 hunks)
  • src/uni_modules/wot-design-uni/components/wd-calendar-view/quarter/types.ts (1 hunks)
  • src/uni_modules/wot-design-uni/components/wd-calendar-view/quarterPanel/index.scss (1 hunks)
  • src/uni_modules/wot-design-uni/components/wd-calendar-view/quarterPanel/quarter-panel.vue (1 hunks)
  • src/uni_modules/wot-design-uni/components/wd-calendar-view/quarterPanel/types.ts (1 hunks)
  • src/uni_modules/wot-design-uni/components/wd-calendar-view/types.ts (1 hunks)
  • src/uni_modules/wot-design-uni/components/wd-calendar-view/utils.ts (3 hunks)
  • src/uni_modules/wot-design-uni/components/wd-calendar-view/wd-calendar-view.vue (4 hunks)
  • src/uni_modules/wot-design-uni/components/wd-calendar/wd-calendar.vue (1 hunks)
  • src/uni_modules/wot-design-uni/dayjs/index.d.ts (1 hunks)
  • src/uni_modules/wot-design-uni/dayjs/index.js (1 hunks)
  • src/uni_modules/wot-design-uni/locale/lang/ar-SA.ts (1 hunks)
  • src/uni_modules/wot-design-uni/locale/lang/de-DE.ts (1 hunks)
  • src/uni_modules/wot-design-uni/locale/lang/en-US.ts (1 hunks)
  • src/uni_modules/wot-design-uni/locale/lang/es-ES.ts (1 hunks)
  • src/uni_modules/wot-design-uni/locale/lang/fr-FR.ts (1 hunks)
  • src/uni_modules/wot-design-uni/locale/lang/ja-JP.ts (1 hunks)
  • src/uni_modules/wot-design-uni/locale/lang/ko-KR.ts (1 hunks)
  • src/uni_modules/wot-design-uni/locale/lang/pt-PT.ts (1 hunks)
  • src/uni_modules/wot-design-uni/locale/lang/ru-RU.ts (1 hunks)
  • src/uni_modules/wot-design-uni/locale/lang/th-TH.ts (1 hunks)
  • src/uni_modules/wot-design-uni/locale/lang/tr-TR.ts (1 hunks)
  • src/uni_modules/wot-design-uni/locale/lang/ug-CN.ts (1 hunks)
  • src/uni_modules/wot-design-uni/locale/lang/vi-VN.ts (1 hunks)
  • src/uni_modules/wot-design-uni/locale/lang/zh-CN.ts (1 hunks)
  • src/uni_modules/wot-design-uni/locale/lang/zh-HK.ts (1 hunks)
  • src/uni_modules/wot-design-uni/locale/lang/zh-TW.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/uni_modules/wot-design-uni/components/wd-calendar-view/quarter/types.ts (1)
src/uni_modules/wot-design-uni/components/wd-calendar-view/types.ts (2)
  • CalendarType (4-15)
  • CalendarFormatter (96-96)
src/uni_modules/wot-design-uni/components/wd-calendar-view/quarterPanel/types.ts (1)
src/uni_modules/wot-design-uni/components/wd-calendar-view/types.ts (2)
  • CalendarType (4-15)
  • CalendarFormatter (96-96)
🪛 Biome (2.1.2)
src/uni_modules/wot-design-uni/dayjs/index.js

[error] 160-160: Do not shadow the global "valueOf" property.

Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.

(lint/suspicious/noShadowRestrictedNames)


[error] 531-531: Do not shadow the global "toString" property.

Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.

(lint/suspicious/noShadowRestrictedNames)

🔇 Additional comments (29)
src/uni_modules/wot-design-uni/locale/lang/vi-VN.ts (2)

20-20: 新增“quarter”键翻译准确,位置正确

“Quý”符合越南语习惯,且与 day/week/month 同层级键保持一致,无需改动。


33-34: 范围文案一致性良好

“Quý bắt đầu/Quý kết thúc”与已有“Tháng bắt đầu/Tháng kết thúc”风格一致,术语统一。

src/uni_modules/wot-design-uni/locale/lang/th-TH.ts (2)

8-8: 新增“季度”文案准确且与现有风格一致

术语“ไตรมาส”准确,键名与其他语言包保持一致,无需变更。


16-16: 确认:季度编号为 1-4,无需额外 +1 调整

  • src/uni_modules/wot-design-uni/components/wd-calendar/wd-calendar.vue 第 206 行,使用 Math.floor(date.getMonth() / 3) + 1 计算季度,确保传入 quarterFormat 的参数始终为 1–4。
  • 各语言包下的 quarterFormat 只是将传入的季度数字格式化,并未自行计算季度索引,无需修改。

当前实现已保证全局一致性,可将原建议关闭。

src/uni_modules/wot-design-uni/locale/lang/ug-CN.ts (1)

12-26: LGTM:新增键与 PR 目标一致,结构正确。

与新增季度类型的 API 保持对齐,放置在 calendar 节点下无问题。

src/locale/en-US.json (1)

1455-1456: 新增英文季度文案 LGTM

与现有 “Monthly selection/Monthly Range Selection” 风格一致。

src/locale/zh-CN.json (1)

1455-1456: 新增中文季度文案 LGTM

键名与含义清晰,可直接用于示例与文档。

src/uni_modules/wot-design-uni/locale/lang/ja-JP.ts (1)

8-8: 日文季度文案与格式化新增合理,LGTM

用词(四半期)与格式符合日文习惯。

Also applies to: 16-16, 21-22

src/uni_modules/wot-design-uni/components/wd-calendar-view/types.ts (1)

4-15: 扩展 CalendarType 到季度/季度范围 —— OK

类型联合扩展合理,与新增面板/文案改动方向一致。

src/uni_modules/wot-design-uni/dayjs/index.js (1)

498-504: 请校对 TS 声明与运行时行为一致

quarter() 无参返回 number;传参返回 Dayjs 实例。请确认 index.d.ts 中的重载声明匹配这些行为,否则会影响类型推断。

我可以根据现有 d.ts 生成补丁。

src/uni_modules/wot-design-uni/locale/lang/en-US.ts (1)

8-8: LGTM:英文季度相关文案与格式清晰且与常见习惯一致

  • quarter/quarterFormat/startQuarter/endQuarter 新增键符合预期,无风险。

Also applies to: 16-16, 21-22

src/subPages/calendarView/Index.vue (2)

10-10: 新增单选类型 quarter:演示用例合理

示例接入无误,保持与其他类型一致的交互。


25-25: 新增范围类型 quarterrange:演示用例合理

:type="type2" 绑定一致,便于联动演示。

src/uni_modules/wot-design-uni/components/wd-calendar/wd-calendar.vue (1)

202-217: 已确认 uni_modules/wot-design-uni 下所有语言包均已新增对应 i18n 键,但项目根目录 src/locale 未发现任何条目

– 在 src/uni_modules/wot-design-uni/locale/lang/*.ts 中,所有语言(包括 zh-CN、en-US、vi-VN、ru-RU 等)均已定义 quarterFormatstartQuarterendQuarter 三个键。
– 在项目根目录 src/locale 中未检索到这三个键的任何翻译。

请根据项目的 i18n 加载逻辑确认:

  • 若仅依赖 uni_modules/wot-design-uni 的 locale,则无需额外操作;
  • 若还需在项目自身的 src/locale 中统一管理所有翻译,则需要将上述三键同步添加至 src/locale 下对应语言文件,以免回退到 key 文本。
src/subPages/calendar/Index.vue (2)

74-74: 无需拆分导入:dayjs 已在根入口显式导出

src/uni_modules/wot-design-uni/index.ts 第16行已确认存在

export { default as dayjs } from './dayjs'

因此可以安全地合并导入 dayjsuseToast,无需拆分或额外调整。


12-15: 确认 i18n 键已添加,需人工验证最小日期边界行为

  • 通过脚本验证,ji-du-xuan-zeji-du-fan-wei-xuan-ze 已在 zh-CN.jsonen-US.json 中新增并生效。
  • 请在 type="quarter"type="quarterrange" 面板上人工测试 :min-date="minDate",确认其按季度粒度限制可选区间(仅限制可选季度边界,而非具体天),以避免边界判断不一致。
src/uni_modules/wot-design-uni/components/wd-calendar-view/wd-calendar-view.vue (2)

76-76: 新增导入 QuarterPanel 与模板标签匹配一致性

已采用与 MonthPanel 一致的“导入 PascalCase,模板使用 kebab-case”的惯例,维持现状即可。


85-85: quarterPanelRef 引用补充 OK

引用已就位,便于滚动与方法代理。

docs/en-US/component/calendar.md (2)

66-79: 新增 Quarter 章节说明清晰

描述了“值为该季度首日”的语义,并提供了基本示例,和实现相符。


141-147: 确认“Quick Operation”是否支持季度类型,若支持请更新文档

若季度类型同样支持 show-confirm="false",需将季度类型加入限制说明。

-Set the `show-confirm` property to `false` to not display the confirm button. This is only valid for `date`, `daterange`, `week`, `weekrange`, `month`, `monthrange` types.
+Set the `show-confirm` property to `false` to not display the confirm button. This is only valid for `date`, `daterange`, `week`, `weekrange`, `month`, `monthrange`, `quarter`, `quarterrange` types.
src/uni_modules/wot-design-uni/components/wd-calendar-view/quarterPanel/types.ts (1)

6-20: Props 设计与现有面板保持一致,LGTM

必填项、可选项与类型(含 defaultTime)与月/年面板对齐,便于复用。

src/uni_modules/wot-design-uni/components/wd-calendar-view/quarter/types.ts (1)

5-20: 季度单元格 Props 定义合理

  • value 允许 number | (number|null)[] | null 与其他面板一致。
  • showTitle 默认 true,与上层 showPanelTitle 区分清晰。
docs/component/calendar.md (2)

84-84: 文档更新完整

很好地在范围选择类型中添加了 quarterrange 类型说明,保持了文档的完整性。


415-458: API 文档更新全面

属性表格中正确添加了 quarterquarterrange 类型,并保持了与其他类型的一致性。废弃属性也做了正确的标记。

src/uni_modules/wot-design-uni/components/wd-calendar-view/quarter/index.scss (1)

76-94: 范围选择样式实现合理

使用 ::after 伪元素实现范围选择的背景效果,通过 left: 50%right: 50% 巧妙地实现了半边背景,设计思路清晰。

Also applies to: 99-113

src/uni_modules/wot-design-uni/components/wd-calendar-view/quarter/quarter.vue (4)

80-88: 季度标签生成逻辑正确

使用 dayjs 的 quarter() 方法获取季度数字,实现简洁且正确。


177-183: 最大范围限制实现合理

正确处理了季度范围选择的最大限制,包括计算偏移量、限制结束日期,并显示提示信息。


195-203: 格式化函数实现良好

getFormatterDate 函数正确生成季度对象,包括禁用状态判断和最后一行标识。季度文本格式(Q1-Q4)清晰易懂。


205-211: formatter 属性验证完善

正确验证了 formatter 必须是函数类型,并在不满足条件时输出错误信息。

Comment on lines +70 to +84
## Month Type Selection

Set `type` to `quarter` type. When `value` has a value, its value is the first day of the quarter.

```html
<wd-calendar-view type="quarter" v-model="value" @change="handleChange" />
```

```typescript
const value = ref(Date.now())

function handleChange({ value }) {
console.log(value)
}
```
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Section heading typo: should be “Quarter Type Selection”

当前标题为 “Month Type Selection”,与内容不符。

建议修正:

-## Month Type Selection
+## Quarter Type Selection
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
## Month Type Selection
Set `type` to `quarter` type. When `value` has a value, its value is the first day of the quarter.
```html
<wd-calendar-view type="quarter" v-model="value" @change="handleChange" />
```
```typescript
const value = ref(Date.now())
function handleChange({ value }) {
console.log(value)
}
```
## Quarter Type Selection
Set `type` to `quarter` type. When `value` has a value, its value is the first day of the quarter.
🤖 Prompt for AI Agents
In docs/en-US/component/calendar-view.md around lines 70 to 84, the section
heading reads "Month Type Selection" but the content describes the quarter type;
change the heading text to "Quarter Type Selection" and verify any adjacent
references (examples, captions) consistently refer to the quarter type to avoid
mismatch.

Comment on lines +96 to +99
if (props.type.indexOf('range') > -1 && value && !isArray(value)) {
console.error('[wot-design] value should be array when type is range')
return
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

错误处理应当更严格

当 type 为 range 但 value 不是数组时,仅输出错误信息就返回,可能导致组件处于异常状态。建议设置默认值或抛出错误。

   if (props.type.indexOf('range') > -1 && value && !isArray(value)) {
     console.error('[wot-design] value should be array when type is range')
+    // 设置默认值为空数组,确保组件正常渲染
+    quarters.value = []
     return
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (props.type.indexOf('range') > -1 && value && !isArray(value)) {
console.error('[wot-design] value should be array when type is range')
return
}
if (props.type.indexOf('range') > -1 && value && !isArray(value)) {
console.error('[wot-design] value should be array when type is range')
// 设置默认值为空数组,确保组件正常渲染
quarters.value = []
return
}
🤖 Prompt for AI Agents
In
src/uni_modules/wot-design-uni/components/wd-calendar-view/quarter/quarter.vue
around lines 96-99, the current code only logs an error and returns when
props.type contains "range" but value is not an array; fix by enforcing a safe
state: replace the silent return with deterministic handling — either throw a
clear Error (to fail fast) or coerce/set a sane default (e.g., assign value = []
or emit an "update:value" with an empty array and/or set an internal reactive
default) and add prop validation to warn at prop init; ensure any chosen
approach also documents the behavior and keeps the component state consistent
rather than leaving it undefined.

function handleQuarterRangeChange(date: CalendarDayItem) {
let value: (number | null)[] = []
const [startDate, endDate] = isArray(props.value) ? props.value || [] : []
const compare = compareQuarter(date.date, startDate!)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

潜在的空值引用问题

在 Line 171 使用 startDate! 进行非空断言,但实际上 startDate 可能为 nullundefined

-  const compare = compareQuarter(date.date, startDate!)
+  const compare = startDate ? compareQuarter(date.date, startDate) : -1
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const compare = compareQuarter(date.date, startDate!)
const compare = startDate ? compareQuarter(date.date, startDate) : -1
🤖 Prompt for AI Agents
In
src/uni_modules/wot-design-uni/components/wd-calendar-view/quarter/quarter.vue
around line 171, the code uses a non-null assertion startDate! when calling
compareQuarter(date.date, startDate!), which can cause a runtime error if
startDate is null or undefined; add a runtime guard to verify startDate is
defined before calling compareQuarter (e.g., if (!startDate) { handle the
missing value or return/skip this item }), or provide a safe fallback value
and/or change the call to use optional handling so the function is only invoked
when startDate is present.


locale(preset: string | ILocale, object?: Partial<ILocale>): Dayjs

quarter():string
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

💡 Verification agent

🧩 Analysis chain

修正 Dayjs quarter() 类型与能力范围

  • 建议将返回类型从 string 改为 number,并补充 setter 重载,保持与常见 quarter 插件约定一致。
  • 同时建议在 OpUnitType 中纳入 'quarter' | 'quarters' | 'Q',否则如 startOf('quarter')、endOf('quarter') 在 TS 下会报错。

在本段内应用补丁:

-    quarter():string
+    quarter(): number
+    quarter(quarter: number): Dayjs

此外(超出当前选区的类型增强示例,仅供参考):

// 建议修改:
export type OpUnitType = UnitType | 'week' | 'weeks' | 'w' | 'quarter' | 'quarters' | 'Q';

验证脚本(检查代码是否使用了 quarter 相关单位):


🏁 Script executed:

#!/bin/bash
rg -nP "startOf\(['\"]quarter['\"]\)|endOf\(['\"]quarter['\"]\)|isSame\([^)]*['\"]quarter['\"]\)|diff\([^)]*['\"]quarter" -S

Length of output: 140


下面运行以下脚本,以验证 quarter() 的定义及 OpUnitType 中是否包含对应选项:


🏁 Script executed:

#!/bin/bash
# 在 index.d.ts 中搜索所有与 quarter 相关的签名
rg -n "quarter" -n src/uni_modules/wot-design-uni/dayjs/index.d.ts

# 查看 OpUnitType 的定义及其后续行,确认是否已包含 'quarter' | 'quarters' | 'Q'
rg -n "type OpUnitType" -A5 -n src/uni_modules/wot-design-uni/dayjs/index.d.ts

Length of output: 521


下面运行脚本,查看 startOfendOf 方法的签名,确认它们使用的是哪个单位类型:


🏁 Script executed:

#!/bin/bash
# 查看 startOf 签名及上下文
rg -n "startOf\(" -C3 -n src/uni_modules/wot-design-uni/dayjs/index.d.ts

# 查看 endOf 签名及上下文
rg -n "endOf\(" -C3 -n src/uni_modules/wot-design-uni/dayjs/index.d.ts

Length of output: 1104


请修复 dayjs().quarter() 方法定义及扩展 OpUnitType

当前问题

  • src/uni_modules/wot-design-uni/dayjs/index.d.ts 第 418 行,quarter() 方法声明为返回 string,且缺少 setter 重载;
  • startOf('quarter')endOf('quarter') 使用的 OpUnitType(位于第 31 行)并未包含 "quarter""quarters"'Q',会导致 TS 报错。

定位

  • 文件:src/uni_modules/wot-design-uni/dayjs/index.d.ts
  • quarter() 方法:第 418 行
  • OpUnitType 定义:第 31 行

建议补丁

--- a/src/uni_modules/wot-design-uni/dayjs/index.d.ts
@@ -418,1 +418,2
-    quarter(): string
+    quarter(): number
+    quarter(quarter: number): Dayjs
--- a/src/uni_modules/wot-design-uni/dayjs/index.d.ts
@@ -31,1 +31,4
-export type OpUnitType = UnitType | "week" | "weeks" | 'w';
+export type OpUnitType = UnitType
+  | "week"   | "weeks"   | 'w'
+  | "quarter"| "quarters"| 'Q';

以上改动可保证

  1. dayjs().quarter() 返回数值类型并支持设置季度;
  2. startOf('quarter') / endOf('quarter') 在 TS 下不再报错,符合常见插件约定。

Comment on lines 195 to 207
switch (unit) {
case C.Y:
return isStartOf ? instanceFactory(1, 0) : instanceFactory(31, 11);
return isStartOf ? instanceFactory(1, 0) : instanceFactory(31, 11)

case C.M:
return isStartOf ? instanceFactory(1, $M) : instanceFactory(0, $M + 1);
return isStartOf ? instanceFactory(1, $M) : instanceFactory(0, $M + 1)

case C.W:
{
var weekStart = this.$locale().weekStart || 0;
var gap = ($W < weekStart ? $W + 7 : $W) - weekStart;
return instanceFactory(isStartOf ? $D - gap : $D + (6 - gap), $M);
}
case C.W: {
var weekStart = this.$locale().weekStart || 0
var gap = ($W < weekStart ? $W + 7 : $W) - weekStart
return instanceFactory(isStartOf ? $D - gap : $D + (6 - gap), $M)
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

缺少对 quarter 的 startOf/endOf 支持,可能影响边界计算

quarter 面板与范围计算通常依赖 startOf('quarter')/endOf('quarter')。当前 switch 未覆盖 C.Q,默认 clone 会导致边界不正确。

     switch (unit) {
       case C.Y:
         return isStartOf ? instanceFactory(1, 0) : instanceFactory(31, 11)

       case C.M:
         return isStartOf ? instanceFactory(1, $M) : instanceFactory(0, $M + 1)
+
+      case C.Q: {
+        const qStartMonth = Math.floor($M / 3) * 3
+        // 与月份逻辑一致:start 用当季首月1号;end 用下一季首月的前一天
+        return isStartOf ? instanceFactory(1, qStartMonth) : instanceFactory(0, qStartMonth + 3)
+      }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
switch (unit) {
case C.Y:
return isStartOf ? instanceFactory(1, 0) : instanceFactory(31, 11);
return isStartOf ? instanceFactory(1, 0) : instanceFactory(31, 11)
case C.M:
return isStartOf ? instanceFactory(1, $M) : instanceFactory(0, $M + 1);
return isStartOf ? instanceFactory(1, $M) : instanceFactory(0, $M + 1)
case C.W:
{
var weekStart = this.$locale().weekStart || 0;
var gap = ($W < weekStart ? $W + 7 : $W) - weekStart;
return instanceFactory(isStartOf ? $D - gap : $D + (6 - gap), $M);
}
case C.W: {
var weekStart = this.$locale().weekStart || 0
var gap = ($W < weekStart ? $W + 7 : $W) - weekStart
return instanceFactory(isStartOf ? $D - gap : $D + (6 - gap), $M)
}
switch (unit) {
case C.Y:
return isStartOf ? instanceFactory(1, 0) : instanceFactory(31, 11)
case C.M:
return isStartOf ? instanceFactory(1, $M) : instanceFactory(0, $M + 1)
case C.Q: {
const qStartMonth = Math.floor($M / 3) * 3
// 与月份逻辑一致:start 用当季首月1号;end 用下一季首月的前一天
return isStartOf
? instanceFactory(1, qStartMonth)
: instanceFactory(0, qStartMonth + 3)
}
case C.W: {
var weekStart = this.$locale().weekStart || 0
var gap = ($W < weekStart ? $W + 7 : $W) - weekStart
return instanceFactory(
isStartOf ? $D - gap : $D + (6 - gap),
$M
)
}
🤖 Prompt for AI Agents
In src/uni_modules/wot-design-uni/dayjs/index.js around lines 195-207, the
switch lacks handling for C.Q (quarter), causing startOf/endOf('quarter') to be
incorrect; add a case C.Q that computes the quarter start month as Math.floor($M
/ 3) * 3 and for startOf returns instanceFactory(1, quarterStartMonth), for
endOf returns instanceFactory(0, quarterStartMonth + 3) so the end uses day 0 of
the month after the quarter to get the proper last day.

Comment on lines 269 to +306
if (unit === C.M) {
return this.set(C.M, this.$M + number);
return this.set(C.M, this.$M + number)
}

if (unit === C.Y) {
return this.set(C.Y, this.$y + number);
return this.set(C.Y, this.$y + number)
}

if (unit === C.D) {
return instanceFactorySet(1);
return instanceFactorySet(1)
}

if (unit === C.W) {
return instanceFactorySet(7);
return instanceFactorySet(7)
}

var step = (_C$MIN$C$H$C$S$unit = {}, _C$MIN$C$H$C$S$unit[C.MIN] = C.MILLISECONDS_A_MINUTE, _C$MIN$C$H$C$S$unit[C.H] = C.MILLISECONDS_A_HOUR, _C$MIN$C$H$C$S$unit[C.S] = C.MILLISECONDS_A_SECOND, _C$MIN$C$H$C$S$unit)[unit] || 1; // ms
var step =
((_C$MIN$C$H$C$S$unit = {}),
(_C$MIN$C$H$C$S$unit[C.MIN] = C.MILLISECONDS_A_MINUTE),
(_C$MIN$C$H$C$S$unit[C.H] = C.MILLISECONDS_A_HOUR),
(_C$MIN$C$H$C$S$unit[C.S] = C.MILLISECONDS_A_SECOND),
_C$MIN$C$H$C$S$unit)[unit] || 1 // ms

var nextTimeStamp = this.$d.getTime() + number * step;
return Utils.w(nextTimeStamp, this);
};
var nextTimeStamp = this.$d.getTime() + number * step
return Utils.w(nextTimeStamp, this)
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

add/subtract 未覆盖 quarter 单位

diff 已支持 C.Q,但 add/subtract 没有 quarter 分支,调用 add(1, 'quarter') 将退化为毫秒步长。

     if (unit === C.M) {
       return this.set(C.M, this.$M + number)
     }
 
     if (unit === C.Y) {
       return this.set(C.Y, this.$y + number)
     }
 
+    if (unit === C.Q) {
+      // 以月为步长,每个季度 3 个月
+      return this.set(C.M, this.$M + number * 3)
+    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (unit === C.M) {
return this.set(C.M, this.$M + number);
return this.set(C.M, this.$M + number)
}
if (unit === C.Y) {
return this.set(C.Y, this.$y + number);
return this.set(C.Y, this.$y + number)
}
if (unit === C.D) {
return instanceFactorySet(1);
return instanceFactorySet(1)
}
if (unit === C.W) {
return instanceFactorySet(7);
return instanceFactorySet(7)
}
var step = (_C$MIN$C$H$C$S$unit = {}, _C$MIN$C$H$C$S$unit[C.MIN] = C.MILLISECONDS_A_MINUTE, _C$MIN$C$H$C$S$unit[C.H] = C.MILLISECONDS_A_HOUR, _C$MIN$C$H$C$S$unit[C.S] = C.MILLISECONDS_A_SECOND, _C$MIN$C$H$C$S$unit)[unit] || 1; // ms
var step =
((_C$MIN$C$H$C$S$unit = {}),
(_C$MIN$C$H$C$S$unit[C.MIN] = C.MILLISECONDS_A_MINUTE),
(_C$MIN$C$H$C$S$unit[C.H] = C.MILLISECONDS_A_HOUR),
(_C$MIN$C$H$C$S$unit[C.S] = C.MILLISECONDS_A_SECOND),
_C$MIN$C$H$C$S$unit)[unit] || 1 // ms
var nextTimeStamp = this.$d.getTime() + number * step;
return Utils.w(nextTimeStamp, this);
};
var nextTimeStamp = this.$d.getTime() + number * step
return Utils.w(nextTimeStamp, this)
}
if (unit === C.M) {
return this.set(C.M, this.$M + number)
}
if (unit === C.Y) {
return this.set(C.Y, this.$y + number)
}
// 支持季度单位,每个季度 3 个月
if (unit === C.Q) {
return this.set(C.M, this.$M + number * 3)
}
if (unit === C.D) {
return instanceFactorySet(1)
}
if (unit === C.W) {
return instanceFactorySet(7)
}
var step =
((_C$MIN$C$H$C$S$unit = {}),
(_C$MIN$C$H$C$S$unit[C.MIN] = C.MILLISECONDS_A_MINUTE),
(_C$MIN$C$H$C$S$unit[C.H] = C.MILLISECONDS_A_HOUR),
(_C$MIN$C$H$C$S$unit[C.S] = C.MILLISECONDS_A_SECOND),
_C$MIN$C$H$C$S$unit)[unit] || 1 // ms
var nextTimeStamp = this.$d.getTime() + number * step
return Utils.w(nextTimeStamp, this)
🤖 Prompt for AI Agents
In src/uni_modules/wot-design-uni/dayjs/index.js around lines 281 to 306, add
handling for the quarter unit (C.Q) in the add/subtract logic: implement a
branch analogous to months/years that advances months by number*3 (e.g. return
this.set(C.M, this.$M + number * 3)) or map C.Q into the step logic so quarter
calls do not fall back to milliseconds; ensure both add and subtract paths use
the same quarter handling and keep consistent behavior with month/year
adjustments.

Comment on lines +12 to +26
quarter: 'چوڭ پەسىل',
confirm: 'جەزملەش',
startTime: 'باشلىنىش ۋاقتى',
endTime: 'ئاخىرلىشىش ۋاقتى',
to: 'دىن',
timeFormat: 'YY-MM-DD HH:mm:ss',
dateFormat: 'YYYY-MM-DD',
weekFormat: (year: number, week: number) => `${year}يىلى ${week}ھەپتە`,
quarterFormat: (year: number, quarter: number) => `${year}يىلى ${quarter}چوڭ پەسىل`,
startWeek: 'باشلىنىش ھەپتىسى',
endWeek: 'ئاخىرلىشىش ھەپتىسى',
startMonth: 'باشلىنىش ئېيى',
endMonth: 'ئاخىرلىشىش ئېيى',
startQuarter: 'باشلىنىش چوڭ پەسىلى',
endQuarter: 'ئاخىرلىشىش چوڭ پەسىلى',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

补全检查:确认所有语言包均新增 quarter 相关键,且组件未引用缺失 key。

建议运行脚本,核对各 locale 是否包含 quarter/quarterFormat/startQuarter/endQuarter,并排查代码中是否出现未在本文件提供的键(如 quarterTitle、rangePromptQuarter)。


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== 检查各 locale 是否补齐 quarter 系列键 =="
for key in 'quarter:' 'quarterFormat' 'startQuarter' 'endQuarter'; do
  echo "[Key] $key"
  fd -t f '.+\.ts$' src/uni_modules/wot-design-uni/locale/lang | while read -r f; do
    if ! rg -q "$key" "$f"; then
      echo "  - 缺失: $f"
    fi
  done
done

echo "== 扫描代码中是否引用了可能缺失的 i18n 键 =="
rg -nP --no-heading -S '(rangePromptQuarter|quarterTitle)' src -g '!**/dist/**' -g '!**/build/**' || true

Length of output: 6538


请为 rangePromptQuarter 补充翻译键

经验证,所有语言包已包含 quarterquarterFormatstartQuarterendQuarter 等系列键,无缺失;但在日历组件中仍有对未定义翻译键的引用:

  • 文件:src/uni_modules/wot-design-uni/components/wd-calendar-view/quarter/quarter.vue
  • 行号:181
  • 代码:translate('rangePromptQuarter', props.maxRange)

请在各语言包(src/uni_modules/wot-design-uni/locale/lang/*.ts)中新增 rangePromptQuarter 键,并提供对应文案。例如在 ug-CN.ts 中:

rangePromptQuarter: '最多可选 {maxRange} 个季度',

确保所有语言文件均同步更新。

🤖 Prompt for AI Agents
In src/uni_modules/wot-design-uni/locale/lang/ug-CN.ts around lines 12 to 26,
the localization is missing the rangePromptQuarter key used by the calendar
component; add a new entry rangePromptQuarter with the Uyghur string for "最多可选
{maxRange} 个季度" (e.g., "ئەڭ كۆپ {maxRange} چوڭ پەسىل تاللىيالايسىز") to match
other language files, and then add the same key with appropriate translations to
all other files under src/uni_modules/wot-design-uni/locale/lang/*.ts so the
translate('rangePromptQuarter', props.maxRange) call resolves.

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.

[新功能需求] Calendar增加季度选择

1 participant