Skip to content

fix: 🐛 修复 InputNumber 微信小程序设置了precision后无法输入小数点的问题 - #902

Merged
Moonofweisheng merged 1 commit into
masterfrom
fix/weapp-input-number
Feb 19, 2025
Merged

fix: 🐛 修复 InputNumber 微信小程序设置了precision后无法输入小数点的问题#902
Moonofweisheng merged 1 commit into
masterfrom
fix/weapp-input-number

Conversation

@Moonofweisheng

@Moonofweisheng Moonofweisheng commented Feb 19, 2025

Copy link
Copy Markdown
Owner

Closes: #878

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

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

🔗 相关 Issue

#878

💡 需求背景和解决方案

input-number在更新modelValue时,会对绑定值进行格式化,造成例如1.被格式化成1的现象。估在允许输入小数的场景下,对有且仅在末尾有一个小数点的数字直接更新,不进行格式化。

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

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

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

Summary by CodeRabbit

  • 新功能

    • 更新了数字输入组件的精度设置,默认值与显示精度调整为一位小数。
    • 加强了事件处理逻辑,以便更好地区分不同的交互场景,提升输入体验。
  • 重构

    • 优化了数值更新与验证流程,使输入响应更精准、流畅。

@vercel

vercel Bot commented Feb 19, 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 Feb 19, 2025 4:58am

@coderabbitai

coderabbitai Bot commented Feb 19, 2025

Copy link
Copy Markdown

Walkthrough

本次 PR 主要对 wd-input-number 组件内的小数精度和事件处理逻辑进行调整。在示例页面中,将演示精度从 2 位调整为 1 位,同时更新了相关数值。组件的类型定义文件中新增了两个类型(InputNumberBeforeChangeInputNumberEventType),并对 beforeChange 属性作出了相应修改。在组件实现中,更新了 updateValue 方法,增加了辅助函数和更细化的事件类型处理,增强了代码文档说明,提升了组件内部流程的清晰度。

Changes

文件路径 修改说明
src/pages/inputNumber/Index.vue 将 demo 中 wd-input-number 组件的 :precision2 调整为 1,并修改 value6 的初始值从 '1.205' 更新为 '1.2'
src/uni_modules/wot-design-uni/components/wd-input-number/{types.ts,wd-input-number.vue} types.ts 中新增 InputNumberBeforeChange 类型和 InputNumberEventType 枚举,并更新 beforeChange 的类型;在组件中修改 updateValue 方法,加入 doUpdatecleanExtraDecimal 辅助函数,实现了针对不同事件类型的精细处理并增加详细注释。

Sequence Diagram(s)

sequenceDiagram
    participant 用户
    participant 组件 as wd-input-number组件
    用户->>组件: 触发输入事件 (eventType = Input)
    组件->>组件: 调用 updateValue(value, eventType)
    组件->>组件: 检查是否以小数点结尾
    alt 值以小数点结尾
        组件->>组件: 直接更新值,不进行格式化
    else 非小数点结尾
        组件->>组件: 调用 doUpdate(value)进行更新
        组件-->>用户: 触发更新完成事件
    end
Loading

Possibly related PRs

Poem

我是一只编码小兔子,
跳跃在代码的花园里,
精度轻调如风过耳,
类型新添点亮前程,
更新流转间快乐无限,
愿代码如诗,美好无限! 🐰💻


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8b4d2ed and c13c06e.

📒 Files selected for processing (3)
  • src/pages/inputNumber/Index.vue (2 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 (6 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (8)
src/uni_modules/wot-design-uni/components/wd-input-number/types.ts (2)

13-18: 代码结构清晰,文档完整!

类型定义清晰,JSDoc 注释完整地说明了参数和返回值。


20-32: 枚举设计合理,有助于事件处理!

事件类型枚举的设计很好地区分了不同的输入来源,这对于正确处理小数点输入很有帮助。

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

25-25: 示例更新合理!

将精度从 2 位改为 1 位,同时设置步进值为 0.1,这样的示例更容易验证小数点输入功能。


52-52: 初始值调整正确!

初始值从 '1.205' 改为 '1.2',与新的精度设置保持一致。

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

152-169: 清理小数点的逻辑完善!

cleanExtraDecimal 函数很好地处理了以下情况:

  1. 当允许小数时,保留第一个小数点
  2. 当不允许小数时,只保留整数部分

176-203: 更新逻辑优化合理!

  1. 通过 eventType 参数区分不同的输入来源
  2. 对于以小数点结尾的输入进行特殊处理,避免格式化
  3. 使用 doUpdate 函数统一处理更新逻辑

232-236: 输入处理逻辑优化!

使用 InputNumberEventType.Input 明确标识用户输入事件,提高代码可读性。


237-241: 失焦处理逻辑优化!

使用 InputNumberEventType.Blur 处理失焦事件,确保在失焦时正确格式化输入值。

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

@netlify

netlify Bot commented Feb 19, 2025

Copy link
Copy Markdown

Deploy Preview for wot-design-uni ready!

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

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.

[Bug 上报] wd-input-number设置小数精度不能输入小数点

1 participant