-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathindex.js
More file actions
81 lines (73 loc) · 1.56 KB
/
index.js
File metadata and controls
81 lines (73 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
let interstitialAd = null
Page({
onShareAppMessage() {
return {
title: '微信广告展示',
path: 'page/ad/index'
}
},
data: {
theme: 'light'
},
onUnload() {
if (wx.offThemeChange) {
wx.offThemeChange()
}
},
onLoad() {
this.setData({
theme: getApp().globalData.theme || 'light'
})
if (wx.onThemeChange) {
wx.onThemeChange(({ theme }) => {
this.setData({ theme })
})
}
// 创建插屏广告
if (wx.createInterstitialAd) {
interstitialAd = wx.createInterstitialAd({
adUnitId: 'adunit-7c0acfb6438237aa'
})
interstitialAd.onLoad(() => {
console.log('插屏广告加载成功')
})
interstitialAd.onError((err) => {
console.error('插屏广告加载失败', err)
})
interstitialAd.onClose(() => {
console.log('插屏广告关闭')
})
}
},
onShow() {
// 显示插屏广告
if (interstitialAd) {
interstitialAd.show().catch((err) => {
console.error('插屏广告显示失败', err)
})
}
},
onItemTap(e) {
const type = e.currentTarget.dataset.type
if (type === 'smart') {
wx.navigateTo({
url: '/page/ad/smart-ad/smart-ad'
})
return
}
if (type === 'optimize') {
wx.navigateTo({
url: '/page/ad/optimize-ad/optimize-ad'
})
return
}
const typeMap = {
hosting: '广告托管',
custom: '自主开发'
}
wx.showToast({
title: '稍后上线',
icon: 'none'
})
}
})