From 453008a83ee3e48dff5104ac6dfb611b345661db Mon Sep 17 00:00:00 2001 From: liangzai <2440983361@qq.com> Date: Wed, 3 Jun 2026 15:04:47 +0800 Subject: [PATCH] f --- pages.config.ts | 3 ++- src/composables/usePrivacyConsent.ts | 33 +++++++++++++++++++++------- src/pages/index.vue | 7 +++++- src/pages/launch.vue | 2 +- src/pages/privacy-consent.vue | 30 +++++++++++++++++++++---- vite.config.ts | 1 + 6 files changed, 61 insertions(+), 15 deletions(-) diff --git a/pages.config.ts b/pages.config.ts index d80f1ac..5ef2a72 100644 --- a/pages.config.ts +++ b/pages.config.ts @@ -2,9 +2,10 @@ import { defineUniPages } from '@uni-helper/vite-plugin-uni-pages' export default defineUniPages({ pages: [ + // 必须为首屏:uni-app 仅 pages[0] 为 entryPagePath,勿依赖 launch 再 redirect(iOS 上易失败) + { path: 'pages/privacy-consent', style: { navigationStyle: 'custom', navigationBarTitleText: '隐私政策授权' } }, { path: 'pages/launch', style: { navigationStyle: 'custom', navigationBarTitleText: '' } }, { path: 'pages/index', style: { navigationBarTitleText: '首页' } }, - { path: 'pages/privacy-consent', style: { navigationStyle: 'custom', navigationBarTitleText: '隐私政策授权' } }, { path: 'pages/agent', style: { navigationBarTitleText: '代理中心' } }, { path: 'pages/agent-manage-agreement', style: { navigationBarTitleText: '代理管理协议', navigationStyle: 'default' } }, { path: 'pages/agent-promote-details', auth: true, style: { navigationBarTitleText: '收益明细' } }, diff --git a/src/composables/usePrivacyConsent.ts b/src/composables/usePrivacyConsent.ts index f3eeeff..72c590a 100644 --- a/src/composables/usePrivacyConsent.ts +++ b/src/composables/usePrivacyConsent.ts @@ -10,10 +10,6 @@ function normalizeRoute(url = '') { return String(url).replace(/^\//, '').split('?')[0] } -function hasDecision() { - return Boolean(getPrivacyDecision()) -} - export function getPrivacyConsentPageUrl() { return PRIVACY_CONSENT_PAGE } @@ -31,14 +27,35 @@ export function setPrivacyDecision(decision: PrivacyDecision) { } function shouldBlockNavigation(url = '') { - if (hasDecision()) + if (hasAcceptedPrivacyPolicy()) return false const route = normalizeRoute(url) return route !== 'pages/privacy-consent' && route !== 'pages/privacy-policy' } 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() { @@ -78,7 +95,7 @@ export function installPrivacyNavigationGuard() { uni.addInterceptor('switchTab', { invoke(args) { - if (!hasDecision()) { + if (!hasAcceptedPrivacyPolicy()) { redirectToConsent() return false } @@ -122,5 +139,5 @@ export function ensurePrivacyConsentIfNeeded() { const route = normalizeRoute(page?.route || '') if (PRIVACY_FLOW_ROUTES.has(route)) return - uni.reLaunch({ url: PRIVACY_CONSENT_PAGE }) + schedulePrivacyConsentRedirect() } diff --git a/src/pages/index.vue b/src/pages/index.vue index ca10209..744bc00 100644 --- a/src/pages/index.vue +++ b/src/pages/index.vue @@ -17,8 +17,13 @@ import indexPromoteIcon from '/static/images/index/tgbg.png' import indexMyReportIcon from '/static/images/index/wdbg.png' import indexInvitationIcon from '/static/images/index/yqhy.png' 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] diff --git a/src/pages/launch.vue b/src/pages/launch.vue index 04d6de6..21ef372 100644 --- a/src/pages/launch.vue +++ b/src/pages/launch.vue @@ -13,7 +13,7 @@ async function routeOnLaunch() { routing.value = true try { if (!hasAcceptedPrivacyPolicy()) { - uni.redirectTo({ url: getPrivacyConsentPageUrl() }) + uni.reLaunch({ url: getPrivacyConsentPageUrl() }) return } await bootstrap() diff --git a/src/pages/privacy-consent.vue b/src/pages/privacy-consent.vue index b9decb3..b4b912a 100644 --- a/src/pages/privacy-consent.vue +++ b/src/pages/privacy-consent.vue @@ -1,7 +1,11 @@ diff --git a/vite.config.ts b/vite.config.ts index 209f9bb..372372e 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -29,6 +29,7 @@ export default defineConfig({ // https://uni-helper.js.org/vite-plugin-uni-pages UniHelperPages({ dts: 'src/uni-pages.d.ts', + homePage: ['pages/index'], }), // https://uni-helper.js.org/vite-plugin-uni-layouts UniHelperLayouts(),