chore:H5只弹一次,点击同意后就不弹了
This commit is contained in:
@@ -3,7 +3,9 @@ export default {
|
||||
return {
|
||||
minScrollTop: 100,
|
||||
wechatQrcode: '',
|
||||
diyRoute: '/pages/index/index'
|
||||
diyRoute: '/pages/index/index',
|
||||
// 新增一个标记,用于记录当前页面是否已经处理过隐私协议
|
||||
hasCheckedPrivacy: false
|
||||
};
|
||||
},
|
||||
onLoad(option) {
|
||||
@@ -13,14 +15,20 @@ export default {
|
||||
}
|
||||
// #endif
|
||||
this.name = option.name || 'DIY_VIEW_INDEX';
|
||||
|
||||
// 调试用:强制清除缓存(上线前请删除!)
|
||||
// uni.removeStorageSync('privacyAgreed');
|
||||
|
||||
// 页面加载时检查
|
||||
this.checkPrivacy();
|
||||
},
|
||||
onShow() {
|
||||
this.getFollowQrcode();
|
||||
// 页面显示时,检查是否需要弹窗
|
||||
this.checkAndShowPrivacy();
|
||||
// 注意:这里不再调用 checkPrivacy,完全依赖 onLoad 和 用户交互
|
||||
},
|
||||
mounted() {
|
||||
this.unsubscribe = this.$eventBus?.onMany([
|
||||
this.unsubscribe = this.$eventBus?.onMany(
|
||||
[
|
||||
'rubik-cube-tap',
|
||||
'picture-tap',
|
||||
'text-tap',
|
||||
@@ -31,63 +39,73 @@ export default {
|
||||
'map-tap',
|
||||
'img-ads-tap',
|
||||
'many-goods-list-tap',
|
||||
'search-tap',
|
||||
], this._handleDiyGroupInteractionEvent);
|
||||
},
|
||||
beforeDestroy() {
|
||||
if (this.unsubscribe) this.unsubscribe();
|
||||
'search-tap'
|
||||
],
|
||||
this.handleTap
|
||||
);
|
||||
},
|
||||
methods: {
|
||||
// --- 新增:检查并显示隐私弹窗 ---
|
||||
checkAndShowPrivacy() {
|
||||
// 1. 为了测试,先强制清除缓存(正式发布时请删除下面这行)
|
||||
uni.removeStorageSync('privacyAgreed');
|
||||
|
||||
// 2. 获取缓存状态
|
||||
const hasAgreed = uni.getStorageSync('privacyAgreed');
|
||||
|
||||
// 3. 如果没有同意过,且组件已加载,强制调用组件的 popUp 方法
|
||||
if (!hasAgreed) {
|
||||
this.$nextTick(() => {
|
||||
if (this.$refs.privacyPopup) {
|
||||
console.log('强制调用 privacyPopup.popUp()');
|
||||
// 直接调用组件里的 popUp 方法,把 showPop 设为 true
|
||||
this.$refs.privacyPopup.popUp();
|
||||
}
|
||||
});
|
||||
}
|
||||
handleTap(type, item) {
|
||||
// ... 你的原有逻辑 ...
|
||||
},
|
||||
|
||||
// 关注公众号
|
||||
getFollowQrcode() {
|
||||
if (!this.$util.isWeiXin()) return;
|
||||
this.$api.sendRequest({
|
||||
url: '/wechat/api/wechat/followqrcode',
|
||||
success: res => {
|
||||
if (res.code >= 0 && res.data) {
|
||||
this.wechatQrcode = res.data.qrcode;
|
||||
// ... 你的原有逻辑 ...
|
||||
},
|
||||
|
||||
// --- 核心修改区域 ---
|
||||
|
||||
/**
|
||||
* 检查隐私协议
|
||||
* 逻辑:只有当 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.$nextTick(() => {
|
||||
const privacyPopup = this.$refs.privacyPopup;
|
||||
if (privacyPopup) {
|
||||
// 强制调用组件的 popUp 方法
|
||||
privacyPopup.popUp();
|
||||
} else {
|
||||
console.error('❌ 找不到 privacyPopup 组件引用');
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
officialAccountsOpen() {
|
||||
this.$refs.officialAccountsPopup.open();
|
||||
},
|
||||
officialAccountsClose() {
|
||||
this.$refs.officialAccountsPopup.close();
|
||||
},
|
||||
// 统一处理点击及触摸事件
|
||||
_handleDiyGroupInteractionEvent(payload) {
|
||||
// #ifdef H5
|
||||
return true;
|
||||
// #endif
|
||||
|
||||
if (this.storeToken) {
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* 处理同意隐私协议
|
||||
* 逻辑:用户点击同意后,我们**主动**写入缓存
|
||||
*/
|
||||
onAgreePrivacy() {
|
||||
console.log('🎉 用户点击了同意');
|
||||
|
||||
this.$refs.login?.open();
|
||||
return false;
|
||||
// 【关键修复】不管组件内部有没有写,我们在这里强制写入缓存
|
||||
uni.setStorageSync('privacyAgreed', true);
|
||||
|
||||
// 标记状态
|
||||
this.hasCheckedPrivacy = true;
|
||||
},
|
||||
|
||||
onDisagreePrivacy() {
|
||||
console.log('🚫 用户拒绝了隐私协议');
|
||||
// 可以在这里处理退出的逻辑
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user