Skip to content

Commit

Permalink
feat: 添加redirect-url
Browse files Browse the repository at this point in the history
  • Loading branch information
orangeboyChen committed Aug 27, 2023
1 parent 992353e commit 4634e41
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
3 changes: 3 additions & 0 deletions pages/login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const appLogo = ref('');
let isWxapp = false;
let isCertifyOnly = false;
let redirectUrl = '';
const isLoading = ref(false);
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
}
/**
Expand Down
28 changes: 26 additions & 2 deletions utils/callback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
}
}

0 comments on commit 4634e41

Please sign in to comment.