Skip to content

Commit 2a26477

Browse files
authored
Merge pull request #190 from wechat-miniprogram/feat-yb-ad-new
Feat yb ad new
2 parents c77e082 + 3db98d9 commit 2a26477

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1784
-209
lines changed

miniprogram/app.json

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,17 @@
44
"page/API/index",
55
"page/cloud/index",
66
"page/extend/index",
7-
"page/animation/index"
7+
"page/animation/index",
8+
"page/ad/index",
9+
"page/ad/smart-ad/smart-ad",
10+
"page/ad/smart-ad/example1/example1",
11+
"page/ad/smart-ad/example2/example2",
12+
"page/ad/smart-ad/example3/example3",
13+
"page/ad/optimize-ad/optimize-ad",
14+
"page/ad/optimize-ad/home-small-card/home-small-card",
15+
"page/ad/optimize-ad/home-large-card/home-large-card",
16+
"page/ad/optimize-ad/other-small-card/other-small-card",
17+
"page/ad/optimize-ad/other-large-card/other-large-card"
818
],
919
"usingComponents": {
1020
"mp-navigation-bar": "/component/navigation-bar/navigation-bar"
@@ -484,6 +494,12 @@
484494
"iconPath": "@iconPathCloud",
485495
"selectedIconPath": "@selectedIconPathCloud",
486496
"text": "云开发"
497+
},
498+
{
499+
"pagePath": "page/ad/index",
500+
"iconPath": "@iconPathAd",
501+
"selectedIconPath": "@selectedIconPathAd",
502+
"text": "广告"
487503
}
488504
]
489505
},

miniprogram/demo.theme.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
"selectedIconPathAPI": "image/icon_API_HL.png",
1616
"iconPathCloud": "image/icon_cloud.png",
1717
"selectedIconPathCloud": "image/icon_cloud_HL.png",
18+
"iconPathAd": "image/icon_ad.png",
19+
"selectedIconPathAd": "image/icon_ad_HL.png",
1820

1921
"backgroundTextStyle": "dark"
2022
},
@@ -34,6 +36,8 @@
3436
"selectedIconPathAPI": "image/icon_API_HL.png",
3537
"iconPathCloud": "image/icon_cloud_dark.png",
3638
"selectedIconPathCloud": "image/icon_cloud_HL.png",
39+
"iconPathAd": "image/icon_ad_dark.png",
40+
"selectedIconPathAd": "image/icon_ad_HL.png",
3741

3842
"backgroundTextStyle": "light"
3943
}

miniprogram/image/icon_ad.png

3.56 KB
Loading

miniprogram/image/icon_ad_HL.png

3.44 KB
Loading

miniprogram/image/icon_ad_dark.png

3.55 KB
Loading

miniprogram/page/ad/index.js

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

miniprogram/page/ad/index.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"navigationBarTitleText": "广告",
3+
"renderer": "webview"
4+
}
5+

miniprogram/page/ad/index.wxml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<view class="page" data-weui-theme="{{theme}}">
2+
<view class="index">
3+
<view class="index-hd">
4+
<image class="index-logo" src="/image/wechat.png"></image>
5+
<text class="index-desc">微信广告是微信官方提供的广告投放平台,帮助开发者通过小程序实现流量变现。支持多种广告形式,包括 Banner 广告、激励视频广告、插屏广告、原生模板广告等。</text>
6+
</view>
7+
<view class="index-bd">
8+
<view class="kind-list">
9+
<view class="kind-list-item">
10+
<view class="kind-list-item-hd" bindtap="onItemTap" data-type="smart">
11+
<view class="kind-list-text">智能广告</view>
12+
<image class="kind-list-img" src="resources/kind/logo.png"></image>
13+
</view>
14+
</view>
15+
<view class="kind-list-item">
16+
<view class="kind-list-item-hd" bindtap="onItemTap" data-type="optimize">
17+
<view class="kind-list-text">广告调优</view>
18+
<image class="kind-list-img" src="resources/kind/logo.png"></image>
19+
</view>
20+
</view>
21+
<view class="kind-list-item">
22+
<view class="kind-list-item-hd" bindtap="onItemTap" data-type="hosting">
23+
<view class="kind-list-text">广告托管</view>
24+
<image class="kind-list-img" src="resources/kind/logo.png"></image>
25+
</view>
26+
</view>
27+
<view class="kind-list-item">
28+
<view class="kind-list-item-hd" bindtap="onItemTap" data-type="custom">
29+
<view class="kind-list-text">自主开发</view>
30+
<image class="kind-list-img" src="resources/kind/logo.png"></image>
31+
</view>
32+
</view>
33+
</view>
34+
</view>
35+
</view>
36+
</view>
37+

miniprogram/page/ad/index.wxss

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@import "../../common/reset.wxss";
2+
@import "../common/index.wxss";
3+
4+
.index-logo {
5+
display: block;
6+
margin: 0 auto;
7+
}
8+
9+
.kind-list-item-hd {
10+
display: flex;
11+
flex-direction: row;
12+
align-items: center;
13+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// 广告调优测试-首页大卡
2+
Page({
3+
data: {
4+
theme: 'light'
5+
},
6+
7+
onShareAppMessage() {
8+
return {
9+
title: '广告调优测试-首页大卡',
10+
path: 'page/ad/optimize-ad/home-large-card/home-large-card'
11+
}
12+
},
13+
14+
onUnload() {
15+
if (wx.offThemeChange) {
16+
wx.offThemeChange()
17+
}
18+
},
19+
20+
onLoad(options) {
21+
this.setData({
22+
theme: getApp().globalData.theme || 'light'
23+
})
24+
25+
if (wx.onThemeChange) {
26+
wx.onThemeChange(({ theme }) => {
27+
this.setData({ theme })
28+
})
29+
}
30+
},
31+
32+
/**
33+
* 广告加载成功回调
34+
*/
35+
onadload(e) {
36+
console.log('广告加载成功:', e)
37+
},
38+
39+
/**
40+
* 广告加载失败回调
41+
*/
42+
onaderror(e) {
43+
console.log('广告加载失败:', e)
44+
},
45+
46+
/**
47+
* 广告视频结束回调
48+
*/
49+
onvideoended(e) {
50+
console.log('广告视频播放结束:', e)
51+
}
52+
})
53+

0 commit comments

Comments
 (0)