Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ✨ 新增 InputNumber 组件支持长按加减功能 #910

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

chen-ziwen
Copy link

@chen-ziwen chen-ziwen commented Feb 20, 2025

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

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

🔗 相关 Issue

💡 需求背景和解决方案

添加 longPress 属性用于长按控制加减,项目中需要用到这个功能。

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

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

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

Summary by CodeRabbit

  • 新功能

    • 数字输入组件现支持长按加减,允许用户通过长按按钮实现数值的连续增减。
    • 新增演示示例展示了如何使用长按功能。
  • 文档

    • 更新了数字输入组件的使用说明,新增“长按加减”部分和属性说明,帮助用户了解该功能的使用方法。

Copy link

vercel bot commented Feb 20, 2025

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 Feb 20, 2025 1:30pm

Copy link

coderabbitai bot commented Feb 20, 2025

Walkthrough

本次变更主要针对 wd-input-number 组件及相关文档进行更新,新增了长按加减功能。文档中更新了函数命名和变量类型,并新增了“长按加减”使用示例及属性说明。演示页面增加了对应的功能块,同时组件内部通过引入 OperationType 类型和统一的事件处理逻辑,实现了对长按事件的处理和连续加减操作。

Changes

文件 修改说明
docs/component/input-number.md 重命名 handleChange1handleChange;更新变量类型为 `number
src/pages/inputNumber/Index.vue 新增长按加减功能演示块;新增变量 value12 与事件处理函数 handleChange12
src/uni_modules/.../types.ts 添加新类型 OperationType('add'
src/uni_modules/.../wd-input-number.vue 移除旧的 add / sub 方法;新增统一方法 handleClick 处理加减操作;增加长按事件处理(touchstarttouchend)及长按计时器变量

Sequence Diagram(s)

sequenceDiagram
    participant U as 用户
    participant B as 按钮
    participant C as wd-input-number组件
    U->>B: 按下按钮
    B->>C: 触发 touchstart 事件
    C->>C: 执行 handleTouchStart(),启动计时器
    loop 长按期间
        C->>C: 执行 handleClick('add' / 'sub')
    end
    U->>B: 松开按钮
    B->>C: 触发 touchend 事件
    C->>C: 调用 clearlongPressTimer() 清除计时器
Loading

Possibly related PRs

Suggested reviewers

  • Moonofweisheng

Poem

我是一只快乐的小兔子,
看着代码花儿绽放,
长按功能快如风,
加减间舞动奇妙节拍,
数字在跳跃中欢唱,
代码如梦,带我奔向星光!
🐰✨

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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.

Copy link

netlify bot commented Feb 20, 2025

Deploy Preview for wot-design-uni ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit bc6b78a
🔍 Latest deploy log https://app.netlify.com/sites/wot-design-uni/deploys/67b72e3bd3722600080259b6
😎 Deploy Preview https://deploy-preview-910--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.

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 (2)
src/uni_modules/wot-design-uni/components/wd-input-number/wd-input-number.vue (2)

250-257: 建议优化长按定时器间隔

当前长按加减的时间间隔固定为 250ms,建议将此值作为可配置项,以便根据不同场景调整响应速度。

+const LONG_PRESS_INTERVAL = 250 // ms
 function longPressStep(type: OperationType) {
   clearlongPressTimer()
   longPressTimer = setTimeout(() => {
     handleClick(type)
     longPressStep(type)
-  }, 250)
+  }, LONG_PRESS_INTERVAL)
 }

259-267: 建议优化长按触发时间

当前长按触发的延迟时间固定为 600ms,建议将此值作为可配置项,以提供更灵活的用户体验。

+const LONG_PRESS_DELAY = 600 // ms
 function handleTouchStart(type: OperationType) {
   if (!props.longPress) return
   clearlongPressTimer()
   longPressTimer = setTimeout(() => {
     handleClick(type)
     longPressStep(type)
-  }, 600)
+  }, LONG_PRESS_DELAY)
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between eb514f0 and bc6b78a.

📒 Files selected for processing (4)
  • docs/component/input-number.md (4 hunks)
  • src/pages/inputNumber/Index.vue (3 hunks)
  • src/uni_modules/wot-design-uni/components/wd-input-number/types.ts (2 hunks)
  • src/uni_modules/wot-design-uni/components/wd-input-number/wd-input-number.vue (5 hunks)
🧰 Additional context used
🧠 Learnings (1)
docs/component/input-number.md (1)
Learnt from: chen-ziwen
PR: Moonofweisheng/wot-design-uni#909
File: docs/component/input-number.md:93-98
Timestamp: 2025-02-20T12:31:40.241Z
Learning: In the InputNumber component documentation, function naming should be consistent across all examples, using `handleChange` instead of variations like `handleChange1`.
🔇 Additional comments (7)
src/uni_modules/wot-design-uni/components/wd-input-number/types.ts (2)

20-20: 类型定义清晰简洁!

OperationType 类型定义明确地限制了操作类型为 'add' 或 'sub',有助于类型安全。


101-105: 属性文档完整!

longPress 属性的类型定义和默认值设置合理,文档注释清晰地说明了属性的用途。

src/pages/inputNumber/Index.vue (2)

39-41: 示例代码结构规范!

新增的长按加减示例遵循了现有的代码结构和命名规范。


61-61: 处理函数实现统一!

value12handleChange12 的实现与其他示例保持一致,便于理解和维护。

Also applies to: 90-92

src/uni_modules/wot-design-uni/components/wd-input-number/wd-input-number.vue (2)

4-11: 事件处理逻辑优化!

减号和加号按钮的事件处理进行了统一,使用 handleClick 方法处理点击事件,同时添加了长按事件的支持,代码结构更加清晰。

Also applies to: 29-36


233-237: 统一的操作处理函数实现清晰!

handleClick 函数通过 OperationType 类型参数统一处理加减操作,实现简洁且易于维护。

docs/component/input-number.md (1)

127-133: 文档示例清晰完整!

新增的长按加减功能文档结构清晰,示例代码简洁易懂。

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.

1 participant