Skip to content

Conversation

xiaoyatong
Copy link
Collaborator

@xiaoyatong xiaoyatong commented Apr 3, 2025

🤔 这个变动的性质是?

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

🔗 相关 Issue

💡 需求背景和解决方案

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

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

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充
  • fork仓库代码是否为最新避免文件冲突
  • Files changed 没有 package.json lock 等无关文件

Summary by CodeRabbit

  • 重构
    • 优化对话框组件的交互逻辑,在不同平台上(Web 与移动端)提供更加一致、流畅的体验。
    • 精简配置及事件处理流程,确保覆盖层点击、确认和取消操作更加直观稳定。
    • 整合并统一了类型定义,降低代码复杂度,移除冗余组件,使对话框功能更简洁高效。

Copy link

coderabbitai bot commented Apr 3, 2025

Walkthrough

此次 PR 主要对对话框组件的类型定义和事件处理逻辑进行了调整与简化。修改内容包括替换部分类型引用、更新组件默认属性和事件回调机制、移除冗余函数以及删除旧的类型文件。同时,在对话框的展示与交互流程上引入了新的类型接口,使得组件在 Web 与 Taro 平台上均能获得更一致和简化的实现。

Changes

File(s) Change Summary
src/.../dialog/confirm.tsx 修改类型引用从 DialogConfirmPropsBaseDialog,将 DialogConfirmNativeProps 定义为 Partial<BaseDialog>,并移除 normalizeConfig 函数,简化配置逻辑。
src/.../dialog/dialog.taro.tsx, src/.../dialog/dialog.tsx 更新 BaseDialog 组件的默认属性与事件处理:使用 MouseEvent 替换 React.MouseEvent,取消可选链调用,重构按钮渲染逻辑,调整传参类型。
src/.../dialog/dialogwrap.tsx 删除文件及其相关动画和默认属性逻辑。
src/.../dialog/content.taro.tsx 更新组件使用 TaroContentProps 替换 ContentProps,新增对 styleclassName 的支持,并简化 onClick 调用。
src/.../dialog/content.tsx 将 ContentProps 修改为 WebContentProps,更改事件参数类型(从 React.MouseEvent 改为 MouseEvent),调整导入。
src/.../dialog/index.taro.ts, src/.../dialog/index.ts 调整导出类型:重命名 ContentProps/DialogProps,移除 DialogBasicProps/DialogConfirmProps,并更新类型来源路径。
src/.../dialog/types.taro.ts, src/.../dialog/types.ts 删除旧的对话框类型定义文件。
src/types/spec/dialog/base.ts 新增基础对话框类型,定义 BaseDialog、BaseContentProps、DialogReturnProps、DialogComponent 及 destroyList,构建完整的对话框类型体系。
src/types/spec/dialog/h5.ts 新增 WebContentProps 接口,扩展 BaseContentProps,并定义 onClick 方法(使用 MouseEvent 参数)。
src/types/spec/dialog/taro.ts 新增 TaroContentProps 接口,同时调整 TaroDialogProps:通过 Omit 排除 onOverlayClick 与 onClick 并重新定义事件方法签名。

Sequence Diagram(s)

sequenceDiagram
    participant U as 用户
    participant D as BaseDialog
    participant O as Overlay
    participant B as 按钮

    U->>D: 触发对话框显示
    D->>O: 渲染 Overlay
    U->>O: 点击 Overlay
    O->>D: 触发 onOverlayClick 事件
    D->>D: 直接调用 onClose/onCancel 处理关闭
    U->>B: 点击确认或取消
    B->>D: 调用 handleOk 或 handleCancel
    D->>D: 更新组件状态,完成事件响应
Loading

Possibly related PRs

Poem

嗨,我是跳跳兔,代码林中乐逍遥,
类型换新装,逻辑整齐好苗条。
配置简化无烦恼,键盘上跳跃多欢笑,
点击中传来新律动,界面跃动像春潮。
编码世界斑斓亮,兔兔祝你一路骄傲! 🐇💻

✨ Finishing Touches
  • 📝 Generate Docstrings

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.
    • Generate unit testing code for this file.
    • 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. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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

Documentation and Community

  • 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.

@github-actions github-actions bot added action:review This PR needs more reviews (less than 2 approvals) 3.x Target branch 3.x labels Apr 3, 2025
Copy link

codecov bot commented Apr 3, 2025

Codecov Report

Attention: Patch coverage is 95.58824% with 6 lines in your changes missing coverage. Please review.

Project coverage is 87.20%. Comparing base (c5f266a) to head (a16fa3d).
Report is 1 commits behind head on feat_v3.x.

Files with missing lines Patch % Lines
src/packages/dialog/dialog.tsx 95.41% 6 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##           feat_v3.x    #3147      +/-   ##
=============================================
+ Coverage      87.18%   87.20%   +0.01%     
=============================================
  Files            280      279       -1     
  Lines          18525    18536      +11     
  Branches        2816     2821       +5     
=============================================
+ Hits           16151    16164      +13     
+ Misses          2369     2367       -2     
  Partials           5        5              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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: 1

🧹 Nitpick comments (5)
src/types/spec/dialog/taro.ts (1)

8-12: 接口定义清晰,但联合类型中的 void 可能造成混淆

TaroDialogProps 接口通过 Omit 移除了基础属性后重新定义,结构清晰。但 onOverlayClick 返回类型中的联合类型 boolean | void 存在潜在混淆。

根据静态分析工具的建议,在联合类型中使用 undefinedvoid 更清晰:

export interface TaroDialogProps
  extends Omit<BaseDialog, 'onOverlayClick' | 'onClick'> {
  onClick: (event: ITouchEvent) => void
-  onOverlayClick: (event: ITouchEvent) => boolean | void
+  onOverlayClick: (event: ITouchEvent) => boolean | undefined
}
🧰 Tools
🪛 Biome (1.9.4)

[error] 11-11: void is confusing inside a union type.

Unsafe fix: Use undefined instead.

(lint/suspicious/noConfusingVoidType)

src/packages/dialog/dialog.tsx (3)

19-45: 建议将大规模 defaultProps 拆分至独立配置文件
当前 defaultProps 字段较多,后续可考虑拆分至单独的配置文件,方便在其他组件中复用并保持代码整洁。


127-140: 取消按钮的逻辑与模态结构解耦较好
若未来需要添加更多功能按钮,可考虑将按钮进一步组件化,提升可维护性和复用性。


200-206: 使用可选链有助于简化判断逻辑
可将 const closed = onOverlayClick && onOverlayClick(e) 改为 const closed = onOverlayClick?.(e),可读性更高,也减少潜在报错。

-const closed = onOverlayClick && onOverlayClick(e)
+const closed = onOverlayClick?.(e)
🧰 Tools
🪛 Biome (1.9.4)

[error] 202-202: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🪛 GitHub Check: codecov/patch

[warning] 201-206: src/packages/dialog/dialog.tsx#L201-L206
Added lines #L201 - L206 were not covered by tests

src/types/spec/dialog/base.ts (1)

30-30: 避免在返回类型中直接使用 void 以减少语义歧义
可以将 void 换成 undefined,更确切表达返回结果为空的情况下所期望的类型。

-onOverlayClick: (e: MouseEvent) => boolean | void
+onOverlayClick: (e: MouseEvent) => boolean | undefined

-onConfirm: (e?: MouseEvent<HTMLButtonElement>) => PromiseLike<any> | void
+onConfirm: (e?: MouseEvent<HTMLButtonElement>) => PromiseLike<any> | undefined

Also applies to: 44-44

🧰 Tools
🪛 Biome (1.9.4)

[error] 30-30: void is confusing inside a union type.

Unsafe fix: Use undefined instead.

(lint/suspicious/noConfusingVoidType)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 78e5c54 and 666a08e.

📒 Files selected for processing (13)
  • src/packages/dialog/confirm.tsx (1 hunks)
  • src/packages/dialog/content.taro.tsx (4 hunks)
  • src/packages/dialog/content.tsx (3 hunks)
  • src/packages/dialog/dialog.taro.tsx (10 hunks)
  • src/packages/dialog/dialog.tsx (7 hunks)
  • src/packages/dialog/dialogwrap.tsx (0 hunks)
  • src/packages/dialog/index.taro.ts (1 hunks)
  • src/packages/dialog/index.ts (1 hunks)
  • src/packages/dialog/types.taro.ts (0 hunks)
  • src/packages/dialog/types.ts (0 hunks)
  • src/types/spec/dialog/base.ts (1 hunks)
  • src/types/spec/dialog/h5.ts (1 hunks)
  • src/types/spec/dialog/taro.ts (1 hunks)
💤 Files with no reviewable changes (3)
  • src/packages/dialog/dialogwrap.tsx
  • src/packages/dialog/types.taro.ts
  • src/packages/dialog/types.ts
🧰 Additional context used
🧬 Code Definitions (4)
src/types/spec/dialog/base.ts (3)
src/packages/dialog/index.taro.ts (5)
  • DialogConfigType (4-4)
  • DialogCloseIconPosition (5-5)
  • DialogFooterDirection (6-6)
  • DialogWrapProps (8-8)
  • DialogReturnProps (10-10)
src/packages/dialog/index.ts (5)
  • DialogConfigType (4-4)
  • DialogCloseIconPosition (5-5)
  • DialogFooterDirection (6-6)
  • DialogWrapProps (8-8)
  • DialogReturnProps (10-10)
src/packages/dialog/dialog.taro.tsx (1)
  • BaseDialog (49-264)
src/packages/dialog/content.tsx (3)
src/packages/dialog/content.taro.tsx (1)
  • defaultContentProps (6-14)
src/packages/dialog/index.ts (1)
  • WebContentProps (7-7)
src/types/spec/dialog/h5.ts (1)
  • WebContentProps (3-5)
src/packages/dialog/content.taro.tsx (3)
src/packages/dialog/content.tsx (1)
  • defaultContentProps (5-13)
src/packages/dialog/index.taro.ts (1)
  • TaroContentProps (7-7)
src/types/spec/dialog/taro.ts (1)
  • TaroContentProps (4-6)
src/packages/dialog/dialog.tsx (4)
src/packages/overlay/overlay.tsx (2)
  • defaultOverlayProps (14-24)
  • Overlay (25-86)
src/packages/dialog/content.tsx (2)
  • defaultContentProps (5-13)
  • Content (15-74)
src/types/spec/dialog/base.ts (3)
  • BaseDialog (33-45)
  • DialogComponent (52-58)
  • DialogReturnProps (47-50)
src/types/spec/dialog/h5.ts (1)
  • WebDialogProps (6-6)
🪛 Biome (1.9.4)
src/types/spec/dialog/taro.ts

[error] 11-11: void is confusing inside a union type.

Unsafe fix: Use undefined instead.

(lint/suspicious/noConfusingVoidType)

src/types/spec/dialog/base.ts

[error] 30-30: void is confusing inside a union type.

Unsafe fix: Use undefined instead.

(lint/suspicious/noConfusingVoidType)


[error] 44-44: void is confusing inside a union type.

Unsafe fix: Use undefined instead.

(lint/suspicious/noConfusingVoidType)

src/packages/dialog/dialog.tsx

[error] 202-202: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🪛 GitHub Check: codecov/patch
src/packages/dialog/dialog.tsx

[warning] 201-206: src/packages/dialog/dialog.tsx#L201-L206
Added lines #L201 - L206 were not covered by tests

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (31)
src/packages/dialog/index.ts (1)

7-11: 类型重构符合规范

将类型从本地 './types' 迁移到全局 '@/types' 并使用别名,有助于维持向后兼容性的同时实现类型标准化。去掉 DialogBasicPropsDialogConfirmProps 的导出也简化了 API 接口。

src/packages/dialog/index.taro.ts (1)

7-11: 类型重命名和导入路径更新保持一致性

将导入路径从相对路径 './types.taro' 更改为绝对路径 '@/types',并使用 TaroContentProps as ContentPropsTaroDialogProps as DialogProps 的别名导出方式,与 Web 版本保持了一致的架构,有助于维护代码库的一致性。

src/packages/dialog/confirm.tsx (3)

3-3: 类型定义迁移到标准位置

DialogConfirmProps替换为从@/types导入的BaseDialog,这符合PR的重构目标,将类型定义抽离到标准规范下。


6-6: 类型定义更新符合重构方向

DialogConfirmNativeProps的类型从Partial<DialogConfirmProps>更新为Partial<BaseDialog>,保持了类型系统的一致性。


11-54:

❓ Verification inconclusive

验证移除normalizeConfig后的行为一致性

注意到normalizeConfig函数已被移除,该函数之前会根据isNotice标志调整hideCancelButton属性。请确保此逻辑变更不会影响现有功能。


🏁 Script executed:

#!/bin/bash
# 描述:检查代码库中是否还有其他地方使用isNotice标志来处理hideCancelButton逻辑

# 搜索可能使用isNotice的代码
rg -B 2 -A 2 "isNotice.*hideCancelButton" --type ts --type tsx

# 搜索Dialog组件中可能的替代逻辑
rg -B 2 -A 2 "hideCancelButton.*=.*" --type ts --type tsx -- **/dialog/**

Length of output: 198


请验证移除normalizeConfig后 isNotice / hideCancelButton 逻辑的一致性
目前已移除的 normalizeConfig 函数原本会根据 isNotice 标志调整 hideCancelButton 属性。为了确保该逻辑移除后不会影响现有功能,请手动运行下面的脚本重新验证代码库中是否有其他地方依赖此行为:

请依据新脚本的搜索结果确认:
• 如果没有输出,说明该逻辑在其他地方不存在,不会影响现有功能;
• 如果有输出,请仔细检查这些代码是否需要相应调整。


🏁 Script executed:

#!/bin/bash
echo "搜索使用 isNotice 调整 hideCancelButton 的相关代码(检查 TS 和 TSX 文件)..."
rg -B 2 -A 2 "isNotice.*hideCancelButton" --glob "*.tsx" --glob "*.ts"

echo "搜索 dialog 目录下 hideCancelButton 的赋值逻辑..."
rg -B 2 -A 2 "hideCancelButton\s*=" --glob "*.tsx" **/dialog/**

Length of output: 409


请验证 normalizeConfig 移除后的 isNotice/hideCancelButton 行为一致性
经过初步检索,目前未发现其他代码依赖 isNotice 标志来调整 hideCancelButton 属性,也没有在相关 dialog 模块中查到赋值逻辑。不过,由于脚本搜索结果存在不确定性(部分 glob 模式可能未覆盖到实际位置),请开发者手动确认以下几点:

  • src/packages/dialog/confirm.tsx 及其他可能依赖该逻辑的文件中,确保不再存在依据 isNotice 设置 hideCancelButton 的代码。
  • 验证在实际场景下(例如通知对话框中)功能行为与预期保持一致,避免因移除 normalizeConfig 而导致界面或交互异常。

请结合单元测试或手动测试对这些关键场景进行最终确认。

🧰 Tools
🪛 Biome (1.9.4)

[error] 25-25: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 33-33: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

src/packages/dialog/content.tsx (4)

1-3: 优化导入结构,使用标准类型定义

React.MouseEvent改为直接导入MouseEvent简化了代码。同时,从@/types导入WebContentProps替代原有的ContentProps,符合类型抽象到标准规范的重构目标。


5-13: 移除了显式类型注解,保持与Taro版本一致

移除了defaultContentProps的显式类型注解,这样的变更与Taro版本保持一致,增强了代码的一致性。


16-17: 组件接口类型更新为标准规范

Content组件的类型从Partial<ContentProps>更新为Partial<WebContentProps>,确保了Web和Taro平台的类型定义一致性。


52-54: 简化事件类型,保持与标准规范一致

将事件参数类型从React.MouseEvent<HTMLDivElement>更改为MouseEvent<HTMLDivElement>,简化了类型定义,与导入变更相匹配。

🧰 Tools
🪛 Biome (1.9.4)

[error] 53-53: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

src/packages/dialog/content.taro.tsx (6)

4-4: 从标准位置导入类型定义

ContentProps从本地导入更改为从@/types导入TaroContentProps,符合类型抽象到标准规范的重构目标。


6-14: 移除了显式类型注解,保持与Web版本一致

移除了defaultContentProps的显式类型注解,与Web版本保持一致,增强了代码的一致性。


17-18: 组件接口类型更新为标准规范

Content组件的类型从Partial<ContentProps>更新为Partial<TaroContentProps>,确保了Web和Taro平台的类型定义一致性。


28-31: 添加样式和类名属性解构,优化属性访问

添加了对styleclassName属性的显式解构,使属性访问更直接,提高了代码可读性。


59-61: 直接使用解构的属性优化代码

使用解构的classNamestyle属性直接在JSX中应用,而不是通过props访问,简化了代码并提高了可读性。


54-54:

❓ Verification inconclusive

注意:移除了onClick的条件检查

移除了对onClick的条件检查,现在直接调用onClick(e)。请确保在组件使用时onClick始终被定义或在默认属性中提供了有效的默认实现。


🏁 Script executed:

#!/bin/bash
# 描述:检查TaroContentProps中的onClick实现和使用情况

# 检查TaroContentProps定义中的onClick是否必需
rg -B 2 -A 2 "TaroContentProps" --type ts

# 检查Content组件的使用,验证onClick是否总是被提供
rg -B 5 -A 5 "<Content" --type tsx -- **/dialog/**

Length of output: 1445


请确认 onClick 始终有效,避免运行时错误!

当前变更中移除了对 onClick 的条件检查,而 TaroContentProps 中定义的 onClick 是必需的,但在 Content 组件中通过 Partial 转为可选,因此直接调用 onClick(e) 可能在未传入有效函数时导致异常。请确保:

  • 在使用 Content 组件时,onClick 始终被传入;
  • 或在 defaultContentProps 中提供一个有效的默认实现(如空函数)。

由于部分验证输出(特别是 tsx 文件的查找)未能覆盖所有使用情况,建议开发者手动确认组件在所有调用场景中均满足该要求。

src/packages/dialog/dialog.taro.tsx (7)

1-11: 优化导入结构,使用标准类型定义

从React直接导入MouseEvent并从@/types导入TaroDialogProps,符合类型抽象的重构目标。同时导入defaultOverlayProps简化了默认属性的管理。


22-47: 使用属性扩展优化默认属性结构

移除了defaultProps的显式类型注解,并使用扩展运算符从defaultOverlayPropsdefaultContentProps继承属性,简化了代码结构并减少了属性重复定义。


49-86: 组件接口类型更新和参数解构优化

BaseDialog组件的类型从旧类型更新为Partial<TaroDialogProps>,并扩展了参数解构以包含更多属性,使代码更清晰直观。


109-119: 优化handleOk事件处理函数

更新了handleOk函数的事件参数类型,并在函数完成后调用onClose而不使用可选链。请确保onClose始终被定义,避免潜在错误。


129-130: 简化事件处理函数调用

移除了事件处理函数的显式类型注解,让TypeScript自动推断类型,简化了代码。

Also applies to: 144-145, 162-163


101-107:

❓ Verification inconclusive

更新事件处理函数类型和移除可选链

更新了handleCancel的事件参数类型,并移除了对onCloseonCancel的可选链调用。请确保这些函数在调用前始终被定义,避免潜在的空引用错误。


🏁 Script executed:

#!/bin/bash
# 描述:检查onClose和onCancel在BaseDialog组件中是否有默认实现

# 检查默认属性中是否定义了onClose和onCancel
rg -B 2 -A 2 "onClose: \(\) => \{\}" --type ts --type tsx -- **/dialog/**
rg -B 2 -A 2 "onCancel: \(\) => \{\}" --type ts --type tsx -- **/dialog/**

# 检查组件使用时是否总是提供这些属性
rg -B 5 -A 5 "<BaseDialog" --type tsx -- **/dialog/**

Length of output: 298


下面的修改明确了事件参数类型,并将对 onClose 和 onCancel 的可选链调用移除,以便在调用它们时能及时暴露问题。不过,目前还不清楚 BaseDialog 组件是否在所有使用场景中都确保传入了这两个函数(或在其默认属性中为它们提供了实现)。因此,请手动确认或运行下面更新后的脚本,检查:

  • 在对话框相关代码(特别是 src/packages/dialog/dialog.taro.tsx)中,handleCancel 函数在移除可选链后,对 onClose 和 onCancel 的调用都能获得有效函数。
  • BaseDialog 组件的默认属性设定中是否为 onClose 和 onCancel 提供了默认实现,或者在所有使用 <BaseDialog> 时确保传入了这两个函数。

你可以使用以下新脚本进行进一步验证(注意不要指定文件类型过滤,以避免误报):

请确保在所有相关场景中都能获得非空的函数定义,以防止运行时出现空引用错误。

总结:

  • 文件:src/packages/dialog/dialog.taro.tsx(第 101-107 行)
  • 修改了 handleCancel 的事件参数类型
  • 移除了 onCloseonCancel 的可选链调用
  • 请验证: BaseDialog 中是否始终定义或传入有效的 onCloseonCancel 函数

🏁 Script executed:

#!/bin/bash
echo "正在搜索对话框目录中 onClose 默认实现:"
rg -B 2 -A 2 "onClose: *(\(\)) *=> *\{" **/dialog/**
echo "正在搜索对话框目录中 onCancel 默认实现:"
rg -B 2 -A 2 "onCancel: *(\(\)) *=> *\{" **/dialog/**
echo "正在检查 BaseDialog 的使用情况:"
rg -B 5 -A 5 "<BaseDialog" **/dialog/**

Length of output: 614


注意:请确保 BaseDialog 中的 onClose 和 onCancel 始终有效

此次修改中更新了 handleCancel 的事件参数类型,并删除了对 onCloseonCancel 的可选链调用。请确认以下两点:

  • 在所有使用此对话框的场景中,必须为 onCloseonCancel 提供有效的实现(例如,BaseDialog 的默认属性是否包含明确的实现,或在使用 <BaseDialog> 时是否必传这两个函数),以避免运行时出现空引用错误。
  • 如果未定义默认实现,请手动检查并保证调用之前已确保这两个函数已被正确赋值。

190-216:

❓ Verification inconclusive

更新关闭图标处理逻辑

更新了关闭图标的处理逻辑,移除了对onCloseonCancel的可选链调用。同样地,在onHandleClickOverlay函数中移除了可选链。请确保这些函数在调用前始终被定义。


🏁 Script executed:

#!/bin/bash
# 描述:检查closeIcon和closeOnOverlayClick的使用情况

# 检查closeIcon默认值和使用情况
rg -B 2 -A 2 "closeIcon: " --type ts --type tsx -- **/dialog/**

# 检查closeOnOverlayClick默认值和使用情况
rg -B 2 -A 2 "closeOnOverlayClick" --type ts --type tsx -- **/dialog/**

Length of output: 197


下面的脚本命令调整了搜索方式,使用通配符来查找 .ts.tsx 文件中关于 closeIconcloseOnOverlayClick 的定义及使用情况。请运行下面新的脚本,并手动验证这些属性和回调函数是否总是被正确赋值,从而确保在调用 onCloseonCancel 时不会出错。



请重点确认:

  • closeIcon 是否始终设置了默认值或被正确传入。
  • closeOnOverlayClick 的默认值逻辑及使用是否符合预期。

在确认这些前提条件之后,再移除对 onCloseonCancel 的可选链调用。请核查后更新代码,如确有必要调整默认值定义。


🏁 Script executed:

#!/bin/bash
# 查找 dialog 目录中包含 closeIcon 定义及使用的代码
rg -B 2 -A 2 "closeIcon:" -g "*.tsx" -g "*.ts" **/dialog/**

# 查找 dialog 目录中包含 closeOnOverlayClick 定义及使用的代码
rg -B 2 -A 2 "closeOnOverlayClick" -g "*.tsx" -g "*.ts" **/dialog/**

Length of output: 360


请确保 onCloseonCancel 调用前,其默认实现或传入值始终已被正确设置,避免因移除可选链调用而出现未定义错误。

  • 当前修改移除了 onCloseonCancel 调用时的可选链保护,请在 src/packages/dialog/dialog.taro.tsx 中确认:
    • closeIcon 是否始终赋予了默认值或正确传入;
    • closeOnOverlayClick(及其默认逻辑)是否能够确保相关回调函数在调用前已定义;
  • 如果确认预期逻辑及默认值设置无遗漏,则可安全移除可选链,否则需要增加断言或默认值保护。

请使用以下新的脚本检查文件中的相关定义与使用情况,并手动验证它们是否存在且符合预期:


🏁 Script executed:

#!/bin/bash
# 检查 src/packages/dialog/dialog.taro.tsx 文件中 closeIcon 的定义及使用情况
rg -B 2 -A 2 "closeIcon:" src/packages/dialog/dialog.taro.tsx

# 检查 src/packages/dialog/dialog.taro.tsx 文件中 closeOnOverlayClick 的定义及使用情况
rg -B 2 -A 2 "closeOnOverlayClick" src/packages/dialog/dialog.taro.tsx

Length of output: 877


更新关闭图标与关闭事件处理逻辑

src/packages/dialog/dialog.taro.tsx 中,对 onCloseonCancel 的可选链调用已被移除,同时在 onHandleClickOverlay 函数中也同步取消了可选链保护。请开发者确认以下几点:

  • 确保组件的 props 中,onCloseonCancel 始终被正确且必定赋值,否则直接调用会导致未定义错误。
  • 检查 closeIcon 的默认值(目前默认为 false)以及相关逻辑,确认不会因默认值问题导致不可预期的行为。
  • 验证 closeOnOverlayClick 的使用场景,确保其在触发时能够正确调用 onOverlayClick 和后续的关闭逻辑。

如果以上几项都经过核实且符合预期,则可以保留当前修改;否则,请增加必要的断言或默认值保护,确保组件在所有情况下都能稳定运行。

🧰 Tools
🪛 Biome (1.9.4)

[error] 212-212: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

src/packages/dialog/dialog.tsx (8)

1-6: 导入 React 相关依赖的重构看起来合理
当前实现并无明显问题,代码可读性良好,继续保持。


114-125: 垂直布局下的取消按钮渲染逻辑清晰可读
通过将取消按钮独立为函数,能够让按钮布局更可扩展,值得肯定。


142-159: 确认按钮的异步处理方式设计合理
在发生错误时重置 loading 的逻辑完整,能够有效避免用户界面的卡顿或不一致。


201-206: 缺少对 onHandleClickOverlay 行为的单测
建议针对点击遮罩层后的关闭操作进行测试,确保逻辑分支得到充分覆盖。

🧰 Tools
🪛 Biome (1.9.4)

[error] 202-202: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🪛 GitHub Check: codecov/patch

[warning] 201-206: src/packages/dialog/dialog.tsx#L201-L206
Added lines #L201 - L206 were not covered by tests


208-231: 引入 CSSTransition 使弹窗过渡更加平滑
过渡动画的可维护性较高,且逻辑布局清晰,与组件结构衔接自然。


235-247: 可选蒙层及其属性配置,可适应多样化场景
对 overlay、className、style 等做出灵活处理,能够满足不同交互需求。


253-256: Dialog.confirm 切换至使用 Partial
与最新的类型定义相符合,保证了类型声明的一致性。


257-262: Dialog.alert 基于同一底层实现减少重复代码
统一在 confirm 函数内进行处理,保留了调用方式的简洁度。

src/types/spec/dialog/base.ts (1)

42-45: beforeClose/beforeCancel 等函数的布尔返回值逻辑直观
通过返回布尔值判定是否继续流程,语义明确,易于维护。

🧰 Tools
🪛 Biome (1.9.4)

[error] 44-44: void is confusing inside a union type.

Unsafe fix: Use undefined instead.

(lint/suspicious/noConfusingVoidType)

Comment on lines +1 to +5
import { BaseDialog, BaseContentProps } from './base'

export interface WebContentProps extends BaseContentProps {
onClick: (event: MouseEvent) => void
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

缺少 MouseEvent 类型的导入声明

MouseEvent 类型没有明确的导入来源,这可能导致类型错误。如果是指 React 的鼠标事件类型,应该从 React 中导入。

建议修改为:

-import { BaseDialog, BaseContentProps } from './base'
+import { BaseDialog, BaseContentProps } from './base'
+import { MouseEvent } from 'react'

export interface WebContentProps extends BaseContentProps {
  onClick: (event: MouseEvent) => void
}
📝 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
import { BaseDialog, BaseContentProps } from './base'
export interface WebContentProps extends BaseContentProps {
onClick: (event: MouseEvent) => void
}
import { BaseDialog, BaseContentProps } from './base'
import { MouseEvent } from 'react'
export interface WebContentProps extends BaseContentProps {
onClick: (event: MouseEvent) => void
}

@Miles-hxy Miles-hxy merged commit 5545133 into jdf2e:feat_v3.x Apr 3, 2025
8 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Apr 14, 2025
20 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.x Target branch 3.x action:review This PR needs more reviews (less than 2 approvals) size/XL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants