This commit is contained in:
2026-06-03 15:04:47 +08:00
parent bf9ea19771
commit 453008a83e
6 changed files with 61 additions and 15 deletions

View File

@@ -2,9 +2,10 @@ import { defineUniPages } from '@uni-helper/vite-plugin-uni-pages'
export default defineUniPages({ export default defineUniPages({
pages: [ pages: [
// 必须为首屏uni-app 仅 pages[0] 为 entryPagePath勿依赖 launch 再 redirectiOS 上易失败)
{ path: 'pages/privacy-consent', style: { navigationStyle: 'custom', navigationBarTitleText: '隐私政策授权' } },
{ path: 'pages/launch', style: { navigationStyle: 'custom', navigationBarTitleText: '' } }, { path: 'pages/launch', style: { navigationStyle: 'custom', navigationBarTitleText: '' } },
{ path: 'pages/index', style: { navigationBarTitleText: '首页' } }, { path: 'pages/index', style: { navigationBarTitleText: '首页' } },
{ path: 'pages/privacy-consent', style: { navigationStyle: 'custom', navigationBarTitleText: '隐私政策授权' } },
{ path: 'pages/agent', style: { navigationBarTitleText: '代理中心' } }, { path: 'pages/agent', style: { navigationBarTitleText: '代理中心' } },
{ path: 'pages/agent-manage-agreement', style: { navigationBarTitleText: '代理管理协议', navigationStyle: 'default' } }, { path: 'pages/agent-manage-agreement', style: { navigationBarTitleText: '代理管理协议', navigationStyle: 'default' } },
{ path: 'pages/agent-promote-details', auth: true, style: { navigationBarTitleText: '收益明细' } }, { path: 'pages/agent-promote-details', auth: true, style: { navigationBarTitleText: '收益明细' } },

View File

@@ -10,10 +10,6 @@ function normalizeRoute(url = '') {
return String(url).replace(/^\//, '').split('?')[0] return String(url).replace(/^\//, '').split('?')[0]
} }
function hasDecision() {
return Boolean(getPrivacyDecision())
}
export function getPrivacyConsentPageUrl() { export function getPrivacyConsentPageUrl() {
return PRIVACY_CONSENT_PAGE return PRIVACY_CONSENT_PAGE
} }
@@ -31,14 +27,35 @@ export function setPrivacyDecision(decision: PrivacyDecision) {
} }
function shouldBlockNavigation(url = '') { function shouldBlockNavigation(url = '') {
if (hasDecision()) if (hasAcceptedPrivacyPolicy())
return false return false
const route = normalizeRoute(url) const route = normalizeRoute(url)
return route !== 'pages/privacy-consent' && route !== 'pages/privacy-policy' return route !== 'pages/privacy-consent' && route !== 'pages/privacy-policy'
} }
function redirectToConsent() { function redirectToConsent() {
uni.redirectTo({ url: PRIVACY_CONSENT_PAGE }) uni.reLaunch({ url: PRIVACY_CONSENT_PAGE })
}
let privacyEnsureScheduled = false
function schedulePrivacyConsentRedirect() {
if (privacyEnsureScheduled)
return
privacyEnsureScheduled = true
const run = () => {
privacyEnsureScheduled = false
if (hasAcceptedPrivacyPolicy())
return
uni.reLaunch({ url: PRIVACY_CONSENT_PAGE })
}
// iOS 在 App.onLaunch / 首屏 layout.onShow 同步 reLaunch 常不生效,需延后到下一帧
// #ifdef APP-IOS
setTimeout(run, 50)
// #endif
// #ifndef APP-IOS
run()
// #endif
} }
export function installPrivacyNavigationGuard() { export function installPrivacyNavigationGuard() {
@@ -78,7 +95,7 @@ export function installPrivacyNavigationGuard() {
uni.addInterceptor('switchTab', { uni.addInterceptor('switchTab', {
invoke(args) { invoke(args) {
if (!hasDecision()) { if (!hasAcceptedPrivacyPolicy()) {
redirectToConsent() redirectToConsent()
return false return false
} }
@@ -122,5 +139,5 @@ export function ensurePrivacyConsentIfNeeded() {
const route = normalizeRoute(page?.route || '') const route = normalizeRoute(page?.route || '')
if (PRIVACY_FLOW_ROUTES.has(route)) if (PRIVACY_FLOW_ROUTES.has(route))
return return
uni.reLaunch({ url: PRIVACY_CONSENT_PAGE }) schedulePrivacyConsentRedirect()
} }

View File

@@ -17,8 +17,13 @@ import indexPromoteIcon from '/static/images/index/tgbg.png'
import indexMyReportIcon from '/static/images/index/wdbg.png' import indexMyReportIcon from '/static/images/index/wdbg.png'
import indexInvitationIcon from '/static/images/index/yqhy.png' import indexInvitationIcon from '/static/images/index/yqhy.png'
import { useAppConfig } from '@/composables/useAppConfig' import { useAppConfig } from '@/composables/useAppConfig'
import { ensurePrivacyConsentIfNeeded } from '@/composables/usePrivacyConsent'
definePage({ type: 'home', layout: 'home' }) definePage({ layout: 'home' })
onShow(() => {
ensurePrivacyConsentIfNeeded()
})
const banners = [bannerImg, bannerImg2, bannerImg3] const banners = [bannerImg, bannerImg2, bannerImg3]

View File

@@ -13,7 +13,7 @@ async function routeOnLaunch() {
routing.value = true routing.value = true
try { try {
if (!hasAcceptedPrivacyPolicy()) { if (!hasAcceptedPrivacyPolicy()) {
uni.redirectTo({ url: getPrivacyConsentPageUrl() }) uni.reLaunch({ url: getPrivacyConsentPageUrl() })
return return
} }
await bootstrap() await bootstrap()

View File

@@ -1,7 +1,11 @@
<script setup lang="ts"> <script setup lang="ts">
import { useAppBootstrap } from '@/composables/useAppBootstrap' import { useAppBootstrap } from '@/composables/useAppBootstrap'
import { useReportWebview } from '@/composables/useReportWebview' import { useReportWebview } from '@/composables/useReportWebview'
import { getPrivacyDecision, setPrivacyDecision } from '@/composables/usePrivacyConsent' import {
getPrivacyDecision,
hasAcceptedPrivacyPolicy,
setPrivacyDecision,
} from '@/composables/usePrivacyConsent'
definePage({ layout: false }) definePage({ layout: false })
@@ -57,10 +61,28 @@ function handleAbandon() {
// #endif // #endif
} }
onShow(() => { const enteringApp = ref(false)
const decision = getPrivacyDecision()
if (decision === 'accepted') async function enterAppIfAccepted() {
if (!hasAcceptedPrivacyPolicy() || enteringApp.value)
return
enteringApp.value = true
try {
await bootstrap()
uni.reLaunch({ url: '/pages/index' }) uni.reLaunch({ url: '/pages/index' })
}
finally {
enteringApp.value = false
}
}
onLoad(() => {
void enterAppIfAccepted()
})
onShow(() => {
if (getPrivacyDecision() === 'accepted')
void enterAppIfAccepted()
}) })
</script> </script>

View File

@@ -29,6 +29,7 @@ export default defineConfig({
// https://uni-helper.js.org/vite-plugin-uni-pages // https://uni-helper.js.org/vite-plugin-uni-pages
UniHelperPages({ UniHelperPages({
dts: 'src/uni-pages.d.ts', dts: 'src/uni-pages.d.ts',
homePage: ['pages/index'],
}), }),
// https://uni-helper.js.org/vite-plugin-uni-layouts // https://uni-helper.js.org/vite-plugin-uni-layouts
UniHelperLayouts(), UniHelperLayouts(),