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(@vben/common-ui): add verify component #4390

Merged
merged 30 commits into from
Sep 21, 2024
Merged

feat(@vben/common-ui): add verify component #4390

merged 30 commits into from
Sep 21, 2024

Conversation

wangjue666
Copy link
Collaborator

@wangjue666 wangjue666 commented Sep 13, 2024

todo

  • 增强拖拽校验的组件的类型

  • 迁移旋转校验组件

Description

image

image

image

image

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 multiple captcha components, including Point Selection, Slider, and Slider Rotate captchas for enhanced user verification.
    • Added localization support for new captcha types, improving user interaction with clear labels in both English and Chinese.
    • Restructured routing for captcha examples, providing organized access to various captcha functionalities.
  • Bug Fixes

    • Enhanced localization key organization for improved clarity in UI elements.
  • Chores

    • Updated localization files to include new keys and improved structure for better maintainability.

Copy link

changeset-bot bot commented Sep 13, 2024

⚠️ No Changeset found

Latest commit: 9e8fc76

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

This pull request introduces significant changes to the captcha components in a Vue.js application. It removes the CaptchaCard export, updates existing exports to new paths, and adds new components for slider-based and point selection captchas. The localization structure is reorganized, and new interfaces are introduced for better type safety and functionality. Additionally, new Vue components for slider and rotation captcha mechanisms are implemented, enhancing user interaction and verification processes.

Changes

File Path Change Summary
packages/effects/common-ui/src/components/captcha/index.ts Removed CaptchaCard, updated PointSelectionCaptcha export path, and added new captcha exports.
packages/effects/common-ui/src/components/captcha/point-selection-captcha/index.vue Updated import paths, renamed CaptchaCard to point-selection-captcha-card.vue, and modified localization keys.
packages/effects/common-ui/src/components/captcha/point-selection-captcha/point-selection-captcha-card.vue Updated props type to PointSelectionCaptchaCardProps, introduced parseValue function for value handling.
packages/effects/common-ui/src/components/captcha/types.ts Renamed CaptchaCardProps to PointSelectionCaptchaCardProps, added new interfaces for slider and rotation captchas.
packages/effects/common-ui/src/components/captcha/slider-captcha/index.vue Introduced a new slider captcha component with props for customization and event handling.
packages/effects/common-ui/src/components/captcha/slider-captcha/slider-captcha-action.vue Added a component for slider actions with props and methods for interaction.
packages/effects/common-ui/src/components/captcha/slider-captcha/slider-captcha-bar.vue Added a slider bar component with customizable styles and methods for width control.
packages/effects/common-ui/src/components/captcha/slider-captcha/slider-captcha-content.vue Introduced a content component for displaying messages and success states.
packages/effects/common-ui/src/components/captcha/slider-rotate-captcha/index.vue Implemented a rotating slider captcha component with user interaction handling.
packages/locales/src/langs/en-US.json Restructured localization keys for captcha under a new "ui" namespace and added new entries.
packages/locales/src/langs/zh-CN.json Updated localization structure for Chinese language, adding new keys under "ui".
playground/src/locales/langs/en-US.json Added new captcha-related entries for point selection, slider captcha, and rotating captcha.
playground/src/locales/langs/zh-CN.json Added new keys for localization of captcha types in Chinese.
playground/src/router/routes/modules/examples.ts Restructured routes for captcha examples into a parent-child hierarchy for better organization.

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • vince292007

Poem

🐇 In the meadow where captchas play,
New components hop in a joyful array!
Slider and points, a dance so sweet,
With every click, our tasks complete.
Type safety blooms, as features grow,
A whimsical world, where bunnies flow! 🌸


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.

@wangjue666 wangjue666 marked this pull request as ready for review September 20, 2024 03:10
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: 11

Outside diff range and nitpick comments (8)
playground/src/views/examples/verify/rotate-verify/index.vue (2)

24-33: Consider adding accessibility attributes to the RotateVerify component.

The RotateVerify component is an interactive component that requires user input. To ensure that it is accessible to users with assistive technologies, consider adding appropriate accessibility attributes such as aria-label or role.

For example, you could add an aria-label attribute to describe the purpose of the component:

<RotateVerify
  :src="avatar"
  text="拖动以进行校验"
  @success="handleSuccess"
+ aria-label="Rotate to verify"
>
  <!-- ... -->
</RotateVerify>

23-34: Consider adding responsive styles for different screen sizes.

The component uses flexbox for layout which is a good practice for responsive design. However, it does not have any specific responsive styles for different screen sizes.

Consider adding responsive styles using CSS media queries to ensure that the component looks good on different screen sizes. For example, you could adjust the padding or font size of the Card component for smaller screens:

<Card class="flex items-center justify-center p-4">
+ <style scoped>
+   @media (max-width: 480px) {
+     :deep(.ant-card-body) {
+       padding: 1rem;
+     }
+     :deep(.vben-rotate-verify) {
+       font-size: 0.8rem;
+     }
+   }
+ </style>
  <!-- ... -->
</Card>
packages/effects/common-ui/src/components/verify/drag-verify/bar.vue (2)

44-44: Remove the empty <style scoped> tag.

The empty <style scoped> tag is unnecessary since no component-specific styles are defined. Please remove it to keep the code clean and concise.

Apply this diff to remove the empty <style scoped> tag:

-<style scoped></style>

1-44: Consider renaming the component file to a more descriptive name.

The component name bar.vue does not clearly convey the purpose or functionality of the component. To improve code readability and maintainability, consider renaming the file to a more descriptive name, such as DraggableVerificationBar.vue or CustomizableVerificationBar.vue.

packages/effects/common-ui/src/components/verify/drag-verify/content.vue (1)

34-49: Consider improving accessibility.

To enhance the accessibility of the component, consider the following suggestions:

  1. Use a more semantically appropriate element like <p> or <span> instead of div for rendering text content. This provides better context to assistive technologies.

  2. Add an aria-label or role attribute to the element to provide additional context to assistive technologies. For example:

<p
  :aria-label="isPassing ? successText : text"
  :class="{ [$style.content]: true, [$style.success]: isPassing }"
  :style="style"
  class="absolute top-0 flex select-none items-center justify-center text-xs"
>
  <!-- ... -->
</p>
  1. Ensure that the conditional rendering of text content is properly conveyed to users relying on assistive technologies. This can be achieved by using the aria-label attribute as shown above.
packages/effects/common-ui/src/components/verify/rotate-verify/index.vue (1)

50-56: Clarify the calculation in 'getFactorRef' when 'minDegree' equals 'maxDegree'

In the getFactorRef computed property, when minDegree equals maxDegree, the function computes:

return Math.floor(1 + Math.random() * 1) / 10 + 1;

This results in a value of either 1.1 or 1.2. Is this the intended behavior? Please confirm that this calculation aligns with the expected functionality, or adjust the formula to produce the desired factor.

packages/effects/common-ui/src/components/verify/drag-verify/index.vue (2)

186-203: Potential Timing Issue in resume Function

The resume function uses useTimeoutFn with a delay of 300ms on line 198. There might be scenarios where state resets occur before animations complete, causing visual glitches.

Consider synchronizing the timeout duration with any CSS transition durations to ensure smooth animations.


208-250: Accessibility Considerations for Drag Components

The template code from lines 208-250 does not include ARIA attributes or keyboard event handlers, which may affect accessibility for users who rely on assistive technologies.

To enhance accessibility:

  • Add ARIA roles and labels to interactive elements.
  • Provide keyboard support for drag actions.
  • Ensure focus management is handled appropriately.
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c72747c and 11caf8c.

Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing (17)
  • packages/@core/base/icons/src/lucide.ts (1 hunks)
  • packages/effects/common-ui/package.json (1 hunks)
  • packages/effects/common-ui/src/components/index.ts (1 hunks)
  • packages/effects/common-ui/src/components/verify/drag-verify/action.vue (1 hunks)
  • packages/effects/common-ui/src/components/verify/drag-verify/bar.vue (1 hunks)
  • packages/effects/common-ui/src/components/verify/drag-verify/content.vue (1 hunks)
  • packages/effects/common-ui/src/components/verify/drag-verify/index.vue (1 hunks)
  • packages/effects/common-ui/src/components/verify/index.ts (1 hunks)
  • packages/effects/common-ui/src/components/verify/props.ts (1 hunks)
  • packages/effects/common-ui/src/components/verify/rotate-verify/index.vue (1 hunks)
  • packages/effects/common-ui/src/components/verify/typing.ts (1 hunks)
  • packages/effects/common-ui/src/components/verify/use-event-listener.ts (1 hunks)
  • playground/src/locales/langs/en-US.json (1 hunks)
  • playground/src/locales/langs/zh-CN.json (1 hunks)
  • playground/src/router/routes/modules/examples.ts (1 hunks)
  • playground/src/views/examples/verify/drag-verify/index.vue (1 hunks)
  • playground/src/views/examples/verify/rotate-verify/index.vue (1 hunks)
Additional comments not posted (33)
packages/effects/common-ui/src/components/verify/index.ts (1)

1-4: LGTM!

The file structure and exports follow best practices for organizing and exporting components and types in a Vue.js application. The exports allow other parts of the application to easily import and utilize the verification functionalities.

packages/effects/common-ui/src/components/index.ts (1)

4-4: LGTM! Ensure proper documentation and adherence to coding standards.

The new export statement correctly re-exports all named exports from the ./verify module, making them accessible to consumers of this index.ts file. This is a common and acceptable pattern for providing a single entry point for related functionality.

However, please ensure that the verify module's exports are properly documented and follow the project's coding standards. This will help maintain consistency and make it easier for other developers to understand and use the newly exposed functionality.

packages/effects/common-ui/src/components/verify/typing.ts (3)

1-3: LGTM!

The interface structure is clear, and the naming is intuitive. The resume method likely resumes a paused drag verification process, which aligns with the interface name.


5-8: LGTM!

The interface structure is clear, and the naming is intuitive. The isPassing and time properties likely represent the verification result and the time taken, which aligns with the interface name.


10-14: LGTM!

The interface structure is clear, and the naming is intuitive. The event, moveDistance, and moveX properties likely represent the event type, total distance moved, and horizontal distance moved, which aligns with the interface name.

packages/@core/base/icons/src/lucide.ts (1)

13-13: LGTM!

The addition of the Check icon export is consistent with the existing code structure and style. It's a straightforward change that doesn't introduce any issues.

packages/effects/common-ui/package.json (2)

30-30: Approve the addition of the @vueuse/core dependency.

The @vueuse/core library provides a collection of useful Vue Composition API utilities. Adding this dependency can enhance the capabilities of the application by allowing developers to leverage reusable logic and features that are part of the Vue ecosystem. This change has the potential to improve code efficiency and modularity in future development efforts.


30-30: Verify the non-standard version specification catalog:.

The version specification catalog: used for the @vueuse/core dependency is non-standard. This may cause issues with dependency resolution and could lead to inconsistencies across different environments.

Please confirm that this version specification is intentional and ensure that it is properly handled by your build tools and package managers. If it is a typo or an unsupported format, update it to a valid semver version or a valid version range.

playground/src/views/examples/verify/rotate-verify/index.vue (2)

1-19: LGTM!

The script section looks good:

  • The imports are relevant and there are no unused imports.
  • The handleSuccess function correctly displays a success message.
  • The avatar computed property correctly retrieves the user avatar or defaults to a predefined avatar.

21-36: LGTM!

The template section looks good:

  • The template structure is clear and easy to understand.
  • The RotateVerify component is correctly configured with the necessary properties and event.
  • The slot for the action icon correctly changes the icon based on the verification state.
packages/effects/common-ui/src/components/verify/drag-verify/bar.vue (2)

1-33: LGTM!

The <script setup> section is well-structured and follows best practices:

  • It properly imports the necessary dependencies.
  • The props are correctly defined with appropriate types.
  • The reactive ref width is used effectively to manage the bar's width.
  • The style computed property constructs the bar's CSS styles based on the provided props.
  • The exposed methods getEl and setWidth are implemented correctly.

Overall, the code is clean, readable, and follows the Vue 3 Composition API conventions.


35-42: LGTM!

The <template> section is properly structured and utilizes the component's props and state:

  • The div element is correctly rendered with a ref attribute for accessing the underlying DOM element.
  • The class attribute is conditionally set based on the toLeft prop to enable a transition effect.
  • The style attribute is properly bound to the style computed property to apply the bar's CSS styles.

The template is clean, readable, and effectively utilizes the component's props and state.

packages/effects/common-ui/src/components/verify/drag-verify/action.vue (1)

1-56: Excellent implementation of the drag-and-verify action component!

The code follows Vue 3 Composition API best practices and effectively utilizes TypeScript for type safety and maintainability. The component is well-structured and encapsulates the logic for a draggable verification action, promoting code reusability.

Some notable aspects of the implementation:

  • The use of defineExpose provides a clear interface for external interaction with the component.
  • The computed style allows the component to adapt to different contexts based on the provided props.
  • The conditional rendering in the template enhances the user experience by displaying appropriate icons based on the isPassing prop.

Overall, the component is flexible, adaptable, and aligns with modern Vue development practices.

packages/effects/common-ui/src/components/verify/drag-verify/content.vue (3)

1-32: LGTM!

The script section of the component follows Vue 3 Composition API best practices:

  • The props are correctly typed and provide good customization options.
  • Using ref and computed is a good way to manage the component's internal state and reactive styles.
  • Exposing the getEl method allows external access to the underlying DOM element, which can be useful for certain use cases.

34-49: LGTM!

The template section of the component is clean and provides good user experience:

  • Using conditional classes based on the isPassing prop provides good visual feedback to the user.
  • Supporting slot content allows for flexibility in text rendering.
  • Defaulting to successText or text based on isPassing provides a good fallback mechanism.

51-71: LGTM!

The CSS styles of the component enhance the user experience:

  • Using CSS modules is a good way to scope the styles to the component.
  • The slidetounlock animation provides a nice visual effect to engage the user.
  • Applying the animation to the .content class is a good way to reuse it across the component.
  • Setting the text fill color to white for the .success class provides good contrast and visual feedback.
packages/effects/common-ui/src/components/verify/use-event-listener.ts (3)

6-6: LGTM!

The RemoveEventFn type alias is appropriately named and has the correct signature for a function that removes an event listener.


7-15: LGTM!

The UseEventParams interface is well-defined and provides a clear contract for the parameters of the useEventListener function. The property names are descriptive, and the types are appropriate. The interface allows for flexibility and type safety in configuring the event listener.


16-61: Excellent work on the useEventListener function!

The function is well-structured and makes effective use of Vue's composition API and reactivity system to manage the event listener. Here are some highlights:

  • The function is flexible and accepts various types for the target element, including a ref to an element.
  • The use of watch ensures that the event listener is properly added and removed based on the lifecycle of the component and changes to the target element.
  • The debounce and throttle options, using useDebounceFn and useThrottleFn from @vueuse/core, help optimize performance by limiting the frequency of the listener's execution.
  • The removeEvent method returned by the function allows for manual cleanup of the event listener, providing flexibility and control to the developer.

Overall, this function is a valuable addition to the codebase, providing a reusable and efficient way to manage event listeners in Vue components.

packages/effects/common-ui/src/components/verify/props.ts (4)

1-2: LGTM!

The import statement is correct and necessary for defining the style properties in the interfaces.


3-68: Great work defining the VerifyProps interface!

The interface is well-structured, covering the necessary properties for a verification component. The JSDoc comments provide clear documentation for each property, making it easy to understand their purpose and default values. The use of optional properties allows for flexibility in customizing the component.


70-105: The RotateProps interface is well-defined!

Extending the VerifyProps interface is a good approach to inherit its properties and add rotation-specific ones. The additional properties are relevant to the rotating verification component, and the JSDoc comments provide clear documentation for each property.


107-133: The default property functions are a nice touch!

Defining defaultDragVerifyProps and defaultRotateVerifyProps functions provides a structured way to initialize the properties with sensible defaults. Using object spread syntax in defaultRotateVerifyProps is a good practice to avoid duplication and ensure consistency with defaultDragVerifyProps. These functions enhance the usability of the verification components by providing default values.

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

106-114: LGTM!

The addition of the "verify" section to the Chinese localization file is a great enhancement. It provides localized titles for the drag and rotate verification components, improving the user experience for Chinese-speaking users.

The new structure also allows for better organization of verification-related text, making it easier to maintain and extend in the future.

playground/src/views/examples/verify/drag-verify/index.vue (5)

1-30: LGTM!

The code segment correctly imports the necessary dependencies and components. The event handlers and template refs are properly defined and typed.


32-41: LGTM!

The code segment correctly structures the components and sets up the necessary bindings for the DragVerify and Button components.


42-60: LGTM!

The code segment is structurally similar to the previous one and correctly sets up the bindings for the DragVerify and Button components. The circle prop is used to enable the circular mode for the DragVerify component.


61-71: LGTM!

The code segment demonstrates the usage of custom props and a scoped slot for the DragVerify component. The bar-style, success-text, and text props are used to customize the appearance and text of the component. The actionIcon scoped slot allows for dynamic rendering of icons based on the verification state. The bindings for the DragVerify and Button components are correctly set up.


72-91: LGTM!

The code segment showcases the usage of a scoped slot for the DragVerify component to customize the displayed text and icons based on the verification state. The text scoped slot conditionally renders different content using v-if and v-else directives. The bindings for the DragVerify and Button components are correctly set up.

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

107-114: LGTM!

The added "verify" section in the localization file is structured correctly and provides the necessary translations for the "drag-verify" and "rotate-verify" components.

playground/src/router/routes/modules/examples.ts (1)

112-139: LGTM!

The new routes for verification examples are correctly defined and follow the existing routing structure. The changes include:

  • A new parent route VerifyExample with the path /examples/verify.
  • Two child routes DragVerifyExample and RotateVerifyExample with their respective paths and components.
  • Dynamic imports for the child route components, which helps with performance.
  • Localized titles in the route metadata, enhancing the user experience for different languages.

The code changes are well-structured and adhere to the project's conventions. Great job!

packages/effects/common-ui/src/components/verify/rotate-verify/index.vue (1)

11-14: Verify the use of 'withDefaults' with 'defaultRotateVerifyProps'

The defaultRotateVerifyProps is being called as a function within withDefaults:

const props = withDefaults(
  defineProps<RotateProps>(),
  defaultRotateVerifyProps(),
);

Ensure that defaultRotateVerifyProps returns an object of default values as expected. If defaultRotateVerifyProps is an object, you should omit the parentheses:

const props = withDefaults(
  defineProps<RotateProps>(),
-  defaultRotateVerifyProps(),
+  defaultRotateVerifyProps,
);

Run the following script to check whether defaultRotateVerifyProps is an object or a function:

Verification successful

Usage of 'defaultRotateVerifyProps' is correct

The current implementation of withDefaults with defaultRotateVerifyProps is correct:

const props = withDefaults(
  defineProps<RotateProps>(),
  defaultRotateVerifyProps(),
);

defaultRotateVerifyProps is defined as a function that returns an object of default values. It's correctly being called within withDefaults. The parentheses are necessary because it's a function that needs to be executed to get the default values object.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find the definition of 'defaultRotateVerifyProps'

# Search for the export of 'defaultRotateVerifyProps' in the codebase
rg --type=typescript 'export (const|function) defaultRotateVerifyProps' -A 5

Length of output: 113


Script:

#!/bin/bash
# Description: Find the definition of 'defaultRotateVerifyProps'

# Find all .vue, .ts, and .tsx files
files=$(fd -e vue -e ts -e tsx)

# Search for 'defaultRotateVerifyProps' in these files
echo "$files" | xargs rg 'export (const|function|let) defaultRotateVerifyProps' -A 5

Length of output: 108327

packages/effects/common-ui/src/components/verify/drag-verify/index.vue (1)

226-231: Props Validation for Child Components

When passing props like contentStyle, height, isPassing, etc., to ContentCmp, ensure that these props are properly defined and typed in the child component to prevent runtime errors.

Run the following script to check if ContentCmp accepts these props:

Verification successful

Props Validation for ContentCmp Confirmed

The ContentCmp component (content.vue) correctly defines and types all the props mentioned in the review comment. The file packages/effects/common-ui/src/components/verify/drag-verify/content.vue contains the following prop definitions:

  • contentStyle: CSSProperties
  • height: number | string
  • isPassing: boolean
  • successText: string
  • text: string
  • width: number | string

These definitions ensure proper prop validation, addressing the concern raised in the review comment.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that ContentCmp defines the expected props.
# Expected result: ContentCmp should define 'contentStyle', 'height', 'isPassing', 'successText', 'text', and 'width' props.

# Using ast-grep to search for prop definitions in content.vue
ast-grep --lang vue --pattern $'<script>
export default {
  props: {
    contentStyle: $_,
    height: $_,
    isPassing: $_,
    successText: $_,
    text: $_,
    width: $_,
  }
}
</script>' $(fd content.vue)

Length of output: 2009


Script:

#!/bin/bash
# Description: Display the contents of content.vue and search for prop definitions
# Expected result: Show the prop definitions for ContentCmp

cat packages/effects/common-ui/src/components/verify/drag-verify/content.vue | grep -A 20 "props:" | grep -v "^--$"

Length of output: 115


Script:

#!/bin/bash
# Description: Check if content.vue exists and display its contents or search for it
# Expected result: Either show the file contents or find similar files

# Check if the file exists
if ls packages/effects/common-ui/src/components/verify/drag-verify/content.vue &> /dev/null; then
    echo "File exists. Displaying contents:"
    cat packages/effects/common-ui/src/components/verify/drag-verify/content.vue
else
    echo "File not found. Searching for similar files:"
    fd -t f content.vue packages/effects/common-ui/src/components/verify/drag-verify
fi

Length of output: 1547

@anncwb anncwb requested a review from a team as a code owner September 21, 2024 07:07
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

Outside diff range and nitpick comments (1)
docs/src/friend-links/index.md (1)

12-12: Address Markdownlint suggestions.

Please consider the following improvements based on the Markdownlint suggestions:

  1. Add alternate text for the WeChat image to improve accessibility. For example:

    - <img src="https://unpkg.com/@vbenjs/static-source@0.1.7/source/wechat.jpg" style="width: 300px;"/>
    + <img src="https://unpkg.com/@vbenjs/static-source@0.1.7/source/wechat.jpg" alt="WeChat QR code" style="width: 300px;"/>
  2. Wrap the logo image URL in angle brackets to avoid a bare URL. For example:

    - Logo:https://unpkg.com/@vbenjs/static-source@0.1.7/source/logo-v1.webp
    + Logo:<https://unpkg.com/@vbenjs/static-source@0.1.7/source/logo-v1.webp>

Also applies to: 25-25

Tools
Markdownlint

12-12: null
Images should have alternate text (alt text)

(MD045, no-alt-text)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6a746dc and d6b2bf8.

Files ignored due to path filters (2)
  • packages/@core/preferences/__tests__/__snapshots__/config.test.ts.snap is excluded by !**/*.snap
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing (22)
  • README.ja-JP.md (2 hunks)
  • README.md (2 hunks)
  • README.zh-CN.md (2 hunks)
  • docs/.vitepress/config/shared.mts (2 hunks)
  • docs/src/commercial/community.md (1 hunks)
  • docs/src/commercial/customized.md (1 hunks)
  • docs/src/en/guide/essentials/settings.md (2 hunks)
  • docs/src/en/index.md (1 hunks)
  • docs/src/friend-links/index.md (2 hunks)
  • docs/src/guide/essentials/settings.md (2 hunks)
  • docs/src/index.md (1 hunks)
  • docs/src/sponsor/personal.md (1 hunks)
  • internal/vite-config/src/options.ts (1 hunks)
  • packages/@core/base/shared/src/constants/vben.ts (1 hunks)
  • packages/@core/preferences/src/config.ts (2 hunks)
  • packages/effects/common-ui/src/components/captcha/index.ts (1 hunks)
  • packages/effects/common-ui/src/components/captcha/point-selection-captcha-card.vue (2 hunks)
  • packages/effects/common-ui/src/components/captcha/point-selection-captcha.vue (1 hunks)
  • packages/effects/common-ui/src/components/captcha/types.ts (3 hunks)
  • packages/effects/common-ui/src/components/verify/drag-verify/index.vue (1 hunks)
  • playground/src/views/examples/captcha/base64.ts (0 hunks)
  • playground/src/views/examples/captcha/index.vue (1 hunks)
Files not reviewed due to no reviewable changes (1)
  • playground/src/views/examples/captcha/base64.ts
Files skipped from review due to trivial changes (6)
  • README.ja-JP.md
  • README.md
  • README.zh-CN.md
  • docs/src/en/index.md
  • docs/src/index.md
  • packages/@core/base/shared/src/constants/vben.ts
Files skipped from review as they are similar to previous changes (1)
  • packages/effects/common-ui/src/components/verify/drag-verify/index.vue
Additional context used
Markdownlint
docs/src/commercial/community.md

27-27: null
Images should have alternate text (alt text)

(MD045, no-alt-text)

docs/src/commercial/customized.md

10-10: null
Images should have alternate text (alt text)

(MD045, no-alt-text)

docs/src/friend-links/index.md

12-12: null
Images should have alternate text (alt text)

(MD045, no-alt-text)


25-25: null
Bare URL used

(MD034, no-bare-urls)

docs/src/sponsor/personal.md

5-5: null
Images should have alternate text (alt text)

(MD045, no-alt-text)

Additional comments not posted (23)
packages/effects/common-ui/src/components/captcha/index.ts (1)

2-2: Verify the usage of the new PointSelectionCaptchaCard component.

The addition of the new export for PointSelectionCaptchaCard looks good. However, it's important to ensure that this new component is being used correctly throughout the codebase.

Run the following script to verify the component usage:

docs/src/friend-links/index.md (1)

12-12: LGTM!

The changes to update the image source URLs from version 0.1.6 to 0.1.7 are reasonable and do not affect the functionality of the document.

Also applies to: 25-25

Tools
Markdownlint

12-12: null
Images should have alternate text (alt text)

(MD045, no-alt-text)

internal/vite-config/src/options.ts (2)

14-14: LGTM!

The update to the static source version for the PWA icon looks good.


19-19: LGTM!

The update to the static source version for the PWA icon looks good.

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

Line range hint 53-64: LGTM!

The PointSelectionCaptchaProps interface correctly extends the renamed PointSelectionCaptchaCardProps interface and defines additional props specific to the point selection captcha. The properties are well-documented with JSDoc comments.


Line range hint 21-52: Verify the usage of the renamed interface.

The renaming of the interface from CaptchaCardProps to PointSelectionCaptchaCardProps aligns with the focus on point selection functionality and provides better clarity. The properties defined in the interface are well-documented with JSDoc comments.

Ensure that all references to the old interface name CaptchaCardProps have been updated to use the new name PointSelectionCaptchaCardProps throughout the codebase.

Run the following script to verify the usage of the renamed interface:

Verification successful

Renaming verified: No issues found

The interface has been successfully renamed from CaptchaCardProps to PointSelectionCaptchaCardProps. All occurrences in the codebase are using the new name correctly. The search results showing CaptchaCardProps are part of the new interface name or in lines extending it, which is expected.

  • File: packages/effects/common-ui/src/components/captcha/types.ts
    • The interface is defined as PointSelectionCaptchaCardProps
    • Other interfaces correctly extend PointSelectionCaptchaCardProps
    • Even commented-out code uses the new name

No further action is required regarding the interface renaming.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all references to the old interface name have been updated.

# Test: Search for the old interface name. Expect: No occurrences.
rg --type typescript $'CaptchaCardProps'

Length of output: 74


Script:

#!/bin/bash
# Description: Verify the usage of the renamed interface

# Search for any remaining occurrences of the old interface name
echo "Searching for CaptchaCardProps:"
rg --type-add 'ts:*.{ts,tsx}' --type ts 'CaptchaCardProps'

echo -e "\nSearching for PointSelectionCaptchaCardProps:"
rg --type-add 'ts:*.{ts,tsx}' --type ts 'PointSelectionCaptchaCardProps'

Length of output: 1009

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

2-2: LGTM!

The import statement has been updated to use a more specific props type PointSelectionCaptchaCardProps, which aligns with the component's purpose. The change is localized and does not introduce any apparent issues.


17-17: LGTM!

The withDefaults function has been updated to use the PointSelectionCaptchaCardProps type when defining the component's props. This change is consistent with the updated import statement and does not introduce any apparent issues.

packages/@core/preferences/src/config.ts (2)

13-13: Verify compatibility of the updated static asset version.

The defaultAvatar URL has been updated to use a newer version of the static asset. Please ensure that the updated version (0.1.7) is compatible and does not introduce any breaking changes.


52-52: Verify compatibility of the updated static asset version.

The logo.source URL has been updated to use a newer version of the static asset. Please ensure that the updated version (0.1.7) is compatible and does not introduce any breaking changes.

docs/.vitepress/config/shared.mts (3)

35-35: LGTM!

The logo URL has been updated to the latest version (0.1.7) of the static source. This change ensures that the most recent logo is used in the application.


141-141: LGTM!

The URL for the 192x192 PWA icon has been updated to the latest version (0.1.7) of the static source. This change ensures that the most recent PWA icon is used when the application is installed as a PWA.


146-146: LGTM!

The URL for the 512x512 PWA icon has been updated to the latest version (0.1.7) of the static source. This change ensures that the most recent PWA icon is used when the application is installed as a PWA.

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

9-9: LGTM!

The import statement update for CaptchaCard is consistent with the component renaming mentioned in the list of alterations. The new name point-selection-captcha-card.vue is more descriptive and improves code readability.

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

12-13: LGTM!

Assigning the default captcha image URL to a constant with a meaningful name improves code readability. Using an external URL for the default image is a good practice to avoid bloating the codebase. Specifying the package version in the URL ensures consistency across environments.


15-16: LGTM!

Assigning the default hint image URL to a constant with a meaningful name improves code readability. Using an external URL for the default image is a good practice to avoid bloating the codebase. Specifying the package version in the URL ensures consistency across environments.


20-21: LGTM!

Initializing captchaImage as an empty string and captchaImageUrl with the default URL aligns with the removal of the imported base64 encoded image. This ensures that a fallback image is always available while allowing for the possibility of populating captchaImage with a base64 encoded image later if needed.


23-24: LGTM!

Initializing hintImage as an empty string and hintImageUrl with the default URL aligns with the removal of the imported base64 encoded image. This ensures that a fallback image is always available while allowing for the possibility of populating hintImage with a base64 encoded image later if needed.


29-29: LGTM!

Initializing showHintImage as false aligns with the initialization of hintImageUrl with a default URL. This ensures that the hint image is hidden by default, providing a cleaner user interface.

docs/src/guide/essentials/settings.md (2)

188-188: LGTM!

The defaultAvatar URL has been correctly updated to reference version 0.1.7 of the @vbenjs/static-source package.


227-227: LGTM!

The logo.source URL has been correctly updated to reference version 0.1.7 of the @vbenjs/static-source package.

docs/src/en/guide/essentials/settings.md (2)

166-166: LGTM!

The avatar URL has been updated to use a newer version of the @vbenjs/static-source package. This change looks good.


205-205: LGTM!

The logo URL has been updated to use a newer version of the @vbenjs/static-source package, consistent with the avatar URL update. This change looks good.

packages/effects/common-ui/src/components/captcha/index.ts Outdated Show resolved Hide resolved
@anncwb anncwb added the feature label Sep 21, 2024
@anncwb anncwb merged commit 000172e into main Sep 21, 2024
14 checks passed
@anncwb anncwb deleted the wangjue-verify-comp branch September 21, 2024 12:52
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: 9

Outside diff range and nitpick comments (7)
packages/effects/common-ui/src/components/captcha/slider-captcha/slider-captcha-action.vue (3)

26-30: Consider extracting the magic number 10 into a constant

Using the literal value 10 directly in your computation can reduce code clarity. Extracting it into a named constant like DRAG_THRESHOLD enhances readability and makes future adjustments easier.

Apply this diff:

+const DRAG_THRESHOLD = 10;

 const isDragging = computed(() => {
-  const currentLeft = Number.parseInt(left.value as string);
+  const currentLeft = Number.parseInt(left.value);

-  return currentLeft > 10 && !props.isPassing;
+  return currentLeft > DRAG_THRESHOLD && !props.isPassing;
 });

49-49: transition-width may not be a valid Tailwind CSS class

The class transition-width is not a standard utility in Tailwind CSS. To apply a transition to the width property, you can use transition-[width] or define a custom utility class if necessary.

Apply this diff:

       'transition-width !left-0 duration-300': toLeft,
+      'transition-[width] !left-0 duration-300': toLeft,

55-55: size-4 is not a valid Tailwind CSS class

The class size-4 is not a recognized Tailwind CSS utility. If you're aiming to set the font size, consider using a class like text-4xl or another appropriate font size utility.

Apply this diff:

-    <Slot :is-passing="isPassing" class="text-foreground/60 size-4">
+    <Slot :is-passing="isPassing" class="text-foreground/60 text-4xl">
packages/effects/common-ui/src/components/captcha/slider-rotate-captcha/index.vue (1)

118-118: Review redundant assignment of state.showTip = true

At line 118, state.showTip is set to true immediately after it has already been set to true at line 112 within the useTimeoutFn callback. This may be redundant and could be removed to simplify the logic.

packages/effects/common-ui/src/components/captcha/slider-captcha/index.vue (3)

175-192: Avoid magic numbers by defining constants for timeouts

The timeout duration in useTimeoutFn is a magic number. Define a constant for better readability and maintainability.

Apply this diff to define a timeout constant:

+ const RESET_TIMEOUT = 300;
  function resume() {
    // ...existing code...
    useTimeoutFn(() => {
      state.toLeft = false;
      actionEl.setLeft('0');
      barEl.setWidth('0');
-   }, 300);
+   }, RESET_TIMEOUT);
  }

98-103: Optimize dimension calculations by caching values

The getOffset function recalculates dimensions every time it's called. If these dimensions don't change during the component's lifecycle, consider caching them to improve performance.


47-49: Document exposed methods for clarity

You are exposing the resume method using defineExpose, but there's no documentation explaining its purpose. Adding JSDoc comments or inline comments enhances maintainability.

Example:

defineExpose({
+ /**
+  * Resets the captcha component to its initial state.
+  */
  resume,
});
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d6b2bf8 and 9e8fc76.

Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing (20)
  • packages/@core/ui-kit/shadcn-ui/src/components/spine-text/spine-text.vue (2 hunks)
  • packages/effects/common-ui/package.json (1 hunks)
  • packages/effects/common-ui/src/components/captcha/index.ts (1 hunks)
  • packages/effects/common-ui/src/components/captcha/point-selection-captcha/index.vue (3 hunks)
  • packages/effects/common-ui/src/components/captcha/point-selection-captcha/point-selection-captcha-card.vue (5 hunks)
  • packages/effects/common-ui/src/components/captcha/slider-captcha/index.vue (1 hunks)
  • packages/effects/common-ui/src/components/captcha/slider-captcha/slider-captcha-action.vue (1 hunks)
  • packages/effects/common-ui/src/components/captcha/slider-captcha/slider-captcha-bar.vue (1 hunks)
  • packages/effects/common-ui/src/components/captcha/slider-captcha/slider-captcha-content.vue (1 hunks)
  • packages/effects/common-ui/src/components/captcha/slider-rotate-captcha/index.vue (1 hunks)
  • packages/effects/common-ui/src/components/captcha/types.ts (4 hunks)
  • packages/effects/common-ui/src/components/captcha/utils.ts (0 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/router/routes/modules/examples.ts (2 hunks)
  • playground/src/views/examples/captcha/point-selection-captcha.vue (1 hunks)
  • playground/src/views/examples/captcha/slider-captcha.vue (1 hunks)
  • playground/src/views/examples/captcha/slider-rotate-captcha.vue (1 hunks)
Files not reviewed due to no reviewable changes (1)
  • packages/effects/common-ui/src/components/captcha/utils.ts
Files skipped from review as they are similar to previous changes (2)
  • playground/src/locales/langs/en-US.json
  • playground/src/locales/langs/zh-CN.json
Additional comments not posted (51)
packages/effects/common-ui/src/components/captcha/index.ts (5)

4-4: LGTM!

The addition of the SliderCaptcha export is correct. It points to the entry point of the new slider captcha component.


5-5: LGTM!

The addition of the SliderRotateCaptcha export is correct. It points to the entry point of the new slider rotate captcha component.


6-6: Skipped reviewing the unchanged type exports.

The type exports from the types module remain unchanged, so no review is necessary.


2-2: Verify that all usages of the removed CaptchaCard component have been updated to use PointSelectionCaptchaCard.

The addition of the PointSelectionCaptchaCard export is correct. Please ensure that all instances in the codebase that were importing and using the removed CaptchaCard component have been updated to use PointSelectionCaptchaCard.

Run the following script to verify that CaptchaCard is no longer being used:

#!/bin/bash
# Description: Verify that `CaptchaCard` is no longer being used in the codebase.

# Find all .vue, .js, and .ts files, then search for CaptchaCard
fd -e vue -e js -e ts | xargs rg -i "captchacard" -A 5

# Specifically search for import statements
fd -e vue -e js -e ts | xargs rg -i "import.*captchacard" -A 5

# Search for component usage in template sections of .vue files
fd -e vue | xargs rg -i "<captchacard" -A 5

1-1: Verify the import statements for PointSelectionCaptcha.

The export path for PointSelectionCaptcha has been updated correctly. Please ensure that all import statements referencing this component have been updated to use the new path.

Run the following script to verify the import statements:

Verification successful

Verification successful: Import statements and exports are correct.

The changes to the PointSelectionCaptcha component have been correctly implemented. The new export path is being used in the index.ts file, and no instances of the old import path were found. The playground is correctly importing the component from the package alias.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that all import statements for `PointSelectionCaptcha` use the new path.

# Test: Search for the import statements. Expect: Only occurrences of the new path.
rg --type typescript -A 5 $'import.*PointSelectionCaptcha'

Length of output: 7569


Script:

#!/bin/bash
# Description: Verify imports of PointSelectionCaptcha and check for any remaining old imports

# Check for imports of PointSelectionCaptcha
rg --type typescript --type vue 'import.*PointSelectionCaptcha' -A 5

# Check for any remaining imports using the old path
rg --type typescript --type vue 'from.*components/captcha/point-selection-captcha\.vue'

# Check the playground file specifically
cat playground/src/views/examples/captcha/point-selection-captcha.vue | head -n 20

Length of output: 925


Script:

#!/bin/bash
# Description: Verify imports of PointSelectionCaptcha and check for any remaining old imports

# Check for imports of PointSelectionCaptcha
fd -e ts -e vue | xargs grep -n "import.*PointSelectionCaptcha"

# Check for any remaining imports using the old path
fd -e ts -e vue | xargs grep -n "from.*components/captcha/point-selection-captcha\.vue"

# Check the contents of the index.ts file
cat packages/effects/common-ui/src/components/captcha/index.ts

Length of output: 1050

packages/effects/common-ui/src/components/captcha/slider-captcha/slider-captcha-bar.vue (3)

1-10: LGTM!

The code segment correctly sets up the necessary imports, props, and template ref for the component. The barStyle and toLeft props provide flexibility in customizing the bar's appearance and behavior. The barRef template ref will be useful for accessing the bar element.


11-28: LGTM!

The code segment effectively manages the bar's width using a reactive width ref and a computed style property. Exposing the getEl and setWidth methods via defineExpose provides a clean interface for the parent component to interact with the bar.


31-38: LGTM!

The template correctly renders the bar element with the necessary ref, dynamic class binding, and style binding. The toLeft prop is used to conditionally apply transition classes, allowing for a smooth visual effect. The static classes ensure the bar has the desired appearance and positioning.

playground/src/views/examples/captcha/slider-rotate-captcha.vue (2)

1-28: LGTM! The component structure and implementation look good.

The component follows Vue 3 composition API conventions and is well-structured. The imports are properly organized and scoped. The useUserStore composable is used effectively to access the user's avatar. The template markup is clean and properly structured, using Ant Design Vue's Card component for the captcha container. The component is appropriately wrapped inside a Page component for consistent layout across examples.


23-25: Verify the SliderRotateCaptcha component usage and @success event handling.

The SliderRotateCaptcha component is used correctly, with the user's avatar passed as the src prop. The @success event is properly handled by the handleSuccess method, which displays a success message using message.success.

To further verify the SliderRotateCaptcha component usage and @success event handling, you can check the following:

  1. Ensure that the SliderRotateCaptcha component is properly exported from the @vben/common-ui library.
  2. Verify that the @success event is emitted by the SliderRotateCaptcha component when the captcha is successfully completed.
  3. Confirm that the message.success method from Ant Design Vue is properly imported and used to display the success message.

Here's a script to help with the verification:

If the above checks pass, it confirms that the SliderRotateCaptcha component is being used correctly and the @success event is properly handled.

Verification successful

Verification successful: SliderRotateCaptcha usage and @success event handling are correct

The verification process confirms that the SliderRotateCaptcha component is used correctly, and the @success event is properly handled. Specifically:

  • SliderRotateCaptcha is correctly imported from '@vben/common-ui'.
  • The @success event is properly bound to the handleSuccess method in the template.
  • The handleSuccess method is implemented and uses message.success to display a success message.
  • The message is correctly imported from 'ant-design-vue'.
  • The src prop is correctly set using the computed avatar property.

No issues were found, and the implementation aligns with the expected behavior.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash

# Check if SliderRotateCaptcha is exported from @vben/common-ui
ast-grep --lang typescript --pattern $'export { SliderRotateCaptcha }'

# Check if the @success event is emitted by SliderRotateCaptcha
ast-grep --lang vue --pattern $'export default {
  $$$
  emits: ["success"],
  $$$
}'

# Check if message.success is imported from ant-design-vue
rg --type typescript $'import { message } from \'ant-design-vue\';'

Length of output: 471


Script:

#!/bin/bash

# Check if SliderRotateCaptcha is exported from any JS/TS file
rg --type-add 'ts:*.{ts,tsx}' --type ts 'export.*SliderRotateCaptcha'

# Check if the @success event is used in Vue files
rg --type vue '@success'

# Check if message.success is imported from ant-design-vue
rg --type-add 'ts:*.{ts,tsx}' --type ts 'import.*message.*from.*ant-design-vue'

# Check for the handleSuccess method in the current file
rg --type vue 'handleSuccess' playground/src/views/examples/captcha/slider-rotate-captcha.vue

Length of output: 872


Script:

#!/bin/bash

# Check for @success event and handleSuccess method in the specific Vue file
rg '@success|handleSuccess' playground/src/views/examples/captcha/slider-rotate-captcha.vue

# Check for message import in the specific Vue file
rg "import.*message.*from 'ant-design-vue'" playground/src/views/examples/captcha/slider-rotate-captcha.vue

# Check for SliderRotateCaptcha import in the specific Vue file
rg "import.*SliderRotateCaptcha" playground/src/views/examples/captcha/slider-rotate-captcha.vue

# Display the content of the Vue file for manual inspection
cat playground/src/views/examples/captcha/slider-rotate-captcha.vue

Length of output: 1335

packages/effects/common-ui/package.json (1)

26-26: Dependencies added to enhance project capabilities

The addition of the @vben-core/shared and @vueuse/core dependencies is a positive change that can improve the project's functionality and maintainability.

  • @vben-core/shared: This local workspace dependency likely contains shared utilities, constants, and components specific to the project. Utilizing a shared library can promote code reuse, consistency, and efficiency across the project.

  • @vueuse/core: This package is a collection of essential Vue Composition API utilities that can enhance the capabilities of the application. It provides a wide range of useful composables and utilities that can simplify common tasks and improve the developer experience.

By leveraging these dependencies, the project can benefit from well-tested and optimized code, reducing duplication and increasing productivity.

Also applies to: 31-31

packages/@core/ui-kit/shadcn-ui/src/components/spine-text/spine-text.vue (3)

1-17: LGTM!

The introduction of the <script> section using TypeScript and the Composition API aligns with Vue 3 best practices. The props are correctly typed and have appropriate default values. The computed property style correctly constructs the animation CSS property based on the prop values. The code segment looks good and is ready to be merged.


19-19: LGTM!

The computed style is correctly bound to the div element using the :style directive. The code segment looks good and is ready to be merged.


29-30: LGTM!

The previous animation declaration is correctly commented out, as it is now handled by the computed style in the <script> section. The code segment looks good and is ready to be merged.

packages/effects/common-ui/src/components/captcha/slider-captcha/slider-captcha-content.vue (4)

1-13: LGTM!

The script setup section is implemented correctly. The component props are defined with their types, and the necessary imports are in place.


14-22: LGTM!

The template ref and computed property are implemented correctly. The template ref is used to get a reference to the content div element, and the computed property is used to compute the style of the content div element based on the contentStyle prop.


24-29: LGTM!

The getEl method is exposed correctly using the defineExpose function. The method returns the value of the contentRef template ref, which is the content div element.


31-52: LGTM!

The template section is implemented correctly. The div element is bound to the contentRef template ref, has dynamic class and style bindings, and displays the success text or the regular text based on the isPassing prop. The slot allows customizing the text content, and the style section defines a CSS module class for the success state.

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

2-2: LGTM!

The import statement update aligns with the type change mentioned in the summary. The new type name PointSelectionCaptchaCardProps is more descriptive and specific to the component.


Line range hint 15-22: Props definition looks good!

The props constant is properly defined using withDefaults and the PointSelectionCaptchaCardProps type. The default values for the props are reasonable and provide flexibility for customization.


27-33: The parseValue function is a nice addition!

The parseValue function provides a safe and convenient way to convert values from either number or string types to a numeric format. It handles invalid number strings gracefully by returning 0. This function can be useful for parsing prop values that are expected to be numbers but may be passed as strings.


56-56: Localization key update looks good!

The change in the localization key from captcha.title to ui.captcha.title aligns with the reorganization mentioned in the summary. Using a more structured key improves the organization and readability of localization keys. This change seems to be a part of a larger localization refactoring effort.

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

Line range hint 23-47: LGTM!

The PointSelectionCaptchaCardProps interface is well-defined with descriptive property names, clear descriptions, and reasonable default values.


Line range hint 55-70: LGTM!

The PointSelectionCaptchaProps interface extends the PointSelectionCaptchaCardProps interface and adds well-defined properties specific to a point selection captcha component.


119-158: LGTM!

The SliderRotateCaptchaProps interface is well-defined with descriptive property names, clear descriptions, and reasonable default values for configuring a slider rotate captcha component.


160-173: LGTM!

The CaptchaVerifyPassingData, SliderCaptchaActionType, and SliderRotateVerifyPassingData interfaces are well-defined with descriptive property names and appropriate types for representing captcha verification-related data and actions.

playground/src/views/examples/captcha/slider-captcha.vue (6)

1-30: LGTM!

The code segment has the following positive aspects:

  • Imports are relevant and there are no unused imports.
  • Event handlers have clear names and implementations.
  • Reactive references are typed correctly and follow a consistent naming pattern.

32-41: LGTM!

The code segment has the following positive aspects:

  • Clear structure following the Vue template syntax.
  • SliderCaptcha component is bound to the el1 ref for resetting.
  • Success event is handled by the handleSuccess method.
  • Reset button click is handled by the handleBtnClick method.

42-53: LGTM!

The code segment has the following positive aspects:

  • Similar structure to the previous code segment.
  • SliderCaptcha component is bound to the el2 ref for resetting.
  • Custom class "rounded-full" is applied to the SliderCaptcha component for rounded corners styling.

54-69: LGTM!

The code segment has the following positive aspects:

  • Similar structure to the previous code segments.
  • SliderCaptcha component is bound to the el3 ref for resetting.
  • Custom props are passed to the SliderCaptcha component for background color, success text, and default text.

70-82: LGTM!

The code segment has the following positive aspects:

  • Similar structure to the previous code segments.
  • SliderCaptcha component is bound to the el4 ref for resetting.
  • actionIcon slot is used to customize the drag icon based on the captcha state.

83-116: LGTM!

The code segment has the following positive aspects:

  • Similar structure to the previous code segments.
  • SliderCaptcha components are bound to the el5 ref for resetting.
  • Custom props and slots are used to customize the text content of the captcha.
packages/effects/common-ui/src/components/captcha/point-selection-captcha/index.vue (3)

2-2: LGTM!

The import path change for PointSelectionCaptchaProps and CaptchaPoint types is a good refactor to improve code organization.


8-9: LGTM!

The import path changes for useCaptchaPoints hook and CaptchaCard component are good refactors to improve code organization and naming.


Line range hint 124-171: LGTM!

The localization key changes to use the ui.captcha namespace are a good refactor to improve the localization structure and maintainability. The changes are consistent across all the affected UI elements.

playground/src/router/routes/modules/examples.ts (4)

104-140: LGTM!

The new CaptchaExample parent route and its child routes are correctly configured. The route paths, components, and metadata look good.


113-120: LGTM!

The DragVerifyExample child route is correctly configured with the path, component, and metadata.


122-129: LGTM!

The RotateVerifyExample child route is correctly configured with the path, component, and metadata.


131-138: LGTM!

The CaptchaPointSelectionExample child route is correctly configured with the path, component, and metadata.

playground/src/views/examples/captcha/point-selection-captcha.vue (5)

12-13: LGTM!

The constant definition and the URL value for the default captcha image look good.


15-16: LGTM!

The constant definition and the URL value for the default hint image look good.


20-21: LGTM!

The initializations of the captchaImage and captchaImageUrl properties in the params object look good. The empty string for captchaImage suggests dynamic population, while the default URL for captchaImageUrl provides a fallback value.


23-24: LGTM!

The initializations of the hintImage and hintImageUrl properties in the params object look good. The empty string for hintImage suggests dynamic population, while the default URL for hintImageUrl provides a fallback value.


29-29: LGTM!

The initialization of the showHintImage property to false in the params object looks good. This ensures that the hint image is hidden by default.

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

316-330: LGTM!

The changes to the Chinese localization file for the captcha component look good:

  • The new "ui" parent key helps organize the localization file better by grouping UI-related elements together.
  • The additional keys provide more informative messages to enhance the user experience during the captcha verification process.
  • The JSON structure and key naming follow the existing conventions.
packages/locales/src/langs/en-US.json (1)

316-330: LGTM!

The addition of the "ui" object and the restructuring of the captcha-related translations improve the organization and maintainability of the localization file. The new properties provide more informative and context-specific messages, enhancing the user experience of the captcha component.

packages/effects/common-ui/src/components/captcha/slider-rotate-captcha/index.vue (2)

44-44: Verify the use of defineModel

The function defineModel used at line 44 is not a standard Vue Composition API function. Please ensure it is correctly imported or configured, possibly through additional plugins or macros, to prevent potential runtime errors.


30-30: Confirm availability of useTemplateRef

The usage of useTemplateRef at line 30 is not part of the standard Vue Composition API. Verify that this function is available in your project setup, potentially provided by libraries or macros.

packages/effects/common-ui/src/components/captcha/slider-captcha/index.vue (3)

36-36: Verify the compatibility of defineModel with your Vue.js version

The defineModel function is a feature introduced in Vue 3.3. Ensure that your project is using Vue 3.3 or later. If not, consider using the standard v-model approach or update your Vue version to utilize this feature.


115-118: Ensure emitted event payload matches the declared type

The move event is declared to emit SliderRotateVerifyPassingData, but the emitted object contains { event, moveDistance, moveX }. Verify that this object conforms to the SliderRotateVerifyPassingData interface.


165-173: Ensure consistent behavior when props.isSlot is true

In checkPass, when props.isSlot is true, the function calls resume immediately, potentially bypassing the setting of state.isPassing. Confirm that this is the intended behavior and that it doesn't adversely affect the captcha verification flow.

@@ -0,0 +1,62 @@
<script setup lang="ts">
import type { CSSProperties } from 'vue';
import { computed, ref, useTemplateRef } from 'vue';
Copy link
Contributor

Choose a reason for hiding this comment

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

Incorrect usage of useTemplateRef; use ref instead

The function useTemplateRef is not a standard part of the Vue.js framework. To reference a DOM element in the Composition API, you should use ref from 'vue'. This ensures compatibility and correct reactivity within your component.

Apply this diff to fix the issue:

-import { computed, ref, useTemplateRef } from 'vue';
+import { computed, ref } from 'vue';

-const actionRef = useTemplateRef<HTMLDivElement>('actionRef');
+const actionRef = ref<HTMLDivElement | null>(null);

Also applies to: 14-14

const { maxDegree, minDegree } = props;
const ranRotate = Math.floor(
minDegree! + Math.random() * (maxDegree! - minDegree!),
); // 生成随机角度
Copy link
Contributor

Choose a reason for hiding this comment

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

Translate comments to English for consistency

There are comments in the code written in Chinese at lines 98 and 113. To maintain consistency and readability across the codebase, please translate these comments to English.

Also applies to: 113-113

Comment on lines +72 to +79
function getEventPageX(e: MouseEvent | TouchEvent): number {
if (e instanceof MouseEvent) {
return e.pageX;
} else if (e instanceof TouchEvent && e.touches[0]) {
return e.touches[0].pageX;
}
return 0;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Improve event type handling in getEventPageX

Using instanceof TouchEvent can cause issues in environments where TouchEvent is not defined (e.g., some desktop browsers or Node.js during SSR). Consider checking for the existence of touches instead.

Apply this diff to enhance compatibility:

-function getEventPageX(e: MouseEvent | TouchEvent): number {
-  if (e instanceof MouseEvent) {
+function getEventPageX(e: MouseEvent | TouchEvent | any): number {
+  if ('pageX' in e) {
     return e.pageX;
-  } else if (e instanceof TouchEvent && e.touches[0]) {
+  } else if ('touches' in e && e.touches[0]) {
     return e.touches[0].pageX;
   }
   return 0;
 }
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
function getEventPageX(e: MouseEvent | TouchEvent): number {
if (e instanceof MouseEvent) {
return e.pageX;
} else if (e instanceof TouchEvent && e.touches[0]) {
return e.touches[0].pageX;
}
return 0;
}
function getEventPageX(e: MouseEvent | TouchEvent | any): number {
if ('pageX' in e) {
return e.pageX;
} else if ('touches' in e && e.touches[0]) {
return e.touches[0].pageX;
}
return 0;
}

Comment on lines +146 to +148
if (contentEl) {
contentEl.getEl().style.width = `${Number.parseInt(barEl.getEl().style.width)}px`;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Prevent potential NaN assignment in style width

When setting contentEl's width, if barEl.getEl().style.width is empty or invalid, Number.parseInt may return NaN, resulting in NaNpx. Add a fallback to handle such cases.

Apply this diff to ensure default value:

- contentEl.getEl().style.width = `${Number.parseInt(barEl.getEl().style.width)}px`;
+ const barWidth = Number.parseInt(barEl.getEl().style.width) || 0;
+ contentEl.getEl().style.width = `${barWidth}px`;
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 (contentEl) {
contentEl.getEl().style.width = `${Number.parseInt(barEl.getEl().style.width)}px`;
}
if (contentEl) {
const barWidth = Number.parseInt(barEl.getEl().style.width) || 0;
contentEl.getEl().style.width = `${barWidth}px`;
}

Comment on lines +91 to +93
actionRef.value.getStyle().left.replace('px', '') || '0',
10,
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactor to avoid manual parsing of style properties

Manually parsing the left style property by stripping 'px' and using parseInt can be error-prone. Use offsetLeft for a more reliable and cleaner approach.

Apply this diff to simplify the calculation:

- state.moveDistance =
-   getEventPageX(e) -
-   Number.parseInt(
-     actionRef.value.getStyle().left.replace('px', '') || '0',
-     10,
-   );
+ state.moveDistance = getEventPageX(e) - actionRef.value.getEl().offsetLeft;
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
actionRef.value.getStyle().left.replace('px', '') || '0',
10,
);
state.moveDistance = getEventPageX(e) - actionRef.value.getEl().offsetLeft;

Comment on lines +132 to +163
function handleDragOver(e: MouseEvent | TouchEvent) {
const { isMoving, isPassing, moveDistance } = state;
if (isMoving && !isPassing) {
emit('end', e);
const actionEl = actionRef.value;
const barEl = unref(barRef);
if (!actionEl || !barEl) return;
const moveX = getEventPageX(e) - moveDistance;
const { actionWidth, offset, wrapperWidth } = getOffset(actionEl.getEl());
if (moveX < offset) {
if (props.isSlot) {
setTimeout(() => {
if (modelValue.value) {
const contentEl = unref(contentRef);
if (contentEl) {
contentEl.getEl().style.width = `${Number.parseInt(barEl.getEl().style.width)}px`;
}
} else {
resume();
}
}, 0);
} else {
resume();
}
} else {
actionEl.setLeft(`${wrapperWidth - actionWidth + 10}px`);
barEl.setWidth(`${wrapperWidth - actionWidth / 2}px`);
checkPass();
}
state.isMoving = false;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Add null checks to prevent runtime errors

In handleDragOver, ensure that barEl.getEl() and contentEl.getEl() are not null before accessing their properties. This prevents potential runtime errors if the elements are not mounted.

Apply this diff to add null checks:

- if (contentEl) {
+ if (contentEl && barEl && barEl.getEl() && contentEl.getEl()) {
     contentEl.getEl().style.width = `${Number.parseInt(barEl.getEl().style.width) || 0}px`;
   }

Committable suggestion was skipped due to low confidence.

@anncwb anncwb changed the title chore(@vben/common-ui): add verify component feat(@vben/common-ui): add verify component Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants