Skip to content

fix: 🐛 修复分页组件为0时不更新页数问题#903

Merged
Moonofweisheng merged 1 commit into
Moonofweisheng:masterfrom
Qiu-Jun:master
Feb 19, 2025
Merged

fix: 🐛 修复分页组件为0时不更新页数问题#903
Moonofweisheng merged 1 commit into
Moonofweisheng:masterfrom
Qiu-Jun:master

Conversation

@Qiu-Jun

@Qiu-Jun Qiu-Jun commented Feb 19, 2025

Copy link
Copy Markdown
Contributor

Closes: #897

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

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

🔗 相关 Issue

#897

💡 需求背景和解决方案

我项目中,商家了一堆活动商品,但由于活动临时变动,需要全部下架,此时用户在滚动的时候,获取到数据total为0了,但是因为if判断跳过了,导致界面的页数不变

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

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

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • 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 7:14am

@coderabbitai

coderabbitai Bot commented Feb 19, 2025

Copy link
Copy Markdown

Walkthrough

此次更改集中在 wd-pagination.vue 组件的 updateTotalPage 函数上。原先在计算总页数前会先判断 total 的真值,而现在直接使用 Math.ceil(total / pageSize) 来计算 totalPageNum。这种修改可能导致在 total 为零或未定义时出现意外行为。

Changes

文件 更改描述
src/.../wd-pagination.vue 修改 updateTotalPage 函数,移除 total 真值判断,直接通过 Math.ceil(total/pageSize) 获取总页数

Sequence Diagram(s)

sequenceDiagram
    participant 用户
    participant wd分页组件 as wd-pagination.vue
    用户->>wd分页组件: 触发分页更新
    wd分页组件->>wd分页组件: 执行 updateTotalPage()
    wd分页组件->>wd分页组件: 计算 totalPageNum = Math.ceil(total / pageSize)
    wd分页组件->>用户: 更新分页显示
Loading

Suggested reviewers

  • Moonofweisheng

Poem

我是一只欢跳的小兔子,
代码中跃动着新的节奏,
分页逻辑更直接明了,
没有了多余的条件束缚,
愿改进如春风般温柔 🐰✨
跳跃吧,代码的每一步!


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!

Built without sensitive environment variables

Name Link
🔨 Latest commit 6b057ad
🔍 Latest deploy log https://app.netlify.com/sites/wot-design-uni/deploys/67b58471f90ddc0008d2f092
😎 Deploy Preview https://deploy-preview-903--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-pagination/wd-pagination.vue (2)

102-105: 修复了总数为 0 时的分页问题,建议增加边界条件处理。

当前修改解决了总数为 0 时不更新页数的问题,这是正确的方向。不过建议增加一些边界条件的处理,以提高组件的健壮性。

建议按如下方式优化代码:

function updateTotalPage() {
  const { total, pageSize } = props
+ if (pageSize <= 0) {
+   console.warn('[WotDesign] pageSize 必须大于 0')
+   return
+ }
  totalPageNum.value = Math.ceil(total / pageSize)
}

76-82: 建议完善 total 属性的类型定义。

为了提高代码的类型安全性,建议在 props 的类型定义中明确指定 total 为 number 类型。

建议在 types.ts 中更新类型定义:

export const paginationProps = {
  total: {
    type: Number,
    required: true
  }
  // ... 其他属性
}
📜 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 6b057ad.

📒 Files selected for processing (1)
  • src/uni_modules/wot-design-uni/components/wd-pagination/wd-pagination.vue (1 hunks)

@Moonofweisheng Moonofweisheng merged commit 604faeb into Moonofweisheng:master Feb 19, 2025
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 上报] 分页组件总数为0时页数数据不更新

2 participants