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

fix: Improve the problem of inaccurate captcha accuracy #4401

Merged
merged 16 commits into from
Sep 14, 2024

Conversation

Squall2017
Copy link
Contributor

@Squall2017 Squall2017 commented Sep 14, 2024

Description

  1. 添加点击位置边界校验,防止点击外部导致x,y误差。
  2. 演示页面宽度过长添加滚动条。
  3. 添加hooks

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

Release Notes

  • New Features

    • Introduced a customizable CaptchaCard component for enhanced captcha interactions.
    • Added a new hook for managing captcha points, allowing for dynamic interaction.
    • Expanded localization support for captcha elements in both English and Chinese.
  • Bug Fixes

    • Improved validation for click events within the captcha component.
  • Enhancements

    • Enhanced user interface with additional input fields for customizing captcha properties.
    • Updated templates for better user guidance and interaction with captcha elements.

Copy link

changeset-bot bot commented Sep 14, 2024

⚠️ No Changeset found

Latest commit: 54e3d70

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 14, 2024

Walkthrough

This pull request introduces several enhancements to the captcha functionality within the application. It adds a new CaptchaCard component and a custom hook for managing captcha points. The existing PointSelectionCaptcha component is refactored to utilize the new CaptchaCard, improving its structure and usability. Additionally, various localization files are updated to support the new features, and utility functions are introduced for better handling of input values.

Changes

File Change Summary
packages/effects/common-ui/src/components/captcha/captcha-card.vue Introduced a new Vue component for rendering a captcha card interface with type-safe props and event emissions.
packages/effects/common-ui/src/components/captcha/hooks/useCaptchaPoints.ts Added a custom hook to manage a reactive array of CaptchaPoint objects with methods to add and clear points.
packages/effects/common-ui/src/components/captcha/index.ts Exported the new CaptchaCard component to make it available for use in the application.
packages/effects/common-ui/src/components/captcha/point-selection-captcha.vue Refactored the component to streamline props and enhance click event handling; integrated the new CaptchaCard component.
packages/effects/common-ui/src/components/captcha/types.ts Introduced new interfaces for CaptchaData, CaptchaCardProps, and PointSelectionCaptchaProps, enhancing type definitions.
packages/effects/common-ui/src/components/captcha/utils.ts Added a utility function parseValue to handle numeric and string inputs.
packages/locales/src/langs/en-US.json Added a new "captcha" object with localization strings for accessibility and user guidance.
packages/locales/src/langs/zh-CN.json Added a "captcha" section with translations for various captcha-related terms and phrases to enhance user experience for Chinese-speaking users.
playground/src/locales/langs/en-US.json Expanded the "captcha" section with additional key-value pairs for improved user guidance and interaction.
playground/src/locales/langs/zh-CN.json Added new entries to the "captcha" section for better user guidance in Chinese localization.
playground/src/views/examples/captcha/index.vue Enhanced the captcha example view with reactive parameters for dynamic updates and improved user interface for customizing captcha properties.

Possibly related PRs

Suggested labels

bug

Poem

🐇 In the garden where bunnies play,
New captchas bloom, bright as day.
With cards and points, they hop around,
Making sure no spam is found.
A joyful leap, a click, a cheer,
Captcha magic, we hold dear! 🌼


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.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d99cad3 and c202641.

Files selected for processing (11)
  • packages/effects/common-ui/src/components/captcha/captcha-card.vue (1 hunks)
  • packages/effects/common-ui/src/components/captcha/hooks/useCaptchaPoints.ts (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)
  • packages/locales/src/langs/en-US.json (1 hunks)
  • packages/locales/src/langs/zh-CN.json (1 hunks)
  • playground/src/locales/langs/en-US.json (1 hunks)
  • playground/src/locales/langs/zh-CN.json (1 hunks)
  • playground/src/views/examples/captcha/index.vue (1 hunks)
Additional comments not posted (45)
packages/effects/common-ui/src/components/captcha/index.ts (1)

1-1: LGTM!

The addition of the CaptchaCard export statement is consistent with the existing exports in the file. It follows the correct syntax and naming convention.

Based on the AI-generated summary, the CaptchaCard component seems to be a valuable addition that enhances the captcha-related UI elements in the application.

packages/effects/common-ui/src/components/captcha/hooks/useCaptchaPoints.ts (1)

5-18: LGTM!

The useCaptchaPoints function is well-structured and provides a clean interface for managing captcha points. The use of reactivity ensures that changes to the points array will trigger updates in the consuming component. The code is properly typed and the naming is clear and descriptive.

Great job encapsulating the captcha point management functionality in this reusable composition function!

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

1-14: LGTM!

The CaptchaData interface is well-defined with clear property names and types. The JSDoc comments provide a brief description of each property, enhancing the code readability.


15-20: LGTM!

The changes to the CaptchaPoint interface are well-implemented. Extending the CaptchaData interface is a good way to reuse the common properties. The additional property i is well-defined with a clear name and type, and the JSDoc comment provides a brief description of the property.


21-51: LGTM!

The CaptchaCardProps interface is well-defined with clear property names and types. The JSDoc comments provide a brief description of each property and their default values, enhancing the code readability. The optional properties allow flexibility in customizing the captcha card component.


53-69: LGTM!

The PointSelectionCaptchaProps interface is well-defined by extending the CaptchaCardProps interface. The additional properties showConfirm, hintImage, and hintText are well-defined with clear names and types. The JSDoc comments provide a brief description of each property and their default values, enhancing the code readability. The optional properties allow flexibility in customizing the point selection captcha component.

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

1-77: Excellent work on the new CaptchaCard component!

The component is well-structured and follows best practices, making it maintainable and reusable. Here are some positive aspects:

  1. The use of the Composition API with TypeScript ensures type safety and improves code readability.
  2. The component's props and default values allow for easy customization of the card's dimensions, padding, and title.
  3. The computed properties for dynamic styling make the component more flexible and adaptable to different use cases.
  4. The template structure is clean and organized, with clear separation of the header, content, and footer sections.
  5. The component emits a click event when the captcha image is clicked, enabling parent components to handle the event and perform necessary actions.
  6. The use of slots for the title, extra content in the header, main content area, and footer enhances the component's flexibility and allows for customization.
  7. The component imports and uses utility functions and types from external files, promoting code reusability and maintainability.

Overall, the CaptchaCard component is a great addition to the project and follows best practices for Vue component development.

playground/src/locales/langs/zh-CN.json (20)

85-85: LGTM!

The key-value pair is correctly formatted and the value is an appropriate translation for the key.


86-86: LGTM!

The key-value pair is correctly formatted and the value is an appropriate translation for the key.


87-87: LGTM!

The key-value pair is correctly formatted and the value is an appropriate translation for the key.


88-88: LGTM!

The key-value pair is correctly formatted and the value is an appropriate translation for the key.


89-89: LGTM!

The key-value pair is correctly formatted and the value is an appropriate translation for the key.


90-90: LGTM!

The key-value pair is correctly formatted and the value is an appropriate translation for the key.


91-91: LGTM!

The key-value pair is correctly formatted and the value is an appropriate translation for the key.


92-92: LGTM!

The key-value pair is correctly formatted and the value is an appropriate translation for the key.


93-93: LGTM!

The key-value pair is correctly formatted and the value is an appropriate translation for the key.


94-94: LGTM!

The key-value pair is correctly formatted and the value is an appropriate translation for the key.


95-95: LGTM!

The key-value pair is correctly formatted and the value is an appropriate translation for the key.


96-96: LGTM!

The key-value pair is correctly formatted and the value is an appropriate translation for the key.


97-97: LGTM!

The key-value pair is correctly formatted and the value is an appropriate translation for the key.


98-98: LGTM!

The key-value pair is correctly formatted and the value is an appropriate translation for the key.


99-99: LGTM!

The key-value pair is correctly formatted and the value is an appropriate translation for the key.


100-100: LGTM!

The key-value pair is correctly formatted and the value is an appropriate translation for the key.


101-101: LGTM!

The key-value pair is correctly formatted and the value is an appropriate translation for the key.


102-102: LGTM!

The key-value pair is correctly formatted and the value is an appropriate translation for the key.


103-103: LGTM!

The key-value pair is correctly formatted and the value is an appropriate translation for the key.


104-104: LGTM!

The key-value pair is

playground/src/locales/langs/en-US.json (1)

84-104: LGTM!

The added localization key-value pairs for the captcha component are comprehensive and well-structured. The keys follow a consistent naming convention, and the values provide clear and concise descriptions. The placeholders offer helpful guidance on the expected format and default values for various attributes.

These changes enhance the user experience by providing localized text for the captcha component, making it more user-friendly and accessible.

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

2-2: LGTM!

Importing types from a separate file is a good practice for code organization and reusability.


5-6: LGTM!

Importing localization and UI components from external packages is a common practice in Vue applications.


8-9: LGTM!

Using a separate component for the captcha card and a custom hook for managing captcha points promotes code modularity and reusability.


11-30: LGTM!

  • Using withDefaults and defineProps with a typed interface is a good practice for defining and validating component props.
  • Providing default values for props enhances the component's flexibility and ease of use.
  • Logging a warning when required props are missing helps catch potential issues during development.

Line range hint 32-80: LGTM!

  • Using constants for magic numbers and separating utility functions are good practices.
  • The handleClick function performs necessary validations and emits the click event with relevant data.
  • Error handling is implemented using try-catch blocks and logging errors to the console.

Line range hint 89-107: LGTM!

  • The functions are correctly implemented and follow the single responsibility principle.
  • Error handling is implemented using try-catch blocks and logging errors to the console.

114-159: LGTM!

  • Using the CaptchaCard component improves code modularity and reusability.
  • Defining slots for customization enhances the component's flexibility.
  • The captcha points are correctly rendered based on their coordinates and styled appropriately.

160-173: LGTM!

  • Using a slot for the footer allows for flexible customization of the captcha hint.
  • Rendering either an image or text based on the provided props is a good approach for handling different hint types.
  • The hint image and text are styled appropriately using CSS classes.

174-174: LGTM!

The closing tag for the CaptchaCard component is correctly placed.

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

4-4: LGTM!

The imports are necessary for the changes introduced in the file and there are no issues with them.


8-9: LGTM!

The imports are necessary for the changes introduced in the file and there are no issues with them.


10-10: LGTM!

The import is necessary for the localized strings used in the template and there are no issues with it.


15-28: LGTM!

The reactive params object provides a structured way to manage the captcha's properties. The properties are initialized with default values and can be dynamically updated. There are no issues with the reactive object declaration.


30-41: LGTM!

The changes to the handleConfirm and handleClick methods are necessary to update the selected points when the captcha is confirmed or a point is clicked. There are no issues with the method updates.


46-177: LGTM!

The template changes introduce input fields for dynamic customization of the captcha's properties. Binding the PointSelectionCaptcha component to the reactive params object enables real-time updates based on user input. The display of selected points using an ordered list with localized labels improves the user experience. There are no issues with the template changes.

packages/locales/src/langs/zh-CN.json (1)

315-322: LGTM!

The added translations for the captcha section in the Simplified Chinese localization file are appropriate and contextually relevant. They provide clear instructions and prompts for users during captcha interactions.

The translations are syntactically correct JSON key-value pairs and integrate well with the existing localization structure.

packages/locales/src/langs/en-US.json (1)

315-322: LGTM!

The addition of the "captcha" object with localization keys and values for captcha-related interactions is a valuable enhancement. It improves accessibility and user guidance during the captcha verification process.

The changes are consistent with the existing localization structure and follow the JSON format correctly.

packages/effects/common-ui/src/components/captcha/utils.ts Outdated Show resolved Hide resolved
@vince292007
Copy link
Collaborator

vince292007 commented Sep 14, 2024

代码有点冲突,前面的已经合并了。还有emit confirm事件目前是返回了数据,至于是否通过校验,这块的逻辑或者演示好像没体现

@Squall2017
Copy link
Contributor Author

代码有点冲突,前面的已经合并了。还有emit confirm事件目前是返回了数据,至于是否通过校验,这块的逻辑或者演示好像没体现

好的,校验交互我看看

@anncwb anncwb changed the title fix: 修复点击外部x,y精度不准问题以及演示页面内容太多的展示问题 fix: Improve the problem of inaccurate captcha accuracy Sep 14, 2024
@anncwb anncwb merged commit 38fe642 into vbenjs:main Sep 14, 2024
12 of 14 checks passed
@anncwb anncwb added the bug Something isn't working label Sep 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants