Skip to content

feat: ✨ Toast 支持通过props设置组件属性并新增居中显示的配置#888

Merged
Moonofweisheng merged 1 commit into
masterfrom
feature/toast-props
Feb 11, 2025
Merged

feat: ✨ Toast 支持通过props设置组件属性并新增居中显示的配置#888
Moonofweisheng merged 1 commit into
masterfrom
feature/toast-props

Conversation

@Moonofweisheng

@Moonofweisheng Moonofweisheng commented Feb 11, 2025

Copy link
Copy Markdown
Owner

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

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

🔗 相关 Issue

💡 需求背景和解决方案

  1. 为Toast组件添加必要的props,支持通过props设置组件属性,其优先级低于optiios,以便使用者可以全局控制其默认属性。
  2. 调整Toast组件的position,新增middle-top,其含义等同于原middle,局中向上偏移。middle恢复其原始含义,局中不偏移。

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

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

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

Summary by CodeRabbit

  • 文档更新

    • 更新了 Toast 组件的文档,添加了新提示、详细参数说明和位置示例(如顶部、中部、底部),帮助用户了解各配置项及默认设置。
  • 新功能

    • 新增中间显示 Toast 及加载状态 Toast 展示选项,支持水平与垂直布局,提供更多展示样式选择。
  • 重构

    • 优化了组件默认选项、状态管理和样式控制,提升了整体的用户体验。

@vercel

vercel Bot commented Feb 11, 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 11, 2025 2:32pm

@coderabbitai

coderabbitai Bot commented Feb 11, 2025

Copy link
Copy Markdown

Walkthrough

该 PR 主要对 Toast 组件的文档说明、样式、逻辑和类型定义进行了更新。文档部分新增了提示信息、演示示例和参数(如 loadingSize、iconColor、cover 等)的详细说明;页面新增了两个 toast 展示函数并调整了参数;样式文件引入了新的消息文本混入以及重命名了定位混入;组件代码简化了默认选项及关闭逻辑,同时对属性合并和方向响应处理进行了优化;类型定义也扩展了位置和布局方向的选项。

Changes

文件 变更摘要
docs/component/toast.md 更新文档,新增提示部分,添加/修改参数(loadingSize、iconColor、cover、position、iconName 及 classPrefix);新增 toast 位置示例。
src/pages/toast/Index.vue 新增 showMiddletoastshowLoadingToast3 方法;更新 showVerticalToast 消息参数,实现不同 toast 展示效果。
src/uni_modules/wot-design-uni/components/wd-toast/index.scss 新增消息文本样式混入 @include e(msg);将定位混入从 m(middle) 重命名为 m(middle-top),保持原有转换属性。
src/uni_modules/wot-design-uni/components/wd-toast/index.ts
src/uni_modules/wot-design-uni/components/wd-toast/types.ts
简化默认选项(defaultOptions)及更新关闭逻辑;扩展类型定义,添加 ToastDirection 类型、更新参数默认值及属性类型。
src/uni_modules/wot-design-uni/components/wd-toast/wd-toast.vue 引入响应式 direction 变量,采用新的 mergeOptionsWithProps 方法合并选项与 props,优化了组件内部属性处理逻辑。

Sequence Diagram(s)

sequenceDiagram
    participant U as 用户
    participant I as Index.vue
    participant T as Toast逻辑
    participant W as wd-toast组件

    U->>I: 点击按钮 (触发 showMiddletoast/showLoadingToast3)
    I->>T: 调用对应的 toast 方法
    T->>W: 通过 mergeOptionsWithProps 合并选项与 props
    W-->>U: 渲染并显示 toast
    Note over W: Toast 显示后等待关闭操作
    W->>W: 调用 close() 更新显示状态
    W-->>U: 隐藏 toast
Loading

Possibly related PRs

Poem

我是一只快乐的小兔子,
在代码丛中蹦跶追逐,
Toast 更新似春风轻柔吹,
新功能如星闪耀夜空,
样式、逻辑齐舞动,
祝代码永远鲜活不断!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 11, 2025

Copy link
Copy Markdown

Deploy Preview for wot-design-uni ready!

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

@Moonofweisheng Moonofweisheng changed the title feat: ✨ Toast 支持通过props设置组件属性并新增局中显示的配置 feat: ✨ Toast 支持通过props设置组件属性并新增居中显示的配置 Feb 11, 2025

@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 (5)
src/pages/toast/Index.vue (2)

20-20: 函数命名不一致。

函数命名风格与其他函数不一致,建议修改为 showMiddleToast 以保持一致性。

-        <wd-button @click="showMiddletoast">局中toast</wd-button>
+        <wd-button @click="showMiddleToast">局中toast</wd-button>

69-81: 函数命名不一致。

函数命名风格与其他函数不一致,建议修改为 showMiddleToast 以保持一致性。

-function showMiddletoast() {
+function showMiddleToast() {
   toast.show({
     position: 'middle',
     iconClass: 'star',
     msg: '提示信息',
     closed() {
       console.log(232)
     },
     opened() {
       console.log(2323232)
     }
   })
}
src/uni_modules/wot-design-uni/components/wd-toast/types.ts (1)

16-16: 位置类型的顺序建议调整。

建议按照从上到下的顺序排列位置类型,使其更直观:'top' | 'middle-top' | 'middle' | 'bottom'

src/uni_modules/wot-design-uni/components/wd-toast/index.scss (1)

20-25: 建议优化字体族列表

建议按照以下方式优化字体族列表,以提供更好的跨平台支持:

-    font-family: "San Francisco", Rotobo, arial, "PingFang SC", "Noto SansCJK", "Microsoft Yahei", sans-serif;
+    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Helvetica, Arial, sans-serif;
docs/component/toast.md (1)

59-60: 建议补充位置说明

建议为不同位置添加更详细的说明,帮助用户理解各个位置的具体表现。

- 通过设置 `position` 属性,可以设置提示信息的位置,默认为 `middle-top`。
+ 通过设置 `position` 属性,可以设置提示信息的位置,默认为 `middle-top`。各个位置说明如下:
+ - `top`: 位于屏幕顶部
+ - `middle-top`: 位于屏幕中上方(默认)
+ - `middle`: 位于屏幕正中央
+ - `bottom`: 位于屏幕底部
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ed60852 and 02e0b05.

📒 Files selected for processing (6)
  • docs/component/toast.md (3 hunks)
  • src/pages/toast/Index.vue (4 hunks)
  • src/uni_modules/wot-design-uni/components/wd-toast/index.scss (2 hunks)
  • src/uni_modules/wot-design-uni/components/wd-toast/index.ts (3 hunks)
  • src/uni_modules/wot-design-uni/components/wd-toast/types.ts (2 hunks)
  • src/uni_modules/wot-design-uni/components/wd-toast/wd-toast.vue (6 hunks)
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
docs/component/toast.md

6-6: Link fragments should be valid
null

(MD051, link-fragments)

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

106-114: 长文本加载提示的实现看起来不错。

新增的 showLoadingToast3 函数实现了纵向布局的长文本加载提示,代码结构清晰。

src/uni_modules/wot-design-uni/components/wd-toast/types.ts (1)

74-196: 属性文档完善,类型定义清晰。

toastProps 的属性定义非常完善:

  • 每个属性都有详细的类型注释
  • 默认值清晰明确
  • 属性分组合理
src/uni_modules/wot-design-uni/components/wd-toast/wd-toast.vue (1)

173-188: 选项合并逻辑优化得很好。

mergeOptionsWithProps 函数的实现:

  • 逻辑清晰,易于维护
  • 统一处理了所有属性的合并
  • 保持了选项优先级
src/uni_modules/wot-design-uni/components/wd-toast/index.ts (2)

11-13: 默认选项简化得很好。

defaultOptions 简化为只包含 show 属性是个好的改进:

  • 减少了重复配置
  • 使代码更易维护
  • 让属性管理更清晰

60-62: 关闭函数实现更简洁。

close 函数的新实现更加简洁明了,直接重置为包含 show: false 的新对象是个好方法。

src/uni_modules/wot-design-uni/components/wd-toast/index.scss (1)

59-61: 新增的中上位置实现正确

middle-top 位置的实现使用了合适的 transform 值,可以确保 Toast 在视觉上的正确定位。

docs/component/toast.md (2)

5-7: 提示信息清晰明确

提示信息准确说明了 propsoptions 的优先级关系,对用户很有帮助。

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

6-6: Link fragments should be valid
null

(MD051, link-fragments)


124-142: 属性表格内容完整

属性表格的内容非常完整,包含了所有必要的参数说明。建议检查链接片段。

❌ Verification inconclusive

🌐 Web query:

markdownlint 中的 MD051 (link-fragments) 规则是什么?如何修复?

💡 Result:

MD051(link-fragments)是 markdownlint 中用于验证 Markdown 文档内部链接片段有效性的规则。该规则要求文档内的锚点链接(形如[text](#fragment))必须指向实际存在的标题片段。

规则核心机制

  1. 自动生成标题片段
    Markdown 标题会根据内容自动生成 URL 片段,转换规则为:

    • 去除特殊符号
    • 空格替换为连字符-
    • 强制转换为小写
      例如:## Hello World! 会生成片段hello-world
  2. 验证逻辑
    当链接片段与任何标题生成的片段不匹配时触发警告。例如:

    [错误示例](#HelloWorld)  <!-- 未匹配 hello-world -->

常见修复方法

方法 1:修正链接片段

- [链接](#旧片段)
+ [链接](#修正后的片段)

需确保片段与目标标题的自动生成形式完全一致(含大小写)。

方法 2:自定义标题锚点
在标题中显式定义锚点名称:

### 自定义标题 {#my-custom-anchor}

此时可用[链接](#my-custom-anchor)直接引用,锚点名称需符合小写字母/数字/-/_格式[1][7]。

方法 3:配置参数
.markdownlint.json中添加:

{
  "MD051": {
    "ignore_case": true
  }
}

此配置将忽略片段名称的大小写差异[1][3]。

典型错误场景

## API v2.0 [查看文档](doc.md)
[示例链接](#api-v20) <!-- 实际生成的片段是 api-v20查看文档 -->

此时需通过自定义锚点修正:

## API v2.0 {#api-v20} [查看文档](doc.md)

版本注意事项

v0.30+ 版本修复了标题内嵌链接导致的片段生成异常(如# Heading [text](url)),建议保持工具版本更新[2][6]。

该规则通过标准化文档内部导航结构,显著提升 Markdown 文档的可维护性和跨平台兼容性。

Citations:


链接片段问题检查建议

文档中的属性表格内容已经完整,没有需要修改的部分。但请仔细核查整篇文档中的内部链接片段,确保所有 [文本](#fragment) 链接指向实际存在且正确生成的标题锚点。根据 markdownlint 的 MD051 规则,请确认以下几点:

  • 检查链接片段的大小写和特殊字符,确保与目标标题自动生成的锚点一致。
  • 如果发现自动生成的锚点与预期不符,可以在标题后面显式定义锚点(例如 ### 标题 {#custom-anchor})以确保链接正确。
  • 或者,在 .markdownlint.json 中配置 ignore_case 以忽略链接锚点的大小写差异,从而解决部分链接片段不匹配的问题。

建议开发者针对整个文档执行一次 MD051 检查,确保所有内部链接都符合规则要求。

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