Skip to content

Conversation

@Moonofweisheng
Copy link
Owner

@Moonofweisheng Moonofweisheng commented Dec 5, 2024

Closes: #740

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

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

🔗 相关 Issue

#740

💡 需求背景和解决方案

MessageBox 添加 cancel-button-propsconfirm-button-props,用于自定义操作按钮样式。

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

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

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

Summary by CodeRabbit

  • 新特性

    • 更新了 MessageBox 组件文档,新增 beforeConfirm 函数,支持预确认逻辑。
    • 新增 cancel-button-propsconfirm-button-props 属性,允许自定义按钮样式。
    • Index.vue 中添加了新的演示块,支持自定义按钮属性的确认对话框。
    • 引入新的 InputSize 类型,增强输入框大小的类型安全。
  • 文档

    • 扩展了文档示例,展示新特性及用法。
    • 改进了文档结构,提高了可读性。
  • 样式

    • 为动作按钮添加了新的样式规则,优化按钮间距。
    • 移除了与 .zoomIn 动画相关的样式。

@vercel
Copy link

vercel bot commented Dec 5, 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 Dec 5, 2024 3:55pm

@coderabbitai
Copy link

coderabbitai bot commented Dec 5, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

本次提交对 MessageBox 组件的文档进行了显著更新,新增了 beforeConfirm 函数,允许开发者执行确认前的逻辑,包括异步操作。此外,添加了 cancel-button-propsconfirm-button-props 属性,以定制取消和确认按钮的样式。文档中还增加了示例,展示如何使用这些新特性。其他文件中也进行了相应的功能增强和样式调整,以支持新的功能和属性。

Changes

文件路径 更改摘要
docs/component/message-box.md 更新文档,新增 beforeConfirm 函数,添加 cancel-button-propsconfirm-button-props 属性,增加示例和格式调整。
src/pages/messageBox/Index.vue 在模板中新增演示块,添加 withButtonProps 函数以支持自定义按钮属性。
src/uni_modules/wot-design-uni/components/wd-input/types.ts 新增 InputSize 类型,更新 inputPropssize 属性类型。
src/uni_modules/wot-design-uni/components/wd-message-box/index.scss 新增按钮间距样式,移除 .zoomIn 动画样式。
src/uni_modules/wot-design-uni/components/wd-message-box/index.ts 更新 defaultOptions 类型,修改 show 函数的处理方式。
src/uni_modules/wot-design-uni/components/wd-message-box/types.ts 更新类型,添加新属性,修改 MessageOptions 结构以支持新功能。
src/uni_modules/wot-design-uni/components/wd-message-box/wd-message-box.vue 整合状态管理,使用 messageState 替代多个 ref,更新按钮属性处理。

Assessment against linked issues

目标 已解决 说明
自定义按钮圆角与插槽替换默认按钮 (#740) 本次更改未涉及自定义圆角或插槽功能。

Possibly related PRs

Poem

🐰 在兔子洞里欢快跳,
MessageBox 新功能真妙!
按钮样式随心定,
确认前逻辑不再少。
代码更新真是好,
开发者笑声绕。 🌟


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between fd09fcd and 9572871.

📒 Files selected for processing (7)
  • docs/component/message-box.md (4 hunks)
  • src/pages/messageBox/Index.vue (3 hunks)
  • src/uni_modules/wot-design-uni/components/wd-input/types.ts (3 hunks)
  • src/uni_modules/wot-design-uni/components/wd-message-box/index.scss (1 hunks)
  • src/uni_modules/wot-design-uni/components/wd-message-box/index.ts (3 hunks)
  • src/uni_modules/wot-design-uni/components/wd-message-box/types.ts (4 hunks)
  • src/uni_modules/wot-design-uni/components/wd-message-box/wd-message-box.vue (7 hunks)

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.

@netlify
Copy link

netlify bot commented Dec 5, 2024

Deploy Preview for wot-design-uni ready!

Name Link
🔨 Latest commit 9572871
🔍 Latest deploy log https://app.netlify.com/sites/wot-design-uni/deploys/6751cc9ee65788000838b26b
😎 Deploy Preview https://deploy-preview-761--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: 3

🧹 Outside diff range and nitpick comments (11)
src/uni_modules/wot-design-uni/components/wd-message-box/wd-message-box.vue (4)

83-99: 建议:在初始化 messageState 时为所有属性提供默认值

在初始化 messageState 时,直接为每个属性赋值,可能会导致某些属性为未定义。建议为每个属性提供明确的默认值,确保状态的一致性,避免在组件使用过程中出现未定义的错误。


104-113: 优化 customConfirmProps 的合并逻辑

在计算属性 customConfirmProps 中,使用了 deepAssignomitBy 进行属性合并。为了简化逻辑,建议直接使用解构赋值并提供默认值,以提高代码的可读性和维护性。

const customConfirmProps = computed(() => {
-  const buttonProps: Partial<ButtonProps> = deepAssign(
-    {
-      block: true
-    },
-    isDef(messageState.confirmButtonProps) ? omitBy(messageState.confirmButtonProps, isUndefined) : {}
-  )
+  const buttonProps: Partial<ButtonProps> = {
+    block: true,
+    ...messageState.confirmButtonProps
+  }
   buttonProps.customClass = `${buttonProps.customClass || ''} wd-message-box__actions-btn`
   return buttonProps
})

118-128: 优化 customCancelProps 的合并逻辑

customConfirmProps 类似,customCancelProps 中的合并逻辑可以简化。建议使用解构赋值方式,提高代码简洁性。

const customCancelProps = computed(() => {
-  const buttonProps: Partial<ButtonProps> = deepAssign(
-    {
-      block: true,
-      type: 'info'
-    },
-    isDef(messageState.cancelButtonProps) ? omitBy(messageState.cancelButtonProps, isUndefined) : {}
-  )
+  const buttonProps: Partial<ButtonProps> = {
+    block: true,
+    type: 'info',
+    ...messageState.cancelButtonProps
+  }
   buttonProps.customClass = `${buttonProps.customClass || ''} wd-message-box__actions-btn`
   return buttonProps
})

223-235: 建议:在 validate 方法中检查输入值的类型

在验证输入值时,直接使用 String(messageState.inputValue),如果 inputValuenullundefined,可能会导致意外结果。建议在转换前检查 inputValue 是否已定义,确保验证逻辑的可靠性。

if (messageState.inputPattern && messageState.inputValue !== undefined && !messageState.inputPattern.test(String(messageState.inputValue))) {
  messageState.showErr = true
  return false
}
src/uni_modules/wot-design-uni/components/wd-message-box/types.ts (2)

103-106: 建议更新类型定义的文档注释

在新添加的 MessageOptionsWithCallBack 类型中,缺少对新属性的文档注释。为了提高代码的可维护性和可读性,建议为新属性添加注释。

export type MessageOptionsWithCallBack = MessageOptions & {
  /**
   * 控制消息框的显示与隐藏
   */
  show?: boolean
  /**
   * 成功回调函数
   */
  success?: (res: MessageResult) => void
  /**
   * 失败回调函数
   */
  fail?: (res: MessageResult) => void
}

72-72: 更新 inputValidate 类型注释

由于 inputValidate 不再接受 null,且只能为函数或未定义,建议更新注释以反映这一变化。

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

110-129: 优化 withButtonProps 方法的错误处理

withButtonProps 方法中,then 中没有处理逻辑,而在 catch 中仅打印错误信息。建议在 thencatch 中添加相应的用户反馈,如提示操作成功或取消。

function withButtonProps() {
  message
    .confirm({
      msg: '自定义按钮样式',
      title: '提示',
      cancelButtonProps: {
        type: 'error',
        customClass: 'custom-shadow'
      },
      confirmButtonProps: {
        type: 'success',
        customClass: 'custom-shadow'
      }
    })
-   .then(() => {})
+   .then(() => {
+     toast.success('操作已确认')
+   })
    .catch((error) => {
      console.log(error)
+     toast.info('操作已取消')
    })
}

148-152: 确认自定义样式的影响范围

新增的 .custom-shadow 样式可能会影响全局的样式,建议使用更具针对性的选择器,或限制样式作用域,防止影响其他组件。

:deep() {
  .custom-shadow {
    box-shadow: 0 3px 1px -2px rgb(0 0 0 / 20%), 0 2px 2px 0 rgb(0 0 0 / 14%), 0 1px 5px 0 rgb(0 0 0 / 12%);
  }
}
+/* 或者使用 scoped 样式 */
src/uni_modules/wot-design-uni/components/wd-input/types.ts (1)

11-11: 代码变更看起来不错,建议考虑未来扩展性

类型定义清晰且符合 TypeScript 最佳实践。不过建议考虑以下建议:

  • 考虑在 InputSize 中预留其他可能的尺寸选项,如 'small'、'medium' 等
  • 为新增的类型添加 JSDoc 注释,说明各个尺寸的使用场景

Also applies to: 143-143

docs/component/message-box.md (2)

126-129: 建议完善插槽示例代码

示例代码中使用了 v-model 绑定 rate,但没有展示完整的响应式数据定义。建议补充说明:

 <wd-message-box selector="wd-message-box-slot">
   <wd-rate custom-class="custom-rate-class" v-model="rate" />
 </wd-message-box>
+
+<!-- 在 script 中添加: -->
+const rate = ref(1)

253-271: 属性表格格式需要调整

表格中的一些单元格存在多余的空格,建议统一格式:

  1. 删除参数列中的多余空格
  2. 统一说明列的中文标点符号
  3. 建议为新增的按钮属性添加示例值
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 356cb4a and fd09fcd.

📒 Files selected for processing (7)
  • docs/component/message-box.md (4 hunks)
  • src/pages/messageBox/Index.vue (3 hunks)
  • src/uni_modules/wot-design-uni/components/wd-input/types.ts (3 hunks)
  • src/uni_modules/wot-design-uni/components/wd-message-box/index.scss (1 hunks)
  • src/uni_modules/wot-design-uni/components/wd-message-box/index.ts (3 hunks)
  • src/uni_modules/wot-design-uni/components/wd-message-box/types.ts (4 hunks)
  • src/uni_modules/wot-design-uni/components/wd-message-box/wd-message-box.vue (7 hunks)
🔇 Additional comments (1)
src/uni_modules/wot-design-uni/components/wd-message-box/index.scss (1)

91-95: 确认新样式对按钮布局的影响

新增的样式可能会影响其他使用 wd-message-box 组件的布局,建议在测试环境下确认新样式的兼容性,确保不会破坏现有界面。

请运行以下脚本检查受影响的文件:

✅ Verification successful

Let me gather more information about the message box component and its usage.


让我检查一下按钮样式的具体实现和使用情况。


新增样式对按钮布局影响可控

经过验证,新增的按钮间距样式是安全的:

  1. 样式仅影响 MessageBox 组件内部的按钮布局,通过 edeep(actions-btn) 选择器严格限定作用范围
  2. 组件模板中的按钮布局结构清晰,新样式与现有布局逻辑(wd-message-box__flexwd-message-box__block)配合得当
  3. 示例代码展示了多种使用场景,包括单按钮和双按钮情况,新样式能够适应这些场景
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:查找所有使用 wd-message-box 的文件,验证按钮样式的影响。

# 测试:搜索 wd-message-box 引用。期望:列出所有相关文件以供手动检查。
fd --type f --extension vue 'wd-message-box'

Length of output: 120


Script:

#!/bin/bash
# 搜索引用 wd-message-box 组件的代码
rg -l "wd-message-box"

# 检查组件的模板代码,了解按钮布局实现
cat src/uni_modules/wot-design-uni/components/wd-message-box/wd-message-box.vue

Length of output: 8989


Script:

#!/bin/bash
# 检查按钮布局相关的样式实现
cat src/uni_modules/wot-design-uni/components/wd-message-box/index.scss

# 查找示例用法
cat src/pages/messageBox/Index.vue

Length of output: 5852

Comment on lines +166 to 182
if (messageState.beforeConfirm) {
messageState.beforeConfirm({
resolve: (isPass) => {
if (isPass) {
handleConfirm({
action: action,
value: inputValue.value
value: messageState.inputValue
})
}
}
})
} else {
handleConfirm({
action: action,
value: inputValue.value
value: messageState.inputValue
})
}
Copy link

@coderabbitai coderabbitai bot Dec 5, 2024

Choose a reason for hiding this comment

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

⚠️ Potential issue

确认 beforeConfirm 回调的错误处理

toggleModal 方法中,当存在 beforeConfirm 时,需要确保在 resolve(false) 的情况下正确处理拒绝逻辑。当前代码仅在 isPasstrue 时执行 handleConfirm,建议在 isPassfalse 时调用 handleCancel,以确保流程的完整性。

if (messageState.beforeConfirm) {
  messageState.beforeConfirm({
    resolve: (isPass) => {
      if (isPass) {
        handleConfirm({
          action: action,
          value: messageState.inputValue
        })
+     } else {
+       handleCancel({
+         action: 'cancel'
+       })
      }
    }
  })
}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (messageState.beforeConfirm) {
messageState.beforeConfirm({
resolve: (isPass) => {
if (isPass) {
handleConfirm({
action: action,
value: inputValue.value
value: messageState.inputValue
})
}
}
})
} else {
handleConfirm({
action: action,
value: inputValue.value
value: messageState.inputValue
})
}
if (messageState.beforeConfirm) {
messageState.beforeConfirm({
resolve: (isPass) => {
if (isPass) {
handleConfirm({
action: action,
value: messageState.inputValue
})
} else {
handleCancel({
action: 'cancel'
})
}
}
})
} else {
handleConfirm({
action: action,
value: messageState.inputValue
})
}

Copy link
Owner Author

Choose a reason for hiding this comment

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

isPass为false时,并非取消,而是阻止了执行confirm

Copy link

Choose a reason for hiding this comment

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

@Moonofweisheng,明白您的意思,感谢您的解释。


✏️ Learnings added
Learnt from: Moonofweisheng
PR: Moonofweisheng/wot-design-uni#761
File: src/uni_modules/wot-design-uni/components/wd-message-box/wd-message-box.vue:166-182
Timestamp: 2024-12-05T15:55:34.823Z
Learning: 在文件 `wd-message-box.vue` 的 `toggleModal` 方法中,当 `isPass` 为 `false` 时,应阻止执行 `confirm`,但不触发 `cancel` 操作。

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Comment on lines 194 to 232
## 自定义操作按钮<el-tag text style="vertical-align: middle;margin-left:8px;" effect="plain">$LOWEST_VERSION$</el-tag>

可以通过按钮属性 `cancel-button-props``confirm-button-props` 自定义操作按钮的样式,具体参考 [Button Attributes](/component/button.html#attributes)

```html
<wd-message-box></wd-message-box>
<wd-button @click="beforeConfirm">beforeConfirm</wd-button>
```

```typescript
function withButtonProps() {
message
.confirm({
msg: '自定义按钮样式',
title: '提示',
cancelButtonProps: {
type: 'error',
customClass: 'custom-shadow'
},
confirmButtonProps: {
type: 'success',
customClass: 'custom-shadow'
}
})
.then(() => {})
.catch((error) => {
console.log(error)
})
}
```

```css
:deep() {
.custom-shadow {
box-shadow: 0 3px 1px -2px rgb(0 0 0 / 20%), 0 2px 2px 0 rgb(0 0 0 / 14%), 0 1px 5px 0 rgb(0 0 0 / 12%);
}
}
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. 示例代码中的方法名与实际调用不一致(beforeConfirm vs withButtonProps
  2. 建议添加效果截图,帮助用户直观理解样式变化
  3. CSS 示例中的 :deep() 选择器缺少目标选择器

建议修改如下:

-<wd-button @click="beforeConfirm">beforeConfirm</wd-button>
+<wd-button @click="withButtonProps">自定义按钮</wd-button>

 :deep() {
+.wd-message-box {
   .custom-shadow {
     box-shadow: 0 3px 1px -2px rgb(0 0 0 / 20%);
   }
+}
 }

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

@Moonofweisheng Moonofweisheng force-pushed the feature/message-button-props branch from fd09fcd to 9572871 Compare December 5, 2024 15:54
@cloudflare-workers-and-pages
Copy link

Deploying wot-design-uni with  Cloudflare Pages  Cloudflare Pages

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

View logs

@Moonofweisheng Moonofweisheng merged commit 80682ba into master Dec 5, 2024
4 of 7 checks passed
@Moonofweisheng Moonofweisheng deleted the feature/message-button-props branch March 25, 2025 15:08
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.

[新功能需求] MessageBox建议可以自定义圆角,自定按钮是否圆角

2 participants