From 9d2b76687cf4c00f52497755d8ecf23bba6e46db Mon Sep 17 00:00:00 2001 From: ZF sun <34314687@qq.com> Date: Fri, 10 Jul 2026 14:01:41 +0800 Subject: [PATCH] feat(privacy): add url-based skip rule for H5 privacy popup add ability to skip privacy popup when visiting specific H5 URLs directly, update PrivacyManager.show to accept skip option, add skip logic for specific form page to avoid blocking UI --- App.vue | 33 ++++++++++++++++++++++++++++++++- common/js/privacy.js | 14 +++++++++++++- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/App.vue b/App.vue index b960eef..ca8cf37 100644 --- a/App.vue +++ b/App.vue @@ -10,6 +10,36 @@ Weixin } from 'common/js/wx-jssdk.js'; + // ============================================================ + // 隐私弹窗跳过规则 (H5 only) + // 浏览器直接访问以下 URL(子串匹配 pathname+hash+search)时不弹隐私弹窗 + // 用于"打开 URL 直接看效果"的场景,避免被隐私弹窗挡住 + // 注意: 只跳过本次弹窗,不写 storage,下次正常访问其他页面还会弹 + // ============================================================ + const SKIP_PRIVACY_URL_PATTERNS_H5 = [ + '/pages_tool/form/formdata', // 表单详情:扫码/外链直访,弹窗会挡住表单 + ] + + /** + * 判断当前 H5 URL 是否命中"跳过隐私弹窗"黑名单 + * @returns {boolean} + */ + function _shouldSkipPrivacyForCurrentUrl() { + // #ifdef H5 + if (typeof window === 'undefined' || !window.location) return false + const patterns = SKIP_PRIVACY_URL_PATTERNS_H5 + if (!patterns || !patterns.length) return false + // 覆盖 history 模式和 hash 模式: pathname + search + hash 都拼上 + const path = (window.location.pathname || '') + + (window.location.search || '') + + (window.location.hash || '') + return patterns.some(p => path.indexOf(p) !== -1) + // #endif + // #ifndef H5 + return false + // #endif + } + // ============================================================ // 主题/语言启动 // ============================================================ @@ -110,7 +140,8 @@ // 通过 PrivacyManager → uni.$emit('privacy:show') 通知当前页面的 privacy-popup 组件 // 只弹一次: 同意后写 storage,后续不再弹 // 异步查询平台隐私状态(微信/鸿蒙), H5 同步返回 - try { await PrivacyManager.show(); } catch (e) { console.warn('[privacy] show fail', e); } + // H5 直访特定 URL(子串匹配)时跳过本次弹窗,不写 storage,下次正常访问其他页面还会弹 + try { await PrivacyManager.show({ skip: _shouldSkipPrivacyForCurrentUrl() }); } catch (e) { console.warn('[privacy] show fail', e); } // ---- 3) 远端就绪后,主题再 apply 一次(preset + remote 合并 ) // 这一次 setThemeStyle + themeColorSet 是同步路径(preset 已在 cache,remote 也在 cache) diff --git a/common/js/privacy.js b/common/js/privacy.js index 35da5cd..b468617 100644 --- a/common/js/privacy.js +++ b/common/js/privacy.js @@ -170,8 +170,20 @@ const PrivacyManager = { * 异步查询平台隐私状态,设置 _pendingShow 标志 * 页面组件 mounted 时通过 consumePendingShow() 消费标志并弹窗 * 不直接 emit 事件,避免 emit + 补偿双触发 + * + * @param {Object} [options] + * @param {boolean} [options.skip=false] true=本次跳过弹窗(不写 storage,下次正常访问其他页面还会弹) */ - async show() { + async show(options = {}) { + // 主动跳过: 不查 storage、不写 storage、不弹窗 + // 用于 H5 浏览器直接访问特定 URL(子串匹配)时不让隐私弹窗挡住 + if (options && options.skip) { + _needShow = false; + _hasChecked = true; + _pendingShow = false; + return; + } + const _storageAgreed = getStorageAgreed(); const result = await checkPrivacy();