chore:启动广告,后台开启首次弹出,第一次进入小程序后会弹出广告,

后台开启每次弹出,每次重新进入小程序都会弹出广告
This commit is contained in:
2026-10-10 11:35:55 +08:00
parent 447f7cd7b5
commit b14032149e

View File

@@ -299,16 +299,25 @@ export default {
async: false
});
this.adv = res.value
// 弹框形式(后台"首次弹出"等配置), 这里统一为: 每次(重新)进入小程序都弹出
// 通过 App 层"重新进入"信号 + 首屏首次加载来判定, 不再依赖持久化缓存计数,
// 否则关闭广告后计数变为 -1, 第二次进入不会弹出, 必须清缓存才能再弹。
// 后台配置: advshow=1 开启启动广告; advtype 决定弹出策略
// advtype == 1: 首次弹出 —— 仅第一次进入小程序弹出(持久化标记, 清缓存后可再弹)
// advtype == 0: 每次弹出 —— 每次"重新进入小程序"都弹出(不含 Tab 切换回首页)
if (this.adv.advshow == 1) {
setTimeout(() => {
if (!this.$refs.uniPopupWindow) return;
const reenter = consumeNeedStartupAd(); // 从后台切回 / "重新进入小程序"
const firstLaunch = isColdLaunchPending(); // 本 app 进程首次冷启动(只一次)
if (reenter || firstLaunch) {
this.$refs.uniPopupWindow.open();
if (res.value.advtype == 1) {
// 首次弹出: 从未展示过才弹
var popwindow_count = uni.getStorageSync(this.id + this.name + '_popwindow_count');
if (popwindow_count == '' || popwindow_count == 0) {
this.$refs.uniPopupWindow.open();
uni.setStorageSync(this.id + this.name + '_popwindow_count', 1);
}
} else {
// 每次弹出: 冷启动首次 或 真正"重新进入小程序"(App 前后台切换)时弹出,
// 由 App.onShow 在重新进入时置位的信号驱动, 切 Tab 不会触发 App.onShow 故不弹
if (consumeNeedStartupAd() || isColdLaunchPending()) {
this.$refs.uniPopupWindow.open();
}
}
}, 500);
}