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: ✨ form 表单禁用功能 #629

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

RYGRIT
Copy link
Contributor

@RYGRIT RYGRIT commented Sep 24, 2024

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

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

🔗 相关 Issue

表单禁用功能

💡 需求背景和解决方案

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

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

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

Summary by CodeRabbit

  • 新功能

    • 在表单组件中添加了“禁用”属性,允许用户在需要时禁用整个表单。
    • 子组件会继承父组件的禁用状态,确保一致的用户体验。
  • 文档

    • 更新了“禁用”属性的描述,明确其功能。

Copy link

vercel bot commented Sep 24, 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 Sep 24, 2024 10:07am

Copy link

coderabbitai bot commented Sep 24, 2024

Walkthrough

此次更改涉及对表单组件的修改,主要是引入了 disabled 属性。通过在 wd-form 组件中添加该属性,表单可以被设置为禁用状态,从而阻止用户与表单字段的交互。此外,相关的组合逻辑也进行了调整,以确保子组件在父组件被禁用时也会继承这一状态。

Changes

文件路径 更改摘要
src/pages/form/Index.vue wd-form 组件中添加了 disabled 属性,使表单处于禁用状态。
src/uni_modules/wot-design-uni/components/composables/useChildren.ts useChildren 组合中添加了条件检查,以确保父组件禁用时,子组件也会继承禁用状态。
src/uni_modules/wot-design-uni/components/wd-form/types.ts formProps 对象中新增了 disabled 属性,类型为布尔值,默认值为 false,并添加了相应的注释说明。

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

netlify bot commented Sep 24, 2024

Deploy Preview for wot-design-uni ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit d93132d
🔍 Latest deploy log https://app.netlify.com/sites/wot-design-uni/deploys/66f28f1732198c000821a7ed
😎 Deploy Preview https://deploy-preview-629--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: 1

Outside diff range and nitpick comments (1)
src/uni_modules/wot-design-uni/components/wd-form/types.ts (1)

66-70: 代码变更看起来不错,建议稍微调整注释措辞。

新增的 disabled 属性实现符合预期,使用了 makeBooleanProp(false) 来定义,与文件中其他布尔属性的定义方式一致。这个改动很好地实现了 PR 中描述的表单禁用功能。

建议稍微调整注释的措辞,使其更加准确和简洁。可以考虑如下修改:

  /**
-  * 表单整体禁用,开启之后,里面的表单项都会被禁用
+  * 禁用整个表单,启用后所有表单项将被禁用
   */

这样的表述更加直接和清晰,同时保持了注释的简洁性。

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c6b2cf8 and d93132d.

Files selected for processing (3)
  • src/pages/form/Index.vue (1 hunks)
  • src/uni_modules/wot-design-uni/components/composables/useChildren.ts (1 hunks)
  • src/uni_modules/wot-design-uni/components/wd-form/types.ts (1 hunks)
Additional comments not posted (1)
src/pages/form/Index.vue (1)

4-4: 已添加禁用功能,请验证并考虑用户体验

这个更改符合PR的目标,为表单添加了禁用功能。很好的实现!

建议:

  1. 请验证 disabled 状态是否正确传播到所有子组件(输入框和按钮)。
  2. 考虑为禁用状态添加视觉反馈,以便用户理解表单当前不可交互。
  3. 建议添加注释说明为什么默认禁用此表单,或考虑是否应该默认启用。

可以运行以下脚本来验证 disabled 属性在其他表单组件中的使用情况:

考虑添加一个计算属性或方法来动态控制表单的禁用状态,而不是硬编码。例如:

<wd-form ref="form1" :model="model1" :disabled="isFormDisabled">
  <!-- 表单内容 -->
</wd-form>

<script setup>
const isFormDisabled = ref(true) // 或者使用计算属性

function toggleFormDisabled() {
  isFormDisabled.value = !isFormDisabled.value
}
</script>

这样可以更灵活地控制表单的禁用状态。

Verification successful

禁用功能已正确实现,无其他问题

经过验证,src/pages/form/Index.vue 中的 wd-form 组件成功添加了 disabled 属性,并且未在其他组件中发现相关问题。该更改符合预期,已通过审核。

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:检查其他表单组件是否正确使用了 disabled 属性

# 测试:搜索其他使用 wd-form 的文件,检查是否正确处理了 disabled 状态
rg --type vue 'wd-form' -A 10 | grep -v 'src/pages/form/Index.vue'

Length of output: 92


Script:

#!/bin/bash
# 描述:检查其他表单组件是否正确使用了 disabled 属性

# 使用 --glob 指定搜索 .vue 文件,避免文件类型未定义的问题
rg 'wd-form' --glob '*.vue' -A 10 | grep -v 'src/pages/form/Index.vue'

Length of output: 22771

Comment on lines +83 to +85
if ((value as any).props?.disabled) {
child.props.disabled = true
}
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. 它假设所有子组件都有 disabled 属性,这可能并不总是成立。
  2. 直接修改子组件的 props 可能会导致意外行为。

建议考虑以下改进:

  1. 在修改子组件的 disabled 属性之前,先检查该属性是否存在:

    if ((value as any).props?.disabled && 'disabled' in child.props) {
      child.props.disabled = true
    }
  2. 考虑使用一个单独的属性(如 parentDisabled)来表示父组件的禁用状态,而不是直接覆盖子组件的 disabled 属性:

    if ((value as any).props?.disabled) {
      child.props.parentDisabled = true
    }
  3. 在文档中明确说明这种行为,以便其他开发者了解这种级联禁用的机制。

  4. 考虑添加一个选项,允许开发者控制是否启用这种级联禁用行为。

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