Skip to content

perf: ⚡ 增强 wd-drop-menu 组件,优化遮罩层闪烁#974

Merged
Moonofweisheng merged 2 commits into
Moonofweisheng:masterfrom
yuhengshen:feat-drop-menu-overlay
Mar 28, 2025
Merged

perf: ⚡ 增强 wd-drop-menu 组件,优化遮罩层闪烁#974
Moonofweisheng merged 2 commits into
Moonofweisheng:masterfrom
yuhengshen:feat-drop-menu-overlay

Conversation

@yuhengshen

@yuhengshen yuhengshen commented Mar 25, 2025

Copy link
Copy Markdown
Contributor

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

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

🔗 相关 Issue

💡 需求背景和解决方案

处理切换 drop menu 时,overlay 闪烁问题。
PixPin_2025-03-25_23-24-29

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

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

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

Summary by CodeRabbit

  • 新增功能

    • 引入了交互覆盖层,提升了下拉菜单弹出时的视觉及点击控制体验。
  • 重构

    • 优化了下拉菜单及菜单项的事件响应,取消了原有模态点击关闭机制,实现了更顺畅的操作流程。

@vercel

vercel Bot commented Mar 25, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
wot-design-uni ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 25, 2025 3:30pm

@coderabbitai

coderabbitai Bot commented Mar 25, 2025

Copy link
Copy Markdown

Walkthrough

本次更新对两个下拉菜单组件进行了调整。对于菜单项组件,修改了模板和脚本,更新了指针事件处理,并移除了模态点击关闭逻辑。对于下拉菜单组件,新增了覆盖层组件,优化了点击事件处理,并引入了新的计算属性和响应式变量以控制覆盖层显示和菜单交互。

Changes

文件 更改摘要
src/uni_modules/.../wd-drop-menu-item.vue 修改模板中的指针事件:添加 pointer-events: none;移除 @click-modal 事件与 closeOnClickModal 响应式引用。
src/uni_modules/.../wd-drop-menu.vue 新增 <wd-overlay> 组件;更新点击事件为 @click.stop.prevent;新增 handleClickOverlay 方法、modalStyleshowOverlay 计算属性,以及 overlayVisible 变量。

Sequence Diagram(s)

sequenceDiagram
    participant U as 用户
    participant O as wd-overlay
    participant DM as wd-drop-menu
    U->>O: 点击覆盖层
    O->>DM: 触发 handleClickOverlay()
    DM->>DM: 检查 closeOnClickModal 条件
    DM-->>O: 隐藏覆盖层(若条件满足)
Loading

Suggested reviewers

  • Moonofweisheng

Poem

我是一只快乐的代码兔,
跳跃在逻辑与功能之间。
遗弃了旧日模态的印记,
覆盖新意在每一次点击中。
代码中藏着诗意,开发更添欢欣。


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.

@netlify

netlify Bot commented Mar 25, 2025

Copy link
Copy Markdown

Deploy Preview for wot-design-uni ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 311d255
🔍 Latest deploy log https://app.netlify.com/sites/wot-design-uni/deploys/67e2cbd2a96efa0008a79c39
😎 Deploy Preview https://deploy-preview-974--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 site configuration.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/uni_modules/wot-design-uni/components/wd-drop-menu/wd-drop-menu.vue (2)

52-56: 建议使用对象形式的样式绑定以提升可维护性
现使用字符串拼接返回内联样式虽能工作,但若样式规则进一步复杂化,后续扩展和可读性可能受影响。可考虑改为返回对象形式的绑定,例如:

const modalStyle = computed(() => {
  return props.direction === 'down'
    ? { top: `calc(var(--window-top) + ${offset.value}px)`, bottom: 0 }
    : { top: 0, bottom: `calc(var(--window-bottom) + ${offset.value}px)` }
})

102-102: 空函数 noop() 的使用可通过指令修饰符简化
若仅用于阻止事件默认行为,可在模板中使用修饰符 @click.prevent.stop 等,减少不必要的空函数声明,提高可读性。

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 32eed53 and 311d255.

📒 Files selected for processing (1)
  • src/uni_modules/wot-design-uni/components/wd-drop-menu/wd-drop-menu.vue (4 hunks)
🔇 Additional comments (6)
src/uni_modules/wot-design-uni/components/wd-drop-menu/wd-drop-menu.vue (6)

2-3: 关于使用 @click.stop.prevent="noop" 的处理需要确认是否符合交互预期
此处通过同时阻止默认事件与冒泡来防止父级处理逻辑,需要确保这不会对用户操作造成意外干扰,比如导致无法滚动、阻断其他交互等。建议在不同终端上测试该修改,以确认是否符合需求。


39-45: 导入新组件及依赖在 <script setup> 场景下可直接使用
在 Vue 3 的 <script setup> 模式中,可以直接使用导入的组件 wdOverlay。目前看来无问题,只需确保所使用的构建工具和环境已正确配置对 <script setup> 的支持。


62-64: showOverlay 逻辑简洁可读
基于子组件的状态来判断是否显示遮罩层,思路清晰且易于维护。


66-66: 新增 overlayVisible 状态合理
该变量与 showOverlay 分离,结合定时器实现延迟关闭,可降低界面闪烁问题的发生。此处设计简洁明了。


71-83: 通过 watch + setTimeout 处理遮罩层闪烁逻辑可能带来潜在兼容性问题,需要验证
使用 16ms 的延时可能仍会在部分终端或慢速设备上出现抖动或无效情况,建议在各端(如微信小程序、支付宝小程序等)进行验证,或考虑使用更稳妥的动画/过渡手段来处理闪烁。


146-153: handleClickOverlay 符合关闭所有打开菜单的需求
在遮罩层被点击时,根据 closeOnClickModal 判断后关闭所有子菜单项,逻辑清晰且易于理解,对于多菜单联动非常实用。

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.

2 participants