perf: 将 getUrlValue 放入 vben/utils 下

pull/170/head^2
xingyu4j 2025-07-09 17:11:22 +08:00
parent 4eeaa32b2c
commit 379e8e755f
7 changed files with 17 additions and 40 deletions

View File

@ -10,6 +10,7 @@ import { AuthenticationLogin, Verification, z } from '@vben/common-ui';
import { isCaptchaEnable, isTenantEnable } from '@vben/hooks'; import { isCaptchaEnable, isTenantEnable } from '@vben/hooks';
import { $t } from '@vben/locales'; import { $t } from '@vben/locales';
import { useAccessStore } from '@vben/stores'; import { useAccessStore } from '@vben/stores';
import { getUrlValue } from '@vben/utils';
import { import {
checkCaptcha, 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 () => { onMounted(async () => {
await fetchTenantList(); await fetchTenantList();

View File

@ -6,6 +6,7 @@ import { computed, onMounted, ref } from 'vue';
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
import { confirm } from '@vben/common-ui'; import { confirm } from '@vben/common-ui';
import { getUrlValue } from '@vben/utils';
import { Button, Card, Image, message } from 'ant-design-vue'; import { Button, Card, Image, message } from 'ant-design-vue';
@ -149,13 +150,6 @@ async function bindSocial() {
window.history.replaceState({}, '', location.pathname); 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(() => { onMounted(() => {
bindSocial(); bindSocial();

View File

@ -10,6 +10,7 @@ import { AuthenticationLogin, Verification, z } from '@vben/common-ui';
import { isCaptchaEnable, isTenantEnable } from '@vben/hooks'; import { isCaptchaEnable, isTenantEnable } from '@vben/hooks';
import { $t } from '@vben/locales'; import { $t } from '@vben/locales';
import { useAccessStore } from '@vben/stores'; import { useAccessStore } from '@vben/stores';
import { getUrlValue } from '@vben/utils';
import { import {
checkCaptcha, 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 () => { onMounted(async () => {
await fetchTenantList(); await fetchTenantList();

View File

@ -6,6 +6,7 @@ import { computed, onMounted, ref } from 'vue';
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
import { confirm } from '@vben/common-ui'; import { confirm } from '@vben/common-ui';
import { getUrlValue } from '@vben/utils';
import { ElButton, ElCard, ElImage, ElMessage } from 'element-plus'; import { ElButton, ElCard, ElImage, ElMessage } from 'element-plus';
@ -149,13 +150,6 @@ async function bindSocial() {
window.history.replaceState({}, '', location.pathname); 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(() => { onMounted(() => {
bindSocial(); bindSocial();

View File

@ -10,6 +10,7 @@ import { AuthenticationLogin, Verification, z } from '@vben/common-ui';
import { isCaptchaEnable, isTenantEnable } from '@vben/hooks'; import { isCaptchaEnable, isTenantEnable } from '@vben/hooks';
import { $t } from '@vben/locales'; import { $t } from '@vben/locales';
import { useAccessStore } from '@vben/stores'; import { useAccessStore } from '@vben/stores';
import { getUrlValue } from '@vben/utils';
import { import {
checkCaptcha, 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 () => { onMounted(async () => {
await fetchTenantList(); await fetchTenantList();

View File

@ -6,6 +6,7 @@ import { computed, onMounted, ref } from 'vue';
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
import { confirm } from '@vben/common-ui'; import { confirm } from '@vben/common-ui';
import { getUrlValue } from '@vben/utils';
import { NButton, NCard, NImage } from 'naive-ui'; import { NButton, NCard, NImage } from 'naive-ui';
@ -150,13 +151,6 @@ async function bindSocial() {
window.history.replaceState({}, '', location.pathname); 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(() => { onMounted(() => {
bindSocial(); bindSocial();
@ -201,7 +195,7 @@ onMounted(() => {
<NButton <NButton
:disabled="!!item.socialUser" :disabled="!!item.socialUser"
size="small" size="small"
type="link" text
@click="onBind(item)" @click="onBind(item)"
> >
{{ item.socialUser ? '已绑定' : '绑定' }} {{ item.socialUser ? '已绑定' : '绑定' }}

View File

@ -42,3 +42,13 @@ export function getNestedValue<T>(obj: T, path: string): any {
return current; return current;
} }
/**
* URL
* @param key -
* @returns
*/
export function getUrlValue(key: string): string {
const url = new URL(decodeURIComponent(location.href));
return url.searchParams.get(key) ?? '';
}