feat: 支持平台代登录客户工作台

This commit is contained in:
2026-08-08 10:14:07 +08:00
parent 0b2380689c
commit c4540c1c0c
7 changed files with 85 additions and 6 deletions
+32 -3
View File
@@ -1,4 +1,33 @@
<template>
<RouterView />
</template>
<script setup lang="ts">
import { onBeforeUnmount, onMounted } from 'vue'
let readyInterval: number | null = null
onMounted(() => {
const configuredAdminOrigin = String(import.meta.env.VITE_ADMIN_WEB_ORIGIN || '').trim()
const targetOrigin = configuredAdminOrigin || window.location.origin
const announceReady = () => window.opener?.postMessage({ source: 'chongchong-client', type: 'impersonation-ready' }, targetOrigin)
announceReady()
readyInterval = window.setInterval(announceReady, 300)
window.setTimeout(() => {
if (readyInterval !== null) window.clearInterval(readyInterval)
readyInterval = null
}, 10000)
window.addEventListener('message', stopReadyAnnouncement)
})
function stopReadyAnnouncement(event: MessageEvent<unknown>) {
const configuredAdminOrigin = String(import.meta.env.VITE_ADMIN_WEB_ORIGIN || '').trim()
const expectedAdminOrigin = configuredAdminOrigin || window.location.origin
const message = event.data as { source?: string; type?: string } | null
if (event.source !== window.opener || event.origin !== expectedAdminOrigin || message?.source !== 'chongchong-admin' || message.type !== 'impersonation-ticket' || readyInterval === null) return
window.clearInterval(readyInterval)
readyInterval = null
}
onBeforeUnmount(() => {
if (readyInterval !== null) window.clearInterval(readyInterval)
window.removeEventListener('message', stopReadyAnnouncement)
})
</script>
<template><RouterView /></template>