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

refactor: refactor code structure and improve demo page #4389

Merged
merged 13 commits into from
Sep 14, 2024

Conversation

Squall2017
Copy link
Contributor

@Squall2017 Squall2017 commented Sep 13, 2024

Description

  1. 优化代码结构以及演例交互效果
  2. click事件回调参数更改为点选点
  3. 增加提示文本参数
  4. 添加国际化

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Checklist

ℹ️ Check all checkboxes - this will indicate that you have done everything in accordance with the rules in CONTRIBUTING.

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs:dev command.
  • Run the tests with pnpm test.
  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced a new CaptchaCard component for enhanced captcha display.
    • Added customizable properties for captcha dimensions and titles.
    • Improved interactivity with new input fields for user-defined captcha settings.
    • Enhanced user feedback with success messages upon point selection.
    • Added localization support for English and Chinese, improving accessibility and user guidance.
  • Bug Fixes

    • Improved error handling for missing hint images or text in the point selection captcha.
  • Documentation

    • Updated types and interfaces for better clarity and usability in captcha-related components.
    • Expanded localization entries to include detailed instructions and descriptions for captcha interactions.

Copy link

changeset-bot bot commented Sep 13, 2024

⚠️ No Changeset found

Latest commit: fe2080d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Sep 13, 2024

Walkthrough

The changes introduce a new captcha-card.vue component for rendering captcha interfaces in a card layout, enhancing the existing captcha functionality. Modifications were made to the point-selection-captcha.vue component, including prop restructuring and logic updates for user interactions. New types were defined in types.ts, and a utility function, parseValue, was added to handle numeric inputs. Additionally, the index.vue file in the playground was updated to allow dynamic configuration of captcha properties, improving user interaction and customization options.

Changes

Files Change Summary
packages/effects/common-ui/src/components/captcha/captcha-card.vue Introduced captcha-card.vue component for captcha display with customizable props and a structured card layout.
packages/effects/common-ui/src/components/captcha/index.ts Added export statement for the new CaptchaCard component, enhancing the module's offerings.
packages/effects/common-ui/src/components/captcha/point-selection-captcha.vue Restructured props and logic, updated event emissions, and replaced layout with CaptchaCard for improved usability.
packages/effects/common-ui/src/components/captcha/types.ts Renamed CaptchaPoint to CaptchaData, added new interfaces for CaptchaCardProps and PointSelectionCaptchaProps, enhancing type structure.
packages/effects/common-ui/src/components/captcha/utils.ts Introduced parseValue utility function to handle numeric input values robustly.
playground/src/views/examples/captcha/index.vue Enhanced captcha configuration with a reactive params object, allowing dynamic updates and improved user interaction through new input fields.
packages/locales/src/langs/en-US.json Added new "captcha" object with properties for UI text related to captcha functionality, improving accessibility.
packages/locales/src/langs/zh-CN.json Added new "captcha" object with properties for UI text related to captcha functionality in Chinese, enhancing accessibility.
playground/src/locales/langs/en-US.json Expanded "captcha" section with detailed descriptions and placeholders for various elements within the captcha interface.
playground/src/locales/langs/zh-CN.json Expanded "captcha" section with detailed descriptions and placeholders for various elements within the captcha interface in Chinese.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CaptchaCard
    participant PointSelectionCaptcha

    User->>CaptchaCard: Click on captcha
    CaptchaCard->>PointSelectionCaptcha: Emit click event with point data
    PointSelectionCaptcha->>User: Display hint or confirmation
Loading

🐰 In a card so bright and fair,
A captcha waits with gentle care.
Click the points, let joy unfold,
In this new world, be brave and bold!
With hints and styles, the fun's begun,
Hop along, let's share the fun! 🌟

Possibly related PRs

Suggested labels

feature

Tip

OpenAI O1 model for chat
  • We have deployed OpenAI's latest O1 model for chat.
  • OpenAI claims that this model has superior reasoning capabilities than their GPT-4o model.
  • Please share any feedback with us in the discussions post.

Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c55375d and fe2080d.

Files selected for processing (1)
  • playground/src/views/examples/captcha/index.vue (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • playground/src/views/examples/captcha/index.vue

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

@Squall2017 Squall2017 changed the title refactor code structure and improve demo page refactor: refactor code structure and improve demo page Sep 13, 2024
Copy link
Contributor

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

Outside diff range and nitpick comments (3)
packages/effects/common-ui/src/components/captcha/utils.ts (1)

1-7: Consider simplifying the function by directly returning the parsed value.

The function can be simplified by directly returning the parsed value and letting the caller handle NaN values if needed.

Apply this diff to simplify the function:

export const parseValue = (value: number | string) => {
  if (typeof value === 'number') {
    return value;
  }
- const parsed = Number.parseFloat(value);
- return Number.isNaN(parsed) ? 0 : parsed;
+ return Number.parseFloat(value);
};

This simplification allows the caller to handle NaN values as needed, providing more flexibility and reducing the function's responsibility.

packages/effects/common-ui/src/components/captcha/captcha-card.vue (2)

40-42: Consider using an arrow function for consistency.

The handleClick function is defined using the function keyword, which is inconsistent with the rest of the code that uses arrow functions. Consider using an arrow function for consistency:

-function handleClick(e: MouseEvent) {
+const handleClick = (e: MouseEvent) => {
   emit('click', e);
 }

55-62: Make the alt attribute of the img element configurable via a prop.

The alt attribute of the img element is hardcoded in Chinese. It should be made configurable via a prop to support internationalization. Consider adding a new prop for the alt attribute:

 const props = withDefaults(defineProps<CaptchaCardProps>(), {
   height: '220px',
   paddingX: '12px',
   paddingY: '16px',
   title: '',
   width: '300px',
+  alt: '验证码图片(支持img标签src属性值)',
 });

Then, use the prop in the template:

 <img
   v-show="captchaImage"
   :src="captchaImage"
   :style="captchaStyles"
-  alt="验证码图片(支持img标签src属性值)"
+  :alt="alt"
   class="relative z-10"
   @click="handleClick"
 />
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between bd6b724 and d95633a.

Files selected for processing (6)
  • packages/effects/common-ui/src/components/captcha/captcha-card.vue (1 hunks)
  • packages/effects/common-ui/src/components/captcha/index.ts (1 hunks)
  • packages/effects/common-ui/src/components/captcha/point-selection-captcha.vue (4 hunks)
  • packages/effects/common-ui/src/components/captcha/types.ts (1 hunks)
  • packages/effects/common-ui/src/components/captcha/utils.ts (1 hunks)
  • playground/src/views/examples/captcha/index.vue (2 hunks)
Additional comments not posted (22)
packages/effects/common-ui/src/components/captcha/index.ts (1)

1-1: LGTM!

The new export statement for the CaptchaCard component is a non-breaking change that enhances the module's functionality without altering existing logic or exports. This is a clean and straightforward addition.

packages/effects/common-ui/src/components/captcha/types.ts (4)

1-14: LGTM!

The CaptchaData interface is well-defined with clear property names and JSDoc comments. The structure aligns with the expected captcha data format.


15-20: LGTM!

The CaptchaPoint interface correctly extends CaptchaData and adds a new property i for data indexing. The structure aligns with the expected captcha point format.


21-51: LGTM!

The CaptchaCardProps interface is well-defined with clear property names and JSDoc comments. The structure aligns with the expected props for a captcha card component. The use of @default tags to specify default values for optional properties is a good practice.


53-69: LGTM!

The PointSelectionCaptchaProps interface correctly extends CaptchaCardProps and adds new properties for controlling the visibility of a confirm button and providing hint images and text. The structure aligns with the expected props for a point selection captcha component. The use of @default tags to specify default values for optional properties is a good practice.

packages/effects/common-ui/src/components/captcha/captcha-card.vue (1)

1-15: LGTM!

The imports are well-organized and follow a consistent pattern. The component imports only what it needs, which is a good practice.

packages/effects/common-ui/src/components/captcha/point-selection-captcha.vue (9)

2-2: LGTM!

The import statement is correct and necessary for using the CaptchaPoint and PointSelectionCaptchaProps types in the component.


7-9: LGTM!

The import statements are correct and necessary for using the VbenButton, VbenIconButton, and CaptchaCard components in the template.


11-30: LGTM!

  • Using withDefaults is a good practice for defining props with default values.
  • The default values seem reasonable.
  • Throwing an error for missing hintImage and hintText props is a good validation check.

23-23: LGTM!

Emitting the click event with a CaptchaPoint object is a good change as it encapsulates the point data. The event name and parameter type are correctly defined.


81-90: LGTM!

  • Creating a CaptchaPoint object with the necessary data is a good approach.
  • Pushing the point to the points array is necessary for tracking the clicked points.
  • Emitting the click event with the created point is consistent with the event definition.

115-115: LGTM!

Checking the showConfirm prop is a good guard to ensure the confirm event is emitted only when necessary.


124-179: LGTM!

  • Using the CaptchaCard component is a good abstraction for rendering the captcha.
  • Passing the component props to the CaptchaCard component is necessary for customization.
  • Rendering the clicked points as numbered dots provides visual feedback to the user.
  • Conditionally rendering the hint image or text based on the props is a good approach.

152-164: LGTM!

  • Rendering the clicked points as numbered dots provides visual feedback to the user.
  • Calculating the position of each dot based on the clicked coordinates is correct.
  • Using Tailwind CSS classes for styling is consistent with the project's styling approach.

Line range hint 1-181: Overall, the changes in this file look good to me!

The refactoring of the point-selection-captcha component has improved its structure, props, and event handling. The use of the CaptchaCard component and the conditional rendering of the hint image or text have enhanced the component's flexibility and maintainability. The code follows good practices and is consistent with the project's conventions.

Great job on this refactor! Let me know if you have any further questions or concerns.

playground/src/views/examples/captcha/index.vue (7)

4-4: LGTM!

The imports are correctly added and necessary for creating reactive data in the component.


8-8: LGTM!

The imports are correctly added and necessary for using the Ant Design Vue components in the template.


13-26: Great work on introducing the params object!

The reactive params object is an excellent way to centralize and manage the captcha configuration options. It provides a clean and organized approach to customizing the captcha component's appearance and behavior.

The properties included in the params object cover a wide range of customization options, allowing users to fine-tune the captcha according to their needs.

The reactive nature of the params object ensures that any changes made by the user are immediately reflected in the captcha component.


28-30: Nice enhancement to the handleConfirm function!

Displaying a success message with the selected captcha points is a great way to provide immediate feedback to the user. It confirms that their input has been successfully processed and allows them to verify the selected points.

This enhancement improves the user experience and helps in debugging or troubleshooting any issues related to point selection.


36-38: Great addition of the handleClick function!

The handleClick function is a useful addition to manage the selection of captcha points. It provides a clear and concise way to track and store the selected points.

Pushing the selected points into the selectedPoints array allows for further processing, validation, or display of the selected points. This can be helpful in scenarios where you need to perform additional checks or provide visual feedback to the user.

The function name handleClick accurately describes its purpose, making the code more readable and maintainable.


47-133: Excellent work on adding the customization options!

The new input fields and switches greatly enhance the flexibility and usability of the captcha component. Users can now easily customize various aspects of the captcha, such as the title, image URLs, dimensions, padding, and display options.

Binding the input fields to the corresponding properties in the params object ensures that any changes made by the user are immediately reflected in the captcha component. This real-time update functionality provides a smooth and interactive user experience.

The switches for controlling the display of the hint image/text and the confirm button are intuitive and user-friendly. They allow users to toggle between different display options based on their preferences or requirements.

The layout and spacing of the input fields and switches are well-organized and visually appealing. The consistent use of margins and widths creates a clean and readable interface.

Overall, these customization options significantly improve the flexibility and usability of the captcha component, making it adaptable to various scenarios and user needs.


136-159: Great job on integrating the params object and improving the selected points display!

Updating the PointSelectionCaptcha component to use the values from the params object is a smart move. It ensures that the captcha component dynamically adapts to the user's customization options, providing a seamless and personalized experience.

The switch from a div to an ordered list (ol) for rendering the selected points is a nice improvement. It enhances the semantic structure of the markup and makes the selected points more readable and visually distinguishable.

Using the v-for directive to dynamically render the selected points is an efficient and flexible approach. It allows for a variable number of points to be displayed without the need for manual updates to the template.

The displayed information for each selected point, including the index, timestamp, and coordinates, provides valuable details for debugging and understanding user interactions.

Overall, these changes enhance the integration and display of the captcha component, making it more dynamic, user-friendly, and informative.

@vince292007
Copy link
Collaborator

可以顺便加下国际化吗

@Squall2017
Copy link
Contributor Author

可以顺便加下国际化吗

ok

@vince292007 vince292007 added enhancement New feature or request perf labels Sep 14, 2024
@vince292007 vince292007 merged commit 5ba3a9d into vbenjs:main Sep 14, 2024
14 checks passed
kkfive pushed a commit to kkfive/vue-vben-admin that referenced this pull request Sep 14, 2024
* feat: captcha example

* fix: fix lint errors

* chore: event handling and methods

* chore: add accessibility features ARIA labels and roles

* refactor: refactor code structure and improve captcha demo page

* feat: add captcha internationalization

* chore: 适配时间戳国际化展示

---------

Co-authored-by: vince <vince292007@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request perf
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants