47 lines
1.2 KiB
JavaScript
47 lines
1.2 KiB
JavaScript
// app.js
|
|
App({
|
|
globalData: {
|
|
userInfo: null,
|
|
isAdPopupVisible: false
|
|
},
|
|
onLaunch() {
|
|
// 展示本地存储能力
|
|
const logs = wx.getStorageSync('logs') || []
|
|
logs.unshift(Date.now())
|
|
wx.setStorageSync('logs', logs)
|
|
|
|
// 登录
|
|
wx.login({
|
|
success: res => {
|
|
// 发送 res.code 到后台换取 openId, sessionKey, unionId
|
|
}
|
|
})
|
|
},
|
|
// 显示广告弹窗
|
|
showAdPopup(imageUrl) {
|
|
this.globalData.isAdPopupVisible = true;
|
|
this.globalData.adImageUrl = imageUrl;
|
|
// 通知所有页面更新弹窗状态
|
|
this.updateAdPopup();
|
|
},
|
|
|
|
// 关闭广告弹窗
|
|
hideAdPopup() {
|
|
this.globalData.isAdPopupVisible = false;
|
|
this.updateAdPopup();
|
|
},
|
|
|
|
// 更新所有页面的弹窗状态
|
|
updateAdPopup() {
|
|
console.log("显示广告")
|
|
const pages = getCurrentPages();
|
|
pages.forEach(page => {
|
|
if (page.setData) {
|
|
page.setData({
|
|
isAdPopupVisible: this.globalData.isAdPopupVisible,
|
|
adImageUrl: this.globalData.adImageUrl
|
|
});
|
|
}
|
|
});
|
|
}
|
|
}) |