Skip to content

feat: ✨ Upload 上传组件支持根据扩展名过滤文件 - #980

Merged
Moonofweisheng merged 1 commit into
masterfrom
feature/upload-extension
Mar 27, 2025
Merged

feat: ✨ Upload 上传组件支持根据扩展名过滤文件#980
Moonofweisheng merged 1 commit into
masterfrom
feature/upload-extension

Conversation

@Moonofweisheng

@Moonofweisheng Moonofweisheng commented Mar 27, 2025

Copy link
Copy Markdown
Owner

Closes: #796,#581

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

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

🔗 相关 Issue

#796,#581

💡 需求背景和解决方案

Upload 上传组件支持根据扩展名过滤文件,根据uni-app相关选择图片、视频和文件的API,H5支持全部类型过滤,微信小程序支持all和file时过滤,其余平台不支持。所以我们在支持的平台提供extension属性用于支持根据扩展名过滤文件

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

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

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

Summary by CodeRabbit

  • 新功能

    • 新增文件上传扩展名过滤功能,允许用户通过配置上传组件来限制可选文件类型(如图片、视频和文档),并为不同平台提供定制化演示。
  • 文档

    • 更新了相关文档,新增“根据文件拓展名过滤”说明和“最低版本”信息,详细展示了如何使用新属性以提升上传体验。

@vercel

vercel Bot commented Mar 27, 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 Mar 27, 2025 1:12pm

@coderabbitai

coderabbitai Bot commented Mar 27, 2025

Copy link
Copy Markdown

Walkthrough

本次变更为文件上传组件新增了基于文件扩展名的过滤功能。文档中增加了相关说明和示例,并在上传组件与相关类型声明中新增了 extension 属性。此外,组件的文件选择逻辑已调整以传递新的扩展名过滤参数,同时对部分参数设为可选,以便更灵活地配置文件上传行为。

Changes

文件/模块路径 变更描述
docs/component/upload.md,
docs/component/use-upload.md
增加了文档说明,新增“根据文件拓展名过滤”章节与“最低版本”列,并引入 extension 参数说明。
src/pages/upload/Index.vue 新增“根据扩展名过滤”演示块,添加了多个 wd-upload 组件及对应的响应式文件列表,支持各平台文件扩展名过滤。
src/uni_modules/wot-design-uni/components/composables/useUpload.ts UseUploadOptions 接口中新增可选属性 extension,修改 chooseFile 调用以传递 extension 参数。
src/uni_modules/wot-design-uni/components/wd-upload/types.ts 修改 ChooseFileOption 接口,将部分属性设为可选,并新增 extension 属性和在 uploadProps 中添加对应配置。
src/uni_modules/wot-design-uni/components/wd-upload/wd-upload.vue onChooseFile 函数中,扩充 props 解构,新增 extension 属性至文件选择参数中。

Sequence Diagram(s)

sequenceDiagram
    participant U as 用户
    participant C as wd-upload 组件
    participant UO as useUpload 模块
    participant API as 文件选择 API

    U->>C: 触发文件选择
    C->>UO: 调用 onChooseFile(extension, …)
    UO->>API: 传递 extension 过滤参数调用 uni.chooseFile/uni.chooseImage 等
    API-->>UO: 返回选择的文件
    UO-->>C: 更新文件列表
    C-->>U: 展示上传结果
Loading

Assessment against linked issues

Objective Addressed Explanation
[#796] 支持APP选择非视频图片以外的文件上传

Possibly related PRs

Poem

我是一只欢快的小兔子,
跳跃中带来了新过滤的消息,
文件扩展名筛选更加灵活,
代码跳跃间不失精准与慧,
祝愿上传之路一路平滑,
欢欣鼓舞共赏这技术之美!

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

 WARN  GET http://10.0.0.28:4873/jest/-/jest-27.0.4.tgz error (ERR_PNPM_FETCH_500). Will retry in 10 seconds. 2 retries left.
 WARN  GET http://10.0.0.28:4873/eslint-config-prettier/-/eslint-config-prettier-8.7.0.tgz error (ERR_PNPM_FETCH_500). Will retry in 10 seconds. 2 retries left.
 WARN  GET http://10.0.0.28:4873/eslint-plugin-vue/-/eslint-plugin-vue-9.9.0.tgz error (ERR_PNPM_FETCH_500). Will retry in 10 seconds. 2 retries left.
Progress: resolved 0, reused 0, downloaded 1, added 0
 ERR_PNPM_FETCH_404  GET http://10.0.0.28:4873/@dcloudio/types/-/types-3.4.12.tgz: Not Found - 404

This error happened while installing a direct dependency of /tmp/eslint

No authorization header was set for the request.


📜 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 1e51c73 and 497523b.

📒 Files selected for processing (6)
  • docs/component/upload.md (3 hunks)
  • docs/component/use-upload.md (1 hunks)
  • src/pages/upload/Index.vue (2 hunks)
  • src/uni_modules/wot-design-uni/components/composables/useUpload.ts (6 hunks)
  • src/uni_modules/wot-design-uni/components/wd-upload/types.ts (2 hunks)
  • src/uni_modules/wot-design-uni/components/wd-upload/wd-upload.vue (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/uni_modules/wot-design-uni/components/wd-upload/wd-upload.vue
  • docs/component/upload.md
  • src/uni_modules/wot-design-uni/components/composables/useUpload.ts
  • src/uni_modules/wot-design-uni/components/wd-upload/types.ts
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
docs/component/use-upload.md

80-80: Table column count
Expected: 5; Actual: 4; Too few cells, row will be missing data

(MD056, table-column-count)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (2)
src/pages/upload/Index.vue (2)

95-111: 新增的扩展名过滤功能实现正确

新增的扩展名过滤功能演示代码实现正确,为不同平台(H5和微信小程序)提供了适当的示例,覆盖了不同文件类型的过滤场景。


156-159: 文件列表变量声明符合规范

新增的响应式文件列表变量声明清晰,类型定义正确。


🪧 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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 Mar 27, 2025

Copy link
Copy Markdown

Deploy Preview for wot-design-uni ready!

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

@petercat-assistant

Copy link
Copy Markdown

Walkthrough

此PR为Upload上传组件新增了根据文件扩展名过滤文件的功能。通过在支持的平台上提供extension属性,用户可以限制选择文件的格式。此功能在H5上支持所有类型过滤,在微信小程序上支持allfile类型过滤,其他平台暂不支持。

Changes

文件 概要
docs/component/upload.md, docs/component/use-upload.md 更新文档以说明新功能和参数。
src/pages/upload/Index.vue 增加了演示代码,展示如何使用extension属性进行文件过滤。
src/uni_modules/wot-design-uni/components/composables/useUpload.ts useUpload函数中添加了extension参数支持。
src/uni_modules/wot-design-uni/components/wd-upload/types.ts 更新了类型定义以支持extension参数。
src/uni_modules/wot-design-uni/components/wd-upload/wd-upload.vue 在文件选择逻辑中加入了extension参数。

extension
}: ChooseFileOption): Promise<ChooseFile[]> {
return new Promise((resolve, reject) => {
const max = isDef(maxCount) ? maxCount : 1

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Ensure that maxCount is defined before using it in Math.min(maxCount, 9). Consider providing a default value or handling undefined cases to prevent potential runtime errors.

@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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d23b2bf and 1e51c73.

📒 Files selected for processing (6)
  • docs/component/upload.md (3 hunks)
  • docs/component/use-upload.md (1 hunks)
  • src/pages/upload/Index.vue (2 hunks)
  • src/uni_modules/wot-design-uni/components/composables/useUpload.ts (6 hunks)
  • src/uni_modules/wot-design-uni/components/wd-upload/types.ts (2 hunks)
  • src/uni_modules/wot-design-uni/components/wd-upload/wd-upload.vue (2 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
src/uni_modules/wot-design-uni/components/composables/useUpload.ts (1)
src/uni_modules/wot-design-uni/components/wd-upload/types.ts (2)
  • ChooseFileOption (6-35)
  • ChooseFile (57-64)
🪛 markdownlint-cli2 (0.17.2)
docs/component/use-upload.md

80-80: Table column count
Expected: 5; Actual: 4; Too few cells, row will be missing data

(MD056, table-column-count)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (19)
src/uni_modules/wot-design-uni/components/wd-upload/wd-upload.vue (2)

412-413: 添加扩展名过滤支持

extension 参数已正确添加到 props 解构中,用于传递到 chooseFile 函数,实现按文件扩展名过滤的功能。实现简洁明了。


422-424: 正确传递扩展名参数

extension 参数已正确传递给 chooseFile 函数,确保文件选择时能应用扩展名过滤规则。

docs/component/upload.md (2)

604-614: 文档添加了扩展名过滤的使用说明

新增的文档部分清晰地解释了如何使用 extension 属性来限制文件选择,示例代码也很直观易懂。


652-652: 表格中添加了新属性的说明

extension 属性已添加到 Attributes 表格中,描述了其用途、类型和平台支持情况。

不过,注意到占位符 $LOWEST_VERSION$ 需要替换为实际的最低支持版本号。

请确认此功能的最低支持版本号,并替换占位符 $LOWEST_VERSION$

src/uni_modules/wot-design-uni/components/composables/useUpload.ts (10)

47-48: 接口中添加扩展名过滤属性

UseUploadOptions 接口中增加了 extension 属性,注释清晰地说明了其用途和平台支持情况。


230-232: 函数参数列表更新

chooseFile 函数参数中添加了 extension 参数,保持与接口定义一致。


234-234: 优化文件数量限制逻辑

使用局部变量 max 存储 maxCount 或默认值 1,提高了代码的可读性和可维护性。


238-243: 为 H5 平台添加扩展名过滤支持

在调用 uni.chooseImage 时,通过条件编译为 H5 平台添加了 extension 参数,同时优化了 count 计算逻辑。


254-256: 为 H5 平台的视频选择添加扩展名过滤

通过条件编译块,仅在 H5 平台传递 extension 参数给 chooseVideo 方法。


264-265: 优化媒体选择的数量限制逻辑

使用与其他选择函数一致的 max 变量计算 count 参数值,保持代码一致性。


275-277: 为微信小程序的文件选择添加扩展名过滤

在调用 uni.chooseMessageFile 时添加了 extension 参数,并优化了 count 的计算逻辑。


286-288: 为 H5 平台的所有文件类型选择添加扩展名过滤

在 H5 平台的 chooseFile 函数中添加了 extension 参数,并优化了 count 参数的计算。


295-297: 为微信小程序的所有文件类型选择添加扩展名过滤

在微信小程序平台的 chooseMessageFile 函数中添加了 extension 参数,同时优化了 count 参数的计算。


307-312: 为默认图片选择添加扩展名过滤

在默认选择图片的逻辑中,通过条件编译为 H5 平台添加了 extension 参数,同时优化了 count 参数的计算。

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

95-111: 👍 新增了根据扩展名过滤的示例演示

这个新增的演示区块很好地展示了根据扩展名过滤文件的功能,并且针对不同平台(H5和微信小程序)提供了合适的示例。示例清晰展示了各种使用场景,包括图片、视频和文档类型的过滤。


156-159: 添加了与新示例对应的状态变量

适当地为新增的上传组件定义了对应的文件列表状态变量,保持了代码组织的一致性。

src/uni_modules/wot-design-uni/components/wd-upload/types.ts (3)

8-28: 👍 优化了接口定义,使多个属性变为可选

multiplesourceTypemaxCountacceptcompressedmaxDurationcamera 等属性修改为可选属性,提高了接口的灵活性,减少了使用时的必填属性负担。


29-34: 很好地实现了文件扩展名过滤功能

新增的 extension 属性及其注释清晰地描述了功能的用途和使用方法。注释中明确指出了支持的平台(H5和微信小程序)以及使用示例,这对开发者非常友好。


340-345: 添加了组件属性定义,保持类型一致性

uploadProps 对象中添加 extension 属性定义,确保了组件属性与接口定义的一致性。注释中明确说明了各平台的支持情况,帮助开发者理解功能限制。

Comment thread docs/component/use-upload.md
@Moonofweisheng
Moonofweisheng force-pushed the feature/upload-extension branch from 1e51c73 to 497523b Compare March 27, 2025 13:11
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Mar 27, 2025

Copy link
Copy Markdown

Deploying wot-design-uni with  Cloudflare Pages  Cloudflare Pages

Latest commit: 497523b
Status: ✅  Deploy successful!
Preview URL: https://054b428d.wot-design-uni.pages.dev
Branch Preview URL: https://feature-upload-extension.wot-design-uni.pages.dev

View logs

@Moonofweisheng
Moonofweisheng merged commit 51adb6b into master Mar 27, 2025
@Moonofweisheng
Moonofweisheng deleted the feature/upload-extension branch March 27, 2025 13:45
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.

[新功能需求] Upload能支持APP选择非视频图片以外的文件

1 participant