Skip to content

docs: ✏️ Table 表格组件提供结合分页器使用的demo#738

Merged
Moonofweisheng merged 1 commit intomasterfrom
docs/table-pagination
Nov 26, 2024
Merged

docs: ✏️ Table 表格组件提供结合分页器使用的demo#738
Moonofweisheng merged 1 commit intomasterfrom
docs/table-pagination

Conversation

@Moonofweisheng
Copy link
Owner

@Moonofweisheng Moonofweisheng commented Nov 25, 2024

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

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

🔗 相关 Issue

💡 需求背景和解决方案

Table 表格组件提供结合分页器使用的demo,方便用户使用table时处理分页。

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

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

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

Summary by CodeRabbit

  • 新功能

    • 更新了 wd-table 组件的文档,新增“结合分页器使用”部分,展示如何与分页组件集成。
    • 添加了“基础用法”部分的详细信息块,提供基本表格使用的示例。
    • 添加了“自定义列模板”部分的详细信息块,提供自定义列渲染的演示。
    • 引入了分页功能,允许用户按页显示数据。
  • 文档

    • 简化了 wd-table-colsortable 属性的语法,提升可读性。

@vercel
Copy link

vercel bot commented Nov 25, 2024

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 Nov 26, 2024 2:58am

@coderabbitai
Copy link

coderabbitai bot commented Nov 25, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

此次更改主要集中在wd-table组件的文档和示例代码上。文档中新增了“结合分页器使用”部分,展示了如何将wd-table与分页组件集成。示例代码的sortable属性语法进行了简化,提升了可读性。此外,文档中还增加了“基础用法”和“自定义列模板”部分的详细说明,提供了自定义列渲染的示例。Index.vue文件也进行了相应修改,新增了分页功能并更新了相关的示例块。

Changes

文件路径 更改摘要
docs/component/table.md 新增“结合分页器使用”部分;新增“基础用法”和“自定义列模板”详细说明;更新wd-table-colsortable属性语法;新增TableData接口。
src/pages/table/Index.vue 移除wd-table-col:sortable属性,改为sortable;新增“结合分页器”示例块及相关分页逻辑;更新dataList类型为TableData接口。

Possibly related PRs

Poem

在桌子上,数据排成行,
分页器来,轻松又畅快,
列的排序,简化了语法,
兔子欢跳,乐在其中呀! 🐇✨

Warning

Rate limit exceeded

@Moonofweisheng has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 10 minutes and 37 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between d211e14 and ece013c.


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

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Nov 25, 2024

Deploying wot-design-uni with  Cloudflare Pages  Cloudflare Pages

Latest commit: ece013c
Status:⚡️  Build in progress...

View logs

@netlify
Copy link

netlify bot commented Nov 25, 2024

Deploy Preview for wot-design-uni ready!

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

🧹 Outside diff range and nitpick comments (4)
src/pages/table/Index.vue (1)

71-82: 建议优化分页示例的用户体验

当前实现可以考虑以下几点改进:

  1. 建议设置固定的表格高度,避免分页切换时的布局抖动
  2. 建议为分页器添加 aria-label 属性,提升无障碍访问体验
  3. 建议在页面切换时添加加载状态提示

建议参考以下修改:

- <wd-table :data="paginationData" height="auto">
+ <wd-table :data="paginationData" height="328px" :loading="isLoading">
   <!-- ... -->
 </wd-table>
- <wd-pagination custom-style="border: 1px solid #ececec;border-top:none" v-model="page" :total="total"></wd-pagination>
+ <wd-pagination
+   custom-style="border: 1px solid #ececec;border-top:none"
+   v-model="page"
+   :total="total"
+   aria-label="表格分页器">
+ </wd-pagination>
docs/component/table.md (3)

Line range hint 135-241: 建议补充自定义模板说明

建议在示例代码前添加更详细的说明,解释自定义模板的具体用法和注意事项,特别是关于作用域插槽 rowindex 参数的使用方式。


243-424: 建议完善分页示例

分页示例可以进一步优化:

  1. 建议添加边界情况的处理,如数据为空时的展示
  2. 建议补充分页器事件(如 change 事件)的处理示例
  3. 建议说明分页器的其他配置项(如 page-size)的使用方法

建议添加以下内容:

 const paginationData = computed(() => {
+  if (!dataList.value.length) {
+    return []
+  }
   // 按页码和每页条数截取数据
   return dataList.value.slice((page.value - 1) * pageSize.value, page.value * pageSize.value)
 })

+// 分页改变事件处理
+function handlePageChange(newPage: number) {
+  page.value = newPage
+  // 这里可以添加获取新数据的逻辑
+}

427-436: 建议优化表格格式

建议调整表格的对齐方式,使用左对齐提升可读性:

-| 参数       | 说明                                                | 类型                         | 可选值 | 默认值 | 最低版本 |
-| ---------- | --------------------------------------------------- | ---------------------------- | ------ | ------ | -------- |
+| 参数 | 说明 | 类型 | 可选值 | 默认值 | 最低版本 |
+| --- | --- | --- | --- | --- | --- |
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between abc8488 and d211e14.

📒 Files selected for processing (2)
  • docs/component/table.md (6 hunks)
  • src/pages/table/Index.vue (4 hunks)
🔇 Additional comments (5)
src/pages/table/Index.vue (3)

33-35: 代码简化优化得当!

:sortable="true" 简化为 sortable 使代码更加简洁,同时保持了相同的功能。


44-46: 保持了代码风格的一致性!

与固定列示例保持一致的简化写法,提高了代码的可维护性。


55-64: 自定义模板部分代码优化合理!

在保持自定义模板功能的同时,统一了属性的书写方式。

docs/component/table.md (2)

Line range hint 11-41: 代码示例结构优化

使用 details 标签包装示例代码提高了文档的可读性,便于用户按需展开查看。


64-72: 布尔属性语法优化

:sortable="true" 简化为 sortable 使代码更简洁,符合 Vue.js 最佳实践。

Comment on lines +240 to +260
const page = ref<number>(1)
const pageSize = ref<number>(10)

const total = ref<number>(dataList.value.length)

const paginationData = computed(() => {
// 按页码和每页条数截取数据
return dataList.value.slice((page.value - 1) * pageSize.value, page.value * pageSize.value)
})
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

建议完善分页逻辑的健壮性

当前分页实现可以考虑以下几点改进:

  1. pageSize 建议作为可配置项,允许用户自定义每页显示条数
  2. 建议添加边界条件处理,如数据为空时的情况
  3. 建议使用 TypeScript 接口定义数据结构,提升类型安全性

建议参考以下修改:

+ interface TableData {
+   name: string
+   school: string
+   major: string
+   gender: string
+   graduation: string
+   grade: number
+   compare: string
+   hobby: string
+ }

- const dataList = ref<Record<string, any>[]>([
+ const dataList = ref<TableData[]>([

+ const isLoading = ref<boolean>(false)
const page = ref<number>(1)
- const pageSize = ref<number>(10)
+ const pageSize = ref<number>(10)
+ const pageSizeOptions = [10, 20, 50]

const total = ref<number>(dataList.value.length)

const paginationData = computed(() => {
+ if (!dataList.value.length) return []
  // 按页码和每页条数截取数据
  const start = (page.value - 1) * pageSize.value
  const end = page.value * pageSize.value
+ return dataList.value.slice(Math.max(0, start), Math.min(end, dataList.value.length))
})

Committable suggestion skipped: line range outside the PR's diff.

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