Skip to content

Conversation

@ming4762
Copy link
Contributor

@ming4762 ming4762 commented Jul 25, 2025

Summary by CodeRabbit

  • New Features
    • Added DingTalk (钉钉) login support, including both QR code and redirect-based authentication options.
    • Introduced a dedicated DingTalk login button with icon and tooltip in the third-party login area.
    • New DingTalk icon added to the icon set.
  • Enhancements
    • Third-party login buttons now display tooltips with localized labels.
    • Application configuration expanded to support DingTalk authentication settings.
  • Localization
    • Added English and Chinese translations for DingTalk and other third-party login options.
  • Chores
    • Updated environment and type definitions to include DingTalk authentication variables.
  • Tests
    • Added tests for the new script loading utility function.

@changeset-bot
Copy link

changeset-bot bot commented Jul 25, 2025

⚠️ No Changeset found

Latest commit: 193f5b6

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 25, 2025

Walkthrough

This change introduces DingTalk (钉钉) login support as a new third-party authentication method. It adds a reusable DingTalk login Vue component, updates configuration, localization, and type definitions, and integrates the new login option into the third-party login UI. Supporting utilities for dynamic script loading and related tests are also included.

Changes

File(s) Change Summary
packages/effects/common-ui/src/ui/authentication/dingding-login.vue New DingTalk login Vue component with QR code and redirect login modes, script loading, and modal UI.
packages/effects/common-ui/src/ui/authentication/third-party-login.vue Integrates DingTalk login, uses app config, adds tooltips to login buttons.
packages/effects/hooks/src/use-app-config.ts Adds extraction and return of DingTalk auth config in app config hook.
packages/types/global.d.ts Adds DingTalk config to type definitions; introduces AuthConfig and updates ApplicationConfig.
playground/.env.development Adds environment variables for DingTalk client and corp IDs.
packages/locales/src/langs/en-US/authentication.json
.../zh-CN/authentication.json
Adds localized labels for DingTalk and other third-party login methods.
packages/icons/src/iconify/index.ts Adds DingTalk icon export.
packages/@core/base/shared/src/utils/resources.ts Adds loadScript utility for dynamic script loading.
packages/@core/base/shared/src/utils/index.ts Re-exports resources utilities.
packages/@core/base/shared/src/utils/__tests__/resources.test.ts Adds tests for loadScript utility, covering loading, errors, and concurrency.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant DingdingLoginComponent
    participant loadScript
    participant DingTalkScript
    participant DingTalkOAuth
    participant Modal

    User->>DingdingLoginComponent: Clicks login button
    alt QR code login
        DingdingLoginComponent->>loadScript: loadScript(dingtalk_url)
        loadScript-->>DingdingLoginComponent: Promise resolved
        DingdingLoginComponent->>DingTalkScript: Initialize QR code widget
        DingTalkScript-->>Modal: Render QR code
        User->>DingTalkScript: Scan QR code
        DingTalkScript-->>DingdingLoginComponent: onSuccess callback
        DingdingLoginComponent->>User: Redirect to DingTalk callback URL
    else Redirect login
        DingdingLoginComponent->>DingTalkOAuth: Redirect to DingTalk OAuth URL
        User->>DingTalkOAuth: Login via DingTalk
        DingTalkOAuth-->>User: Redirects back to app with code
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~18 minutes

Poem

🐇✨
DingTalk hops into our login scene,
With QR codes and scripts so clean.
Configs aligned, icons in tow,
New buttons greet with a friendly glow.
From English to 中文, all strings in place—
Third-party login, a hoppier space!

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this 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

🧹 Nitpick comments (3)
packages/@core/base/shared/src/utils/resources.ts (1)

1-4: Consider using English for JSDoc comments for consistency.

The JSDoc documentation is in Chinese while the codebase appears to use English elsewhere. Consider translating for consistency.

-/**
- * 加载js文件
- * @param src js文件地址
- */
+/**
+ * Load a JavaScript file dynamically
+ * @param src - The URL of the JavaScript file to load
+ * @returns Promise that resolves when the script is loaded
+ */
playground/.env.development (1)

18-20: Environment variables follow correct patterns for DingTalk OAuth.

The new environment variables use the appropriate VITE_GLOB_AUTH_ prefix and will be correctly exposed to the client-side for OAuth flows.

Consider using English placeholder text for consistency:

-# 钉钉登录配置
-VITE_GLOB_AUTH_DINGDING_CLIENT_ID=应用的clientId
-VITE_GLOB_AUTH_DINGDING_CORP_ID=应用的corpId
+# DingTalk login configuration
+VITE_GLOB_AUTH_DINGDING_CLIENT_ID=your_client_id
+VITE_GLOB_AUTH_DINGDING_CORP_ID=your_corp_id
packages/effects/common-ui/src/ui/authentication/dingding-login.vue (1)

107-113: Consider using more specific selectors instead of !important.

The styling correctly removes padding for QR code display, but the !important declaration suggests style conflicts. Consider using more specific selectors for better maintainability.

 .dingding-qrcode-login-modal {
-  .relative {
+  .relative > * {
     padding: 0 !important;
   }
 }

Or investigate if the padding can be controlled through modal props instead.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5b75e5e and 06ffdf1.

📒 Files selected for processing (11)
  • packages/@core/base/shared/src/utils/__tests__/resources.test.ts (1 hunks)
  • packages/@core/base/shared/src/utils/index.ts (1 hunks)
  • packages/@core/base/shared/src/utils/resources.ts (1 hunks)
  • packages/effects/common-ui/src/ui/authentication/dingding-login.vue (1 hunks)
  • packages/effects/common-ui/src/ui/authentication/third-party-login.vue (2 hunks)
  • packages/effects/hooks/src/use-app-config.ts (1 hunks)
  • packages/icons/src/iconify/index.ts (1 hunks)
  • packages/locales/src/langs/en-US/authentication.json (1 hunks)
  • packages/locales/src/langs/zh-CN/authentication.json (1 hunks)
  • packages/types/global.d.ts (1 hunks)
  • playground/.env.development (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
packages/icons/src/iconify/index.ts (1)
packages/@core/base/icons/src/create-icon.ts (1)
  • createIconifyIcon (14-14)
packages/@core/base/shared/src/utils/__tests__/resources.test.ts (1)
packages/@core/base/shared/src/utils/resources.ts (1)
  • loadScript (21-21)
packages/effects/hooks/src/use-app-config.ts (1)
packages/types/global.d.ts (1)
  • ApplicationConfig (23-26)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: Test (windows-latest)
  • GitHub Check: Check (windows-latest)
  • GitHub Check: Check (ubuntu-latest)
  • GitHub Check: Lint (windows-latest)
  • GitHub Check: Lint (ubuntu-latest)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: post-update (windows-latest)
  • GitHub Check: post-update (ubuntu-latest)
🔇 Additional comments (27)
packages/icons/src/iconify/index.ts (1)

15-15: Verify DingTalk icon loading
The RiDingding export points to ri:dingding-fill. Our checks show:

  • SVG endpoint (…/ri:dingding-fill.svg) returns HTTP 200
  • JSON metadata endpoint (…/ri:dingding-fill.json) returns HTTP 404

Please confirm that createIconifyIcon will load the SVG directly (and not rely on the missing JSON metadata) and test in the running app to ensure the DingTalk icon renders correctly.

packages/@core/base/shared/src/utils/resources.ts (1)

5-19: Approve script loading utility – no SSR guard required based on current usage

  • Verified with ripgrep: loadScript is only imported in browser-only Vue components (e.g., dingding-login.vue), with no SSR or Node.js contexts detected.
  • Since this utility isn’t used server-side today, an explicit browser check isn’t necessary. You can add one later if it’s ever consumed in SSR code.
  • All other aspects (duplicate prevention, promise API, error handling, DOM cleanup) look solid—great work!
packages/@core/base/shared/src/utils/index.ts (1)

10-10: LGTM! Export addition follows established patterns.

The new resources module export is correctly placed in alphabetical order and follows the same pattern as other module exports.

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

39-43: Well-structured localization entries for third-party login options.

The new localization keys follow a consistent naming pattern and provide clear, appropriate English labels for the social login buttons.

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

39-43: LGTM! Chinese translations for third-party login options look good.

The new localization keys follow the existing naming conventions and provide appropriate Chinese translations for the third-party login buttons.

packages/types/global.d.ts (3)

12-14: Good addition of DingTalk environment variables to the config interface.

The new properties follow the existing naming convention and are appropriately typed as strings.


16-21: Well-designed AuthConfig interface with good extensibility.

The optional dingding property allows for flexible configuration, and the interface structure makes it easy to add other authentication providers in the future.


25-25: Appropriate integration of auth configuration into ApplicationConfig.

The addition of the auth property maintains consistency with the existing interface structure.

packages/effects/hooks/src/use-app-config.ts (3)

18-22: Clean destructuring of the new DingTalk configuration variables.

The extraction follows the existing pattern and maintains code consistency.


24-27: Good initialization of the auth configuration object.

Starting with an empty auth object provides a clean foundation for conditional configuration additions.


28-33: Excellent conditional logic for DingTalk configuration.

The check ensures that both corpId and clientId are present before adding the DingTalk configuration, preventing incomplete auth setups that could cause runtime issues.

packages/effects/common-ui/src/ui/authentication/third-party-login.vue (5)

2-2: Good integration of the app configuration hook.

Importing useAppConfig allows the component to access DingTalk authentication configuration dynamically.


8-8: Appropriate import of the DingdingLogin component.

The import follows Vue component naming conventions.


14-16: Clean extraction of DingTalk configuration.

The destructuring pattern cleanly extracts the DingTalk auth config for conditional rendering.


30-36: Great UX improvement with localized tooltips.

Adding tooltips with localized text improves user experience by clearly indicating what each login button does.


58-63: Excellent conditional rendering and prop binding.

The v-if directive ensures the DingdingLogin component only renders when configuration is available, and the prop binding correctly passes the required credentials.

packages/@core/base/shared/src/utils/__tests__/resources.test.ts (5)

8-12: Good test setup with proper environment isolation.

The beforeEach hook ensures each test starts with a clean DOM state, preventing test interference.


14-28: Comprehensive test for successful script loading.

The test properly verifies DOM manipulation and promise resolution by simulating the load event.


30-45: Excellent test for duplicate script prevention.

This test ensures the utility doesn't create duplicate script tags, which is crucial for performance and avoiding conflicts.


47-59: Good error handling test with appropriate error message.

The test verifies that loading failures are properly handled and provides meaningful error messages.


61-81: Thorough test for concurrent call handling.

This test ensures the utility handles multiple simultaneous requests for the same script correctly, which is important for real-world usage scenarios.

packages/effects/common-ui/src/ui/authentication/dingding-login.vue (6)

1-9: LGTM! Clean imports and proper Vue 3 setup.

The imports are well-organized and follow proper TypeScript conventions. Good use of Vue 3 composition API with script setup syntax.


11-22: Well-defined Props interface with good documentation.

The TypeScript interface is properly structured with clear property definitions. The Chinese comments provide helpful context for the redirect URI usage.


24-32: Modal configuration is appropriate for QR code display.

The fixed dimensions and callback-based initialization ensure the QR code widget loads properly when the modal opens.


34-40: Good fallback logic for redirect URI.

The function properly handles both explicit redirect URI and automatic fallback to current location.


81-89: URL construction needs parameter consistency check.

The redirect URL construction should use consistent parameter naming. Verify that corpid (line 87) matches DingTalk's API requirements, as the QR code login uses corpId (line 67).

Consider extracting URL construction to a helper function for better maintainability:

+const buildOAuthUrl = () => {
+  const { clientId, corpId } = props;
+  const params = new URLSearchParams({
+    redirect_uri: getRedirectUri(),
+    response_type: 'code',
+    client_id: clientId,
+    scope: 'openid',
+    corpid: corpId, // Verify this parameter name
+    prompt: 'consent'
+  });
+  return `https://login.dingtalk.com/oauth2/auth?${params}`;
+};

 const handleLogin = () => {
   const { isQrCode } = props;
   if (isQrCode) {
     modalApi.open();
   } else {
-    window.location.href = `https://login.dingtalk.com/oauth2/auth?redirect_uri=${encodeURIComponent(getRedirectUri())}&response_type=code&client_id=${clientId}&scope=openid&corpid=${corpId}&prompt=consent`;
+    window.location.href = buildOAuthUrl();
   }
 };

92-105: Clean template structure with proper component usage.

The template follows Vue 3 best practices with appropriate use of Vben UI components. The tooltip configuration and modal integration are well-implemented.

Comment on lines +45 to +79
const handleQrCodeLogin = async () => {
const { clientId, corpId } = props;
if (!(window as any).DTFrameLogin) {
// 二维码登录 加载资源
await loadScript(
'https://g.alicdn.com/dingding/h5-dingtalk-login/0.21.0/ddlogin.js',
);
}
(window as any).DTFrameLogin(
{
id: 'dingding_qrcode_login_element',
width: 300,
height: 300,
},
{
// 注意:redirect_uri 需为完整URL,扫码后钉钉会带code跳转到这里
redirect_uri: encodeURIComponent(getRedirectUri()),
client_id: clientId,
scope: 'openid corpid',
response_type: 'code',
state: '1',
prompt: 'consent',
corpId,
},
(loginResult: any) => {
const { redirectUrl } = loginResult;
// 这里可以直接进行重定向
window.location.href = redirectUrl;
},
(errorMsg: string) => {
// 这里一般需要展示登录失败的具体原因
alert(`Login Error: ${errorMsg}`);
},
);
};
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify parameter consistency and improve error handling.

The QR code login implementation is solid, but there are a few areas for improvement:

  1. Parameter naming inconsistency: Line 67 uses corpId while line 87 uses corpid - ensure consistency with DingTalk API requirements.
  2. Consider adding loading state: Users don't see feedback during script loading.
  3. Error handling: The alert for login errors could be more user-friendly.

🏁 Script executed:

#!/bin/bash
# Verify DingTalk API parameter naming consistency
rg -A 5 -B 5 "corpid|corpId" --type vue

Length of output: 69


🏁 Script executed:

#!/bin/bash
# Search for `corpId` and `corpid` usage across all .vue files to verify naming consistency
rg -n 'corpId|corpid' -g '*.vue'

Length of output: 935


Update DingTalk QR Code Login Implementation

The corpId and corpid usages are correct (camel-case prop for the JS SDK vs. lowercase query param and scope name). Focus on the remaining improvements:

• Remove the parameter-name consistency suggestion—these keys serve different, correct purposes.
• Add a loading indicator/state while ddlogin.js is being fetched.
• Replace the alert in the error callback with a more user-friendly UI message (e.g., inline error banner or toast).

🤖 Prompt for AI Agents
In packages/effects/common-ui/src/ui/authentication/dingding-login.vue between
lines 45 and 79, add a loading state to show a loading indicator while the
ddlogin.js script is being fetched asynchronously. Remove any changes suggesting
renaming corpId or corpid as they are correctly used. Replace the alert in the
error callback with a user-friendly UI message such as an inline error banner or
toast notification to display login errors more gracefully.

@jinmao88 jinmao88 merged commit 193f5b6 into vbenjs:main Jul 28, 2025
12 checks passed
@ming4762 ming4762 deleted the 2025072604 branch July 29, 2025 01:57
@github-actions github-actions bot locked and limited conversation to collaborators Aug 29, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants