Skip to content

Feat ✨ drop menu 添加 filterable 支持本地搜索 #1040

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

carsum
Copy link
Contributor

@carsum carsum commented May 7, 2025

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

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

🔗 相关 Issue

需求来源: #550
之前的解决方案已讨论完成, 但是合并代码已出现问题, 故重新提交请求, 之前的PR: #552

💡 需求背景和解决方案

当下拉选项过多时, 有搜索功能可以更方便的找到目标, 通过在组件中添加filterable属性, 在下拉顶部增加一个检索框, 输入内容, 则过滤出相应选项

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

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

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

Summary by CodeRabbit

  • 新功能

    • 下拉菜单组件新增本地搜索功能。支持通过 filterable 属性开启搜索,并可自定义搜索框占位符(filter-placeholder)。
  • 文档

    • DropMenu 组件文档新增本地搜索功能说明及示例,属性表补充 filterable 和 filter-placeholder。
    • 多处文档修正了徽章图片链接的换行格式,确保图片正常显示。
  • 其他

    • 移除 Petercat AI 助手相关的样式文件及网站集成配置。

Moonofweisheng and others added 4 commits May 7, 2025 15:03
加入本地搜索的使用文档
ts加入对应的搜索属性
加入本地搜索对应逻辑功能
Copy link

netlify bot commented May 7, 2025

Deploy Preview for wot-design-uni ready!

Built without sensitive environment variables

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

vercel bot commented May 7, 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 May 7, 2025 8:35am

Copy link

coderabbitai bot commented May 7, 2025

Walkthrough

本次变更主要修复了多个文档和徽章图片的 Markdown 格式问题,删除了 Petercat AI 助手相关的前端集成与样式,并为下拉菜单组件(DropMenu)新增了本地搜索功能及相关属性,完善了组件类型定义和文档说明。

Changes

文件/路径分组 变更摘要
README.md
README_en.md
src/uni_modules/wot-design-uni/readme.md
docs/.vitepress/theme/components/HomeStar.vue
修正 Markdown 图片标签的 src 属性中断行,保证徽章图片正常显示;部分文件仅更新时间戳。
docs/.vitepress/config.mts
docs/public/petercatai/assistant.min.css
移除 Petercat AI 助手相关的样式、脚本和初始化配置,删除对应的 min.css 样式文件。
docs/component/drop-menu.md 文档新增下拉菜单本地搜索功能说明,补充 filterablefilter-placeholder 属性及用法示例,完善属性表。
src/uni_modules/wot-design-uni/components/wd-drop-menu-item/types.ts 在 dropMenuItemProps 中新增 filterable(布尔型,默认 false)和 filterPlaceholder(字符串型)属性。
src/uni_modules/wot-design-uni/components/wd-drop-menu-item/wd-drop-menu-item.vue 新增本地搜索功能:增加响应式变量 filterValfilterOptions,实现过滤逻辑与输入框,调整选项渲染与选择逻辑。

Sequence Diagram(s)

sequenceDiagram
    participant 用户
    participant DropMenuItem组件
    participant wd-search输入框

    用户->>DropMenuItem组件: 打开下拉菜单
    DropMenuItem组件->>wd-search输入框: 显示(若 filterable 为 true)
    用户->>wd-search输入框: 输入关键字
    wd-search输入框->>DropMenuItem组件: 触发 handleFilterChange
    DropMenuItem组件->>DropMenuItem组件: 过滤 options,更新 filterOptions
    用户->>DropMenuItem组件: 选择过滤后的选项
    DropMenuItem组件->>DropMenuItem组件: 触发 choose,处理选中逻辑
Loading

Suggested reviewers

  • Moonofweisheng

Poem

🐇
格式修正徽章亮,
助手离场风也轻。
下拉菜单添搜索,
过滤筛选更聪明。
文档属性新补全,
代码春意正盈盈。

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in this 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.

Copy link

Walkthrough

此PR为下拉菜单组件添加了filterable属性,支持本地搜索功能。用户可以在下拉菜单顶部输入内容以过滤选项,从而更方便地找到目标项。此外,还更新了TypeScript定义以支持此新特性。

Changes

文件 概要
src/uni_modules/wot-design-uni/components/wd-drop-menu-item/types.ts 添加了filterablefilterPlaceholder属性以支持本地搜索。
src/uni_modules/wot-design-uni/components/wd-drop-menu-item/wd-drop-menu-item.vue 实现了本地搜索功能,包括搜索框和选项过滤逻辑。
docs/component/drop-menu.md 更新文档以说明新特性和用法。
README.md, README_en.md, src/uni_modules/wot-design-uni/readme.md, docs/.vitepress/theme/components/HomeStar.vue 修复了徽章链接的格式问题。
docs/.vitepress/config.mts 移除了不必要的脚本和样式链接。

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: 0

🧹 Nitpick comments (5)
src/uni_modules/wot-design-uni/components/wd-drop-menu-item/types.ts (1)

74-79: 需要修复格式问题

代码存在一些空格格式问题,需要修正以符合项目代码风格。

以下为修复格式问题的建议:

-  customPopupStyle: makeStringProp(''),
-  
-  /** 可搜索(目前只支持本地搜索) */
-  filterable: makeBooleanProp(false),
-  /** 搜索框占位符 */
-  filterPlaceholder: String,
+  customPopupStyle: makeStringProp(''),
+  /** 可搜索(目前只支持本地搜索) */
+  filterable: makeBooleanProp(false),
+  /** 搜索框占位符 */
+  filterPlaceholder: String
🧰 Tools
🪛 ESLint

[error] 75-75: Delete ··

(prettier/prettier)


[error] 79-79: Delete ,

(prettier/prettier)

src/uni_modules/wot-design-uni/components/wd-drop-menu-item/wd-drop-menu-item.vue (4)

159-170: 过滤逻辑实现合理

formatFilterOptions函数实现了不区分大小写的字符串匹配,但可以考虑优化性能和用户体验。

对于大量选项时,可以考虑以下优化:

function formatFilterOptions(
  options: Record<string, any>[],
  filterVal: string
) {
+ // 优化:空字符串直接返回所有选项
+ if (!filterVal.trim()) {
+   filterOptions.value = options;
+   return;
+ }
+ 
+ // 转换为小写一次,避免循环中重复转换
+ const lowerFilterVal = filterVal.toLowerCase();
  const filterOptionsTemp = options.filter((item) => {
    const label = item?.[props.labelKey]
    return typeof label === 'string'
-      ? label.toLowerCase().includes(filterVal.toLowerCase())
-      : String(label).toLowerCase().includes(filterVal.toLowerCase())
+      ? label.toLowerCase().includes(lowerFilterVal)
+      : String(label).toLowerCase().includes(lowerFilterVal)
  })
  filterOptions.value = filterOptionsTemp
}

234-239: 添加了下拉菜单打开时的清空逻辑

使用延时清空搜索避免UI闪烁,处理合理。但建议考虑一些边缘情况处理。

为避免潜在的内存泄漏问题,建议储存timeout引用以便在组件销毁时清理:

+ const clearFilterTimeout = ref<ReturnType<typeof setTimeout> | null>(null);

+ onBeforeUnmount(() => {
+   if (clearFilterTimeout.value) {
+     clearTimeout(clearFilterTimeout.value);
+     clearFilterTimeout.value = null;
+   }
+ })

function open() {
  // ...现有代码
  
  //关闭弹窗清空搜索 延迟避免清空画面闪过
  if (filterVal.value !== '') {
-   setTimeout(() => {
+   if (clearFilterTimeout.value) {
+     clearTimeout(clearFilterTimeout.value);
+   }
+   clearFilterTimeout.value = setTimeout(() => {
      handleFilterChange({ value: '' })
+     clearFilterTimeout.value = null;
    }, 300)
  }
}

159-181: 考虑添加空结果提示

当过滤后没有任何匹配结果时,目前没有提供空状态展示。

建议添加一个空结果状态展示:

<template>
  <!-- 现有代码 -->
  <view v-if="options.length">
    <wd-search
      v-if="filterable"
      v-model="filterVal"
      :placeholder="filterPlaceholder || translate('filterPlaceholder')"
      hide-cancel
      placeholder-left
      @change="handleFilterChange"
    />
+   <view v-if="filterable && filterOptions.length === 0 && filterVal" class="wd-drop-item__empty">
+     {{ translate('noMatchingData') }}
+   </view>
    <view
      v-for="(item, index) in filterOptions"
      <!-- 其余代码 -->
    </view>
  </view>
  <!-- 其余代码 -->
</template>

并在translations中添加相应文案:

// 在相应的翻译文件中
{
  filterPlaceholder: '搜索',
  noMatchingData: '无匹配数据'
}

76-77: 代码格式需要修正

代码中存在一些格式问题,如多余空格和不一致的格式。

建议使用项目的代码格式化工具(如Prettier)来统一代码格式,尤其是以下几处:

  1. 第76行的额外空格
  2. 第159-162行的函数声明格式
  3. 第182行的额外空格
  4. 第233行的额外空格

Also applies to: 90-92, 159-170, 172-181

🧰 Tools
🪛 ESLint

[error] 76-76: Delete ··

(prettier/prettier)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5c77483 and e49e6dc.

⛔ Files ignored due to path filters (2)
  • docs/public/petercatai/assistant.min.js is excluded by !**/*.min.js
  • docs/public/petercatai/dayjs.min.js is excluded by !**/*.min.js
📒 Files selected for processing (9)
  • README.md (1 hunks)
  • README_en.md (1 hunks)
  • docs/.vitepress/config.mts (1 hunks)
  • docs/.vitepress/theme/components/HomeStar.vue (2 hunks)
  • docs/component/drop-menu.md (2 hunks)
  • docs/public/petercatai/assistant.min.css (0 hunks)
  • src/uni_modules/wot-design-uni/components/wd-drop-menu-item/types.ts (1 hunks)
  • src/uni_modules/wot-design-uni/components/wd-drop-menu-item/wd-drop-menu-item.vue (7 hunks)
  • src/uni_modules/wot-design-uni/readme.md (1 hunks)
💤 Files with no reviewable changes (1)
  • docs/public/petercatai/assistant.min.css
🧰 Additional context used
🪛 ESLint
src/uni_modules/wot-design-uni/components/wd-drop-menu-item/types.ts

[error] 75-75: Delete ··

(prettier/prettier)


[error] 79-79: Delete ,

(prettier/prettier)

src/uni_modules/wot-design-uni/components/wd-drop-menu-item/wd-drop-menu-item.vue

[error] 76-76: Delete ··

(prettier/prettier)


[error] 158-162: Replace ⏎function·formatFilterOptions(⏎··options:·Record<string,·any>[],⏎··filterVal:·string⏎ with function·formatFilterOptions(options:·Record<string,·any>[],·filterVal:·string

(prettier/prettier)


[error] 182-182: Delete ··

(prettier/prettier)


[error] 233-233: Delete ··

(prettier/prettier)

🔇 Additional comments (16)
docs/.vitepress/config.mts (1)

4-4: 跳过:仅更新时间戳
此处仅更新了 @LastEditTime 注释,无实质性功能或配置变更,可忽略审查。

src/uni_modules/wot-design-uni/readme.md (1)

16-16: 修复徽章 URL 换行问题,保证图片正常渲染
已将 src 属性的 URL 从多行合并为单行,避免 Markdown 渲染时出现断行导致徽章无法显示的问题。

README.md (1)

20-20: 修复徽章 URL 换行问题,保证 Markdown 图片渲染正常
src 属性的 URL 从多行合并为单行,避免出现意外断行导致徽章无法显示。

docs/.vitepress/theme/components/HomeStar.vue (2)

4-4: 更新最后编辑时间
已将 @LastEditTime 更新为最新编辑日期,保持文件头注释信息与实际变更同步。


20-20: 修复徽章 URL 换行问题,保证图片正常渲染
已将 <img> 标签的 src 属性 URL 从多行合并为单行,避免模板渲染时因断行导致徽章不可见。

README_en.md (1)

20-20: 修复徽章 URL 格式,确保正确渲染
合并 src 属性 URL 为单行,避免换行导致徽章无法显示的问题。

docs/component/drop-menu.md (2)

186-196: 文档更新清晰地介绍了新增的本地搜索功能

新增的"本地搜索"部分很好地描述了filterable和filter-placeholder属性的使用方法,并提供了三种不同场景的代码示例,方便开发者理解如何实现。


222-223: 属性表文档更新完整

filterable属性的描述简洁明了,正确标明了类型为boolean和默认值为false。

src/uni_modules/wot-design-uni/components/wd-drop-menu-item/types.ts (1)

76-79: 属性定义清晰并保持一致的文档风格

新增的filterable和filterPlaceholder属性遵循了现有代码的注释和类型定义风格,并使用了适当的默认值。

🧰 Tools
🪛 ESLint

[error] 79-79: Delete ,

(prettier/prettier)

src/uni_modules/wot-design-uni/components/wd-drop-menu-item/wd-drop-menu-item.vue (7)

22-29: 搜索组件集成良好

搜索组件被正确地条件渲染并绑定了必要的属性和事件。使用了适当的placeholder处理逻辑,既支持自定义也支持默认值。


31-32: 正确更新了选项列表循环

将options替换为filterOptions,确保筛选功能正常工作。


66-77: 引入了必要的组件和composable

正确导入了wdSearch组件和useTranslate composable用于国际化支持。

🧰 Tools
🪛 ESLint

[error] 76-76: Delete ··

(prettier/prettier)


90-92: 添加了必要的响应式变量

添加了filterVal和filterOptions用于管理搜索状态和过滤结果。


110-123: 监听options变化更新过滤结果

合理处理了options变化的情况,确保过滤结果与当前搜索条件同步。


172-181: 处理搜索输入变化逻辑清晰

当搜索框清空时正确重置为完整列表,当有输入时进行过滤,逻辑合理。


187-187: 选择项逻辑更新正确

choose函数已更新为使用filterOptions而非原始options,确保从过滤后的列表中选择。

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