diff --git a/pages/login.vue b/pages/login.vue index 1deb079..f9c6ac1 100644 --- a/pages/login.vue +++ b/pages/login.vue @@ -65,6 +65,7 @@ const appLogo = ref(''); let isWxapp = false; let isCertifyOnly = false; +let redirectUrl = ''; const isLoading = ref(false); @@ -112,6 +113,7 @@ onMounted(() => { appLogo.value = route.query['app-logo']?.toString() ?? sessionStorage.getItem('app-logo') ?? ''; isWxapp = route.query['wxapp']?.toString() === 'true' || sessionStorage.getItem('wxapp') === 'true'; isCertifyOnly = route.query['certify-only']?.toString() === 'true'; + redirectUrl = route.query['redirect-url']?.toString() ?? sessionStorage.getItem('redirect-url') ?? '' const manually = route.query.manually?.toString() === 'true'; if (appName.value.length === 0) { @@ -125,6 +127,7 @@ onMounted(() => { sessionStorage.setItem('app-name', appName.value); sessionStorage.setItem('app-logo', appLogo.value); sessionStorage.setItem('certify-only', isCertifyOnly.toString()); + sessionStorage.setItem('redirect-url', redirectUrl) } /** diff --git a/utils/callback.ts b/utils/callback.ts index ea2df4d..f663217 100644 --- a/utils/callback.ts +++ b/utils/callback.ts @@ -6,8 +6,13 @@ export function callback(data: unknown) { const isWxapp = route.query['wxapp']?.toString() === 'true' || sessionStorage.getItem('wxapp') === 'true'; if (process.client && window.opener) { - window.opener.postMessage(data, '*'); - window.close(); + const url = getRedirectUrl() + if (url) { + handleWithUrl(url, data as any) + } else { + window.opener.postMessage(data, '*'); + window.close(); + } } else if (isWxapp) { wx.miniProgram.postMessage({ data, @@ -18,3 +23,22 @@ export function callback(data: unknown) { MMessage.error('无法回到应用中,请退出页面重新进入'); } } + +function getRedirectUrl(): URL | null { + const url = sessionStorage.getItem('redirect-url') ?? ''; + try { + return new URL(decodeURIComponent(url)) + } catch { + return null + } +} + +function handleWithUrl(url: URL, extend: any) { + if (!extend) { + return + } + + if (extend['is_certified']) { + window.location.href = url.toString() + } +}