| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- /**
- * 全局隐私协议检查 mixin
- * 注入所有页面的 onShow 生命周期
- * 通过版本号对比判断是否需要重新弹窗,支持协议更新后自动重新同意
- * 作用于:App 端 + 小程序端(H5 不拦截)
- */
- import { needPrivacyPopup } from '@/util/privacyConfig.js';
- // 防止多次 reLaunch 冲突导致页面卡死
- let isReLaunching = false;
- export default {
- onShow() {
- // privacy 页面自身不拦截(避免死循环)
- // 协议详情页也不拦截(用户从弹窗点"查看完整协议"跳过去时不能被 reLaunch 回来,否则白屏)
- // 登录页也不拦截(登录本身不涉及隐私数据使用,用户应能自由访问;
- // 若未同意隐私协议,登录成功进入主页时仍会被拦截到 privacy)
- // 关于我们页也不拦截(纯静态信息展示,不涉及隐私数据使用)
- // 注意:不能用 this.$route,vue-router 只在 H5 端存在
- // 统一用 getCurrentPages() 获取当前页面路径(三端都支持)
- const pages = getCurrentPages();
- if (pages && pages.length > 0) {
- const current = pages[pages.length - 1];
- const route = '/' + (current.route || '');
- if (
- route.indexOf('/pages/privacy/') !== -1 ||
- route.indexOf('/pages/login/agreement') !== -1 ||
- route.indexOf('/pages/login/login') !== -1 ||
- route.indexOf('/pages/my/about/about') !== -1
- ) {
- return;
- }
- }
- // App 端 + 小程序端:都拦截隐私协议(版本号不匹配时)
- // #ifndef H5
- if (needPrivacyPopup()) {
- // 防抖锁:避免多个页面 onShow 同时触发 reLaunch 导致页面栈混乱
- if (isReLaunching) return;
- isReLaunching = true;
- uni.reLaunch({
- url: '/pages/privacy/privacy',
- complete: () => {
- isReLaunching = false;
- },
- });
- }
- // #endif
- },
- };
|