From 379e8e755fb062bee0aaa5b4f15743b28830e800 Mon Sep 17 00:00:00 2001 From: xingyu4j Date: Wed, 9 Jul 2025 17:11:22 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E5=B0=86=20getUrlValue=20=E6=94=BE?= =?UTF-8?q?=E5=85=A5=20vben/utils=20=E4=B8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/views/_core/authentication/social-login.vue | 7 +------ .../src/views/_core/profile/modules/user-social.vue | 8 +------- .../src/views/_core/authentication/social-login.vue | 7 +------ .../src/views/_core/profile/modules/user-social.vue | 8 +------- .../src/views/_core/authentication/social-login.vue | 7 +------ .../src/views/_core/profile/modules/user-social.vue | 10 ++-------- packages/@core/base/shared/src/utils/util.ts | 10 ++++++++++ 7 files changed, 17 insertions(+), 40 deletions(-) diff --git a/apps/web-antd/src/views/_core/authentication/social-login.vue b/apps/web-antd/src/views/_core/authentication/social-login.vue index e75a9c0d4..1052a9a18 100644 --- a/apps/web-antd/src/views/_core/authentication/social-login.vue +++ b/apps/web-antd/src/views/_core/authentication/social-login.vue @@ -10,6 +10,7 @@ import { AuthenticationLogin, Verification, z } from '@vben/common-ui'; import { isCaptchaEnable, isTenantEnable } from '@vben/hooks'; import { $t } from '@vben/locales'; import { useAccessStore } from '@vben/stores'; +import { getUrlValue } from '@vben/utils'; import { checkCaptcha, @@ -124,12 +125,6 @@ async function handleVerifySuccess({ captchaVerification }: any) { } } -/** tricky: 配合 login.vue 中,redirectUri 需要对参数进行 encode,需要在回调后进行decode */ -function getUrlValue(key: string): string { - const url = new URL(decodeURIComponent(location.href)); - return url.searchParams.get(key) ?? ''; -} - /** 组件挂载时获取租户信息 */ onMounted(async () => { await fetchTenantList(); diff --git a/apps/web-antd/src/views/_core/profile/modules/user-social.vue b/apps/web-antd/src/views/_core/profile/modules/user-social.vue index 37f5c7e94..9e6911d43 100644 --- a/apps/web-antd/src/views/_core/profile/modules/user-social.vue +++ b/apps/web-antd/src/views/_core/profile/modules/user-social.vue @@ -6,6 +6,7 @@ import { computed, onMounted, ref } from 'vue'; import { useRoute } from 'vue-router'; import { confirm } from '@vben/common-ui'; +import { getUrlValue } from '@vben/utils'; import { Button, Card, Image, message } from 'ant-design-vue'; @@ -149,13 +150,6 @@ async function bindSocial() { window.history.replaceState({}, '', location.pathname); } -// TODO @芋艿:后续搞到 util 里; -// 双层 encode 需要在回调后进行 decode -function getUrlValue(key: string): string { - const url = new URL(decodeURIComponent(location.href)); - return url.searchParams.get(key) ?? ''; -} - /** 初始化 */ onMounted(() => { bindSocial(); diff --git a/apps/web-ele/src/views/_core/authentication/social-login.vue b/apps/web-ele/src/views/_core/authentication/social-login.vue index e75a9c0d4..1052a9a18 100644 --- a/apps/web-ele/src/views/_core/authentication/social-login.vue +++ b/apps/web-ele/src/views/_core/authentication/social-login.vue @@ -10,6 +10,7 @@ import { AuthenticationLogin, Verification, z } from '@vben/common-ui'; import { isCaptchaEnable, isTenantEnable } from '@vben/hooks'; import { $t } from '@vben/locales'; import { useAccessStore } from '@vben/stores'; +import { getUrlValue } from '@vben/utils'; import { checkCaptcha, @@ -124,12 +125,6 @@ async function handleVerifySuccess({ captchaVerification }: any) { } } -/** tricky: 配合 login.vue 中,redirectUri 需要对参数进行 encode,需要在回调后进行decode */ -function getUrlValue(key: string): string { - const url = new URL(decodeURIComponent(location.href)); - return url.searchParams.get(key) ?? ''; -} - /** 组件挂载时获取租户信息 */ onMounted(async () => { await fetchTenantList(); diff --git a/apps/web-ele/src/views/_core/profile/modules/user-social.vue b/apps/web-ele/src/views/_core/profile/modules/user-social.vue index afedf32ff..f4ff0769a 100644 --- a/apps/web-ele/src/views/_core/profile/modules/user-social.vue +++ b/apps/web-ele/src/views/_core/profile/modules/user-social.vue @@ -6,6 +6,7 @@ import { computed, onMounted, ref } from 'vue'; import { useRoute } from 'vue-router'; import { confirm } from '@vben/common-ui'; +import { getUrlValue } from '@vben/utils'; import { ElButton, ElCard, ElImage, ElMessage } from 'element-plus'; @@ -149,13 +150,6 @@ async function bindSocial() { window.history.replaceState({}, '', location.pathname); } -// TODO @芋艿:后续搞到 util 里; -// 双层 encode 需要在回调后进行 decode -function getUrlValue(key: string): string { - const url = new URL(decodeURIComponent(location.href)); - return url.searchParams.get(key) ?? ''; -} - /** 初始化 */ onMounted(() => { bindSocial(); diff --git a/apps/web-naive/src/views/_core/authentication/social-login.vue b/apps/web-naive/src/views/_core/authentication/social-login.vue index e75a9c0d4..1052a9a18 100644 --- a/apps/web-naive/src/views/_core/authentication/social-login.vue +++ b/apps/web-naive/src/views/_core/authentication/social-login.vue @@ -10,6 +10,7 @@ import { AuthenticationLogin, Verification, z } from '@vben/common-ui'; import { isCaptchaEnable, isTenantEnable } from '@vben/hooks'; import { $t } from '@vben/locales'; import { useAccessStore } from '@vben/stores'; +import { getUrlValue } from '@vben/utils'; import { checkCaptcha, @@ -124,12 +125,6 @@ async function handleVerifySuccess({ captchaVerification }: any) { } } -/** tricky: 配合 login.vue 中,redirectUri 需要对参数进行 encode,需要在回调后进行decode */ -function getUrlValue(key: string): string { - const url = new URL(decodeURIComponent(location.href)); - return url.searchParams.get(key) ?? ''; -} - /** 组件挂载时获取租户信息 */ onMounted(async () => { await fetchTenantList(); diff --git a/apps/web-naive/src/views/_core/profile/modules/user-social.vue b/apps/web-naive/src/views/_core/profile/modules/user-social.vue index 2b2693c30..0c5422f6a 100644 --- a/apps/web-naive/src/views/_core/profile/modules/user-social.vue +++ b/apps/web-naive/src/views/_core/profile/modules/user-social.vue @@ -6,6 +6,7 @@ import { computed, onMounted, ref } from 'vue'; import { useRoute } from 'vue-router'; import { confirm } from '@vben/common-ui'; +import { getUrlValue } from '@vben/utils'; import { NButton, NCard, NImage } from 'naive-ui'; @@ -150,13 +151,6 @@ async function bindSocial() { window.history.replaceState({}, '', location.pathname); } -// TODO @芋艿:后续搞到 util 里; -// 双层 encode 需要在回调后进行 decode -function getUrlValue(key: string): string { - const url = new URL(decodeURIComponent(location.href)); - return url.searchParams.get(key) ?? ''; -} - /** 初始化 */ onMounted(() => { bindSocial(); @@ -201,7 +195,7 @@ onMounted(() => { {{ item.socialUser ? '已绑定' : '绑定' }} diff --git a/packages/@core/base/shared/src/utils/util.ts b/packages/@core/base/shared/src/utils/util.ts index 885eeaa63..6ed9591d4 100644 --- a/packages/@core/base/shared/src/utils/util.ts +++ b/packages/@core/base/shared/src/utils/util.ts @@ -42,3 +42,13 @@ export function getNestedValue(obj: T, path: string): any { return current; } + +/** + * 获取 URL 参数值 + * @param key - 参数键 + * @returns 参数值,或者未找到时返回空字符串 + */ +export function getUrlValue(key: string): string { + const url = new URL(decodeURIComponent(location.href)); + return url.searchParams.get(key) ?? ''; +}