<script setup>
|
import {
|
onLaunch,
|
onShow
|
} from '@dcloudio/uni-app'
|
import {
|
extractBindTicket,
|
extractInviteCode
|
} from '@/utils/utils.js'
|
import { hasCompletedAuthSession } from '@/utils/auth-session.js'
|
import { cacheInviteCode } from '@/utils/invite-cache.js'
|
import { initJPushLifecycle } from '@/utils/push.js'
|
import {
|
getOpeninstallInstallData,
|
initOpeninstall,
|
registerOpeninstallWakeUp
|
} from '@/utils/openinstall.js'
|
let lastHandledInvitePayload = ''
|
|
/**
|
* 应用启动时初始化极光与 openinstall,承接推广关系参数。
|
*/
|
onLaunch(() => {
|
// #ifdef APP-PLUS
|
initJPushLifecycle()
|
initOpeninstall()
|
registerOpeninstallWakeUp(handleOpeninstallPayload)
|
getOpeninstallInstallData(handleOpeninstallPayload)
|
// #endif
|
})
|
|
/**
|
* App 被外部 Scheme 拉起时,解析 bindTicket 或 inviteCode 并跳转注册页。
|
*/
|
onShow(() => {
|
handleOpenByScheme()
|
})
|
|
/**
|
* 读取原生启动参数中的绑定票据或邀请码,并在命中时跳转注册页。
|
*/
|
function handleOpenByScheme() {
|
// #ifdef APP-PLUS
|
const runtimeArguments = typeof plus !== 'undefined' && plus.runtime ? plus.runtime.arguments : ''
|
handleInvitePayload(runtimeArguments)
|
// #endif
|
}
|
|
/**
|
* 处理 openinstall 安装参数或唤醒参数。
|
*/
|
function handleOpeninstallPayload(payload) {
|
handleInvitePayload(payload)
|
}
|
|
/**
|
* 统一解析外部推广参数,并跳转到注册页回填。
|
*/
|
function handleInvitePayload(payload) {
|
const bindTicket = extractBindTicket(payload)
|
const inviteCode = extractInviteCode(payload)
|
if (!bindTicket && !inviteCode) {
|
return
|
}
|
if (inviteCode) {
|
cacheInviteCode(inviteCode)
|
}
|
const payloadKey = `${bindTicket || ''}_${inviteCode || ''}`
|
if (payloadKey === lastHandledInvitePayload) {
|
return
|
}
|
lastHandledInvitePayload = payloadKey
|
if (hasCompletedAuthSession()) {
|
return
|
}
|
const currentPages = getCurrentPages()
|
const currentRoute = currentPages && currentPages.length > 0 ? currentPages[currentPages.length - 1].route : ''
|
const targetParams = []
|
if (bindTicket) {
|
targetParams.push(`bindTicket=${encodeURIComponent(bindTicket)}`)
|
}
|
if (inviteCode) {
|
targetParams.push(`inviteCode=${encodeURIComponent(inviteCode)}`)
|
}
|
const targetUrl = `/pages/register/register?${targetParams.join('&')}`
|
if (currentRoute === 'pages/register/register') {
|
uni.redirectTo({
|
url: targetUrl
|
})
|
return
|
}
|
uni.navigateTo({
|
url: targetUrl
|
})
|
}
|
</script>
|
|
<style lang="scss">
|
/*每个页面公共css */
|
@import "@/uni_modules/uview-pro/index.scss";
|
@import "@/static/style/index.scss";
|
</style>
|