Skip to content
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

feat: ✨ Swiper 支持指定轮播项的文件类型 #720

Merged
merged 1 commit into from
Nov 18, 2024

Conversation

Moonofweisheng
Copy link
Owner

@Moonofweisheng Moonofweisheng commented Nov 18, 2024

Closes: #712

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

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

🔗 相关 Issue

#712

💡 需求背景和解决方案

轮播项增加type属性,可选值:imagevideotype优先于组件内部对于文件类型的判断。

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

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

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

Summary by CodeRabbit

  • 新功能

    • 更新了 wd-swiper 组件文档,新增 type 属性以指定资源类型为 imagevideo
    • 引入 autoplayVideostopPreviousVideostopAutoplayWhenVideoPlay 属性,控制视频播放行为。
    • 增加了 text-keyvalue-key 属性,允许用户自定义图像 URL 和标题的键。
  • 文档

    • 扩展了文档内容,提供了新属性的详细描述和使用指南。
    • 更新了外部样式类,替换了过时的类名。

Copy link

vercel bot commented Nov 18, 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 18, 2024 1:58pm

Copy link

netlify bot commented Nov 18, 2024

Deploy Preview for wot-design-uni ready!

Name Link
🔨 Latest commit 563d12d
🔍 Latest deploy log https://app.netlify.com/sites/wot-design-uni/deploys/673b47c13d52df000866077d
😎 Deploy Preview https://deploy-preview-720--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

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

Deploying wot-design-uni with  Cloudflare Pages  Cloudflare Pages

Latest commit: 563d12d
Status: ✅  Deploy successful!
Preview URL: https://ede5ca8f.wot-design-uni.pages.dev
Branch Preview URL: https://feature-swiper-type.wot-design-uni.pages.dev

View logs

Copy link

coderabbitai bot commented Nov 18, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

此次更改主要集中在wd-swiper组件的文档和代码实现上。文档更新了SwiperList配置,新增了type属性以指定资源类型(图片或视频),并引入了text-keyvalue-key属性以自定义图像URL和标题的键。此外,视频播放相关的属性(如autoplayVideostopPreviousVideo等)也被添加。代码方面,更新了媒体类型检测逻辑,简化了图像和视频的渲染过程,增强了播放逻辑的健壮性。

Changes

文件路径 更改摘要
docs/component/swiper.md 更新文档,新增typetext-keyvalue-key属性,详细描述新属性,增强样式类的定义。
src/uni_modules/wot-design-uni/components/wd-swiper/types.ts SwiperList接口中添加可选属性type,允许指定资源类型(图片或视频)。
src/uni_modules/wot-design-uni/components/wd-swiper/wd-swiper.vue 更新媒体类型检测逻辑,新增getMediaTypeisVideoisImage方法,简化图像和视频的渲染过程。

Assessment against linked issues

Objective Addressed Explanation
支持外部传入图片类型或视频类型,解决URL后缀识别错误的问题(#712

Possibly related PRs

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

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

🧹 Outside diff range and nitpick comments (3)
src/uni_modules/wot-design-uni/components/wd-swiper/wd-swiper.vue (1)

125-140: 建议优化媒体类型判断的实现

当前实现已经很好地处理了显式类型指定和 URL 后缀检测,但建议进行以下改进:

  1. 将媒体类型字符串常量化,避免魔法字符串
  2. 考虑添加类型验证,确保传入的类型值有效

建议添加以下类型常量:

+const MEDIA_TYPES = {
+  VIDEO: 'video' as const,
+  IMAGE: 'image' as const
+} as const;
+
+type MediaType = typeof MEDIA_TYPES[keyof typeof MEDIA_TYPES];

-const getMediaType = (item: string | SwiperList, type: 'video' | 'image') => {
+const getMediaType = (item: string | SwiperList, type: MediaType) => {
docs/component/swiper.md (2)

Line range hint 456-458: 建议优化废弃提示的展示方式

当前的废弃提示混合在表格中,建议将废弃相关的信息单独提取出来,形成一个独立的"废弃提示"章节,以提高文档的可读性。

建议在外部样式类表格前添加:

## 废弃提示

以下样式类将在 1.3 版本废弃:
- `customImageClass` 请使用 `customItemClass` 代替
- `customPrevImageClass` 请使用 `customPrevClass` 代替
- `customNextImageClass` 请使用 `customNextClass` 代替
🧰 Tools
🪛 Markdownlint

350-350: null
Tables should be surrounded by blank lines

(MD058, blanks-around-tables)


Line range hint 4-4: 建议添加 type 属性的使用示例

为了更好地展示新增的 type 属性功能,建议在文档中添加一个专门的示例,展示如何明确指定资源类型。

建议添加如下示例:

<!-- 明确指定资源类型的示例 -->
<wd-swiper :list="typedList" autoplay></wd-swiper>

<script setup>
const typedList = ref([
  { 
    value: 'https://example.com/api/video',
    type: 'video',
    poster: 'https://example.com/poster.jpg'
  },
  { 
    value: 'https://example.com/api/image',
    type: 'image'
  }
])
</script>
🧰 Tools
🪛 Markdownlint

350-350: null
Tables should be surrounded by blank lines

(MD058, blanks-around-tables)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 314c2e8 and c205a1b.

📒 Files selected for processing (3)
  • docs/component/swiper.md (1 hunks)
  • src/uni_modules/wot-design-uni/components/wd-swiper/types.ts (1 hunks)
  • src/uni_modules/wot-design-uni/components/wd-swiper/wd-swiper.vue (5 hunks)
🧰 Additional context used
🪛 Markdownlint
docs/component/swiper.md

350-350: null
Tables should be surrounded by blank lines

(MD058, blanks-around-tables)

🔇 Additional comments (2)
src/uni_modules/wot-design-uni/components/wd-swiper/wd-swiper.vue (2)

24-31: 模板条件渲染逻辑优化

使用新的 isImageisVideo 工具函数替代原有的 URL 检测方法,使得类型判断更加清晰和灵活。这样的改动使得组件能够支持显式指定媒体类型,不再完全依赖 URL 后缀。


80-80: 新增空值检查工具函数

引入 isDef 工具函数用于视频对象的空值检查,这是一个良好的防御性编程实践。

@Moonofweisheng Moonofweisheng merged commit 1e039cb into master Nov 18, 2024
7 checks passed
@Moonofweisheng Moonofweisheng deleted the feature/swiper-type branch November 18, 2024 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant