diff --git a/components/privacy-popup/privacy-popup.vue b/components/privacy-popup/privacy-popup.vue index 0a53959..11c4544 100644 --- a/components/privacy-popup/privacy-popup.vue +++ b/components/privacy-popup/privacy-popup.vue @@ -158,22 +158,48 @@ export default { success: (res) => { // console.log(res) if (res.needAuthorization) { - this.popUp() - // 额外逻辑:当前页面的隐私弹窗弹起的时候,关掉其他页面的隐私弹窗 - this.closeOtherPagePopUp(this.disPopUp) + // 检查本地存储中是否已经同意过隐私政策 + const privacyAgreed = uni.getStorageSync('privacyAgreed'); + if (!privacyAgreed) { + this.popUp() + // 额外逻辑:当前页面的隐私弹窗弹起的时候,关掉其他页面的隐私弹窗 + this.closeOtherPagePopUp(this.disPopUp) + } else { + this.$emit('agree') + } } else { this.$emit('agree') } }, }); } else { - this.$emit('agree') + // 检查本地存储中是否已经同意过隐私政策 + const privacyAgreed = uni.getStorageSync('privacyAgreed'); + if (privacyAgreed) { + this.$emit('agree'); + } else { + this.popUp() + // 额外逻辑:当前页面的隐私弹窗弹起的时候,关掉其他页面的隐私弹窗 + this.closeOtherPagePopUp(this.disPopUp) + } } // #endif // #ifdef QUICKAPP-WEBVIEW this.getPrivacySettingByQuickApp(); // #endif + + // #ifdef H5 || WEB + // 检查本地存储中是否已经同意过隐私政策 + const privacyAgreed = uni.getStorageSync('privacyAgreed'); + if (privacyAgreed) { + this.$emit('agree'); + } else { + this.popUp() + // 额外逻辑:当前页面的隐私弹窗弹起的时候,关掉其他页面的隐私弹窗 + this.closeOtherPagePopUp(this.disPopUp) + } + // #endif }, //初始化监听程序 curPageShow() { @@ -281,10 +307,8 @@ export default { //关闭弹窗 this.disPopUp() - // #ifdef QUICKAPP-WEBVIEW || H5 || WEB - // 保存用户授权状态到本地存储,用于快应用Webview组件中的H5方式处理 + // 保存用户授权状态到本地存储,用于所有环境 uni.setStorageSync('privacyAgreed', true); - // #endif this.$emit('agree') }, //打开弹窗 diff --git a/pages/index/public/js/index.js b/pages/index/public/js/index.js index 76bce50..0c7242c 100644 --- a/pages/index/public/js/index.js +++ b/pages/index/public/js/index.js @@ -4,7 +4,6 @@ export default { minScrollTop: 100, wechatQrcode: '', diyRoute: '/pages/index/index', - // 新增一个标记,用于记录当前页面是否已经处理过隐私协议 hasCheckedPrivacy: false }; }, @@ -16,15 +15,11 @@ export default { // #endif this.name = option.name || 'DIY_VIEW_INDEX'; - // 调试用:强制清除缓存(上线前请删除!) - // uni.removeStorageSync('privacyAgreed'); - // 页面加载时检查 this.checkPrivacy(); }, onShow() { this.getFollowQrcode(); - // 注意:这里不再调用 checkPrivacy,完全依赖 onLoad 和 用户交互 }, mounted() { this.unsubscribe = this.$eventBus?.onMany( @@ -46,66 +41,46 @@ export default { }, methods: { handleTap(type, item) { - // ... 你的原有逻辑 ... }, getFollowQrcode() { - // ... 你的原有逻辑 ... }, - - // --- 核心修改区域 --- - - /** - * 检查隐私协议 - * 逻辑:只有当 hasCheckedPrivacy 为 false 且 本地没有缓存时,才弹窗 - */ checkPrivacy() { - // 1. 如果已经检查过了,直接返回,绝不再弹 + if (this.hasCheckedPrivacy) { return; } - // 2. 检查本地缓存 + const agreed = uni.getStorageSync('privacyAgreed'); if (agreed) { - // 如果有缓存,标记为已检查,不弹窗 - this.hasCheckedPrivacy = true; - console.log('✅ 隐私协议已同意,不再弹出'); - } else { - // 3. 如果没有缓存,标记为已检查(防止 onShow 重复触发),并强制弹窗 - this.hasCheckedPrivacy = true; - console.log('⚠️ 未同意隐私协议,强制弹窗'); - // 使用 $nextTick 确保 DOM 渲染完成后再操作组件 + this.hasCheckedPrivacy = true; + console.log(' 隐私协议已同意,不再弹出'); + } else { + + this.hasCheckedPrivacy = true; + console.log(' 未同意隐私协议,强制弹窗'); this.$nextTick(() => { const privacyPopup = this.$refs.privacyPopup; if (privacyPopup) { - // 强制调用组件的 popUp 方法 privacyPopup.popUp(); } else { - console.error('❌ 找不到 privacyPopup 组件引用'); + console.error(' 找不到 privacyPopup 组件引用'); } }); } }, - /** - * 处理同意隐私协议 - * 逻辑:用户点击同意后,我们**主动**写入缓存 - */ onAgreePrivacy() { - console.log('🎉 用户点击了同意'); + console.log(' 用户点击了同意'); - // 【关键修复】不管组件内部有没有写,我们在这里强制写入缓存 uni.setStorageSync('privacyAgreed', true); - - // 标记状态 this.hasCheckedPrivacy = true; }, onDisagreePrivacy() { - console.log('🚫 用户拒绝了隐私协议'); - // 可以在这里处理退出的逻辑 + console.log(' 用户拒绝了隐私协议'); } } } \ No newline at end of file