f
This commit is contained in:
@@ -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: '收益明细' } },
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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]
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ async function routeOnLaunch() {
|
||||
routing.value = true
|
||||
try {
|
||||
if (!hasAcceptedPrivacyPolicy()) {
|
||||
uni.redirectTo({ url: getPrivacyConsentPageUrl() })
|
||||
uni.reLaunch({ url: getPrivacyConsentPageUrl() })
|
||||
return
|
||||
}
|
||||
await bootstrap()
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
<script setup lang="ts">
|
||||
import { useAppBootstrap } from '@/composables/useAppBootstrap'
|
||||
import { useReportWebview } from '@/composables/useReportWebview'
|
||||
import { getPrivacyDecision, setPrivacyDecision } from '@/composables/usePrivacyConsent'
|
||||
import {
|
||||
getPrivacyDecision,
|
||||
hasAcceptedPrivacyPolicy,
|
||||
setPrivacyDecision,
|
||||
} from '@/composables/usePrivacyConsent'
|
||||
|
||||
definePage({ layout: false })
|
||||
|
||||
@@ -57,10 +61,28 @@ function handleAbandon() {
|
||||
// #endif
|
||||
}
|
||||
|
||||
onShow(() => {
|
||||
const decision = getPrivacyDecision()
|
||||
if (decision === 'accepted')
|
||||
const enteringApp = ref(false)
|
||||
|
||||
async function enterAppIfAccepted() {
|
||||
if (!hasAcceptedPrivacyPolicy() || enteringApp.value)
|
||||
return
|
||||
enteringApp.value = true
|
||||
try {
|
||||
await bootstrap()
|
||||
uni.reLaunch({ url: '/pages/index' })
|
||||
}
|
||||
finally {
|
||||
enteringApp.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onLoad(() => {
|
||||
void enterAppIfAccepted()
|
||||
})
|
||||
|
||||
onShow(() => {
|
||||
if (getPrivacyDecision() === 'accepted')
|
||||
void enterAppIfAccepted()
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user