Skip to content

Commit 4c9e7be

Browse files
committed
add: <ad> rewarded-video-ad API
1 parent 94178c2 commit 4c9e7be

File tree

5 files changed

+206
-6
lines changed

5 files changed

+206
-6
lines changed

pages.json

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,15 @@
250250
"style": {
251251
"navigationBarTitleText": "web-view"
252252
}
253-
},
253+
},
254+
// #ifndef H5 || MP-BAIDU
255+
{
256+
"path" : "pages/component/ad/ad",
257+
"style" : {
258+
"navigationBarTitleText": "AD"
259+
}
260+
},
261+
// #endif
254262
// #ifdef APP-PLUS
255263
{
256264
"path": "pages/component/web-view-local/web-view-local",
@@ -605,7 +613,15 @@
605613
"style": {
606614
"navigationBarTitleText": "SQLite"
607615
}
608-
},
616+
},
617+
// #ifdef APP-PLUS || MP-WEIXIN
618+
{
619+
"path" : "rewarded-video-ad/rewarded-video-ad",
620+
"style" : {
621+
"navigationBarTitleText": "激励视频广告"
622+
}
623+
},
624+
// #endif
609625
// #ifndef H5
610626
{
611627
"path": "brightness/brightness",
@@ -1166,4 +1182,4 @@
11661182
}
11671183
]
11681184
}
1169-
}
1185+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<template>
2+
<view>
3+
<page-head :title="title"></page-head>
4+
<view class="uni-padding-wrap uni-common-mt">
5+
<button type="primary" class="btn" @click="show">显示广告</button>
6+
</view>
7+
<!-- #ifndef APP-PLUS -->
8+
<view class="ad-tips">
9+
<text>小程序端的广告ID由小程序平台提供</text>
10+
</view>
11+
<!-- #endif -->
12+
</view>
13+
</template>
14+
15+
<script>
16+
export default {
17+
data() {
18+
return {
19+
title: '激励视频广告'
20+
}
21+
},
22+
onReady() {
23+
// #ifdef APP-PLUS
24+
this.adOption = {
25+
adpid: '1507000689'
26+
};
27+
// #endif
28+
// #ifdef MP-WEIXIN
29+
this.adOption = {
30+
adUnitId: ''
31+
};
32+
// #endif
33+
this.createAd();
34+
},
35+
methods: {
36+
createAd() {
37+
var rewardedVideoAd = this.rewardedVideoAd = uni.createRewardedVideoAd(this.adOption);
38+
rewardedVideoAd.onLoad(() => {
39+
console.log('onLoad event')
40+
});
41+
rewardedVideoAd.onClose((res) => {
42+
// 用户点击了【关闭广告】按钮
43+
if (res && res.isEnded) {
44+
// 正常播放结束
45+
console.log("onClose " + res.isEnded);
46+
} else {
47+
// 播放中途退出
48+
console.log("onClose " + res.isEnded);
49+
}
50+
51+
setTimeout(() => {
52+
uni.showToast({
53+
title: "激励视频" + (res.isEnded ? "成功" : "") + "播放完毕",
54+
duration: 10000,
55+
position: 'bottom'
56+
})
57+
}, 500)
58+
});
59+
rewardedVideoAd.onError((err) => {
60+
console.log('onError event', err)
61+
});
62+
},
63+
show() {
64+
const rewardedVideoAd = this.rewardedVideoAd;
65+
rewardedVideoAd.show().catch(() => {
66+
rewardedVideoAd.load()
67+
.then(() => rewardedVideoAd.show())
68+
.catch(err => {
69+
console.log('激励视频 广告显示失败', err)
70+
uni.showToast({
71+
title: err.errMsg || err.message,
72+
duration: 5000,
73+
position: 'bottom'
74+
})
75+
})
76+
})
77+
}
78+
}
79+
}
80+
</script>
81+
82+
<style>
83+
.btn {
84+
margin-bottom: 20px;
85+
}
86+
87+
.ad-tips {
88+
color: #999;
89+
padding: 30px 0;
90+
text-align: center;
91+
}
92+
</style>

pages/component/ad/ad.vue

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<template>
2+
<view>
3+
<page-head :title="title"></page-head>
4+
<view class="ad-view">
5+
<ad adpid="1111111111" :unit-id="unitId" type="feed" @load="adload"></ad>
6+
<!-- #ifdef APP-PLUS -->
7+
<view class="ad-tips" v-if="!isLoad">
8+
<text>广告加载中...</text>
9+
</view>
10+
<!-- #endif -->
11+
<!-- #ifndef APP-PLUS -->
12+
<view class="ad-tips">
13+
<text>小程序端的广告ID由小程序平台提供</text>
14+
</view>
15+
<!-- #endif -->
16+
</view>
17+
<view class="tips" @click="gotoapi">
18+
<text>本示例页面仅演示ad组件,可点此体验激励视频API</text>
19+
</view>
20+
</view>
21+
</template>
22+
23+
<script>
24+
export default {
25+
data() {
26+
return {
27+
title: 'AD组件',
28+
unitId: '',
29+
isLoad: false
30+
}
31+
},
32+
onLoad() {
33+
// #ifdef MP-WEIXIN
34+
this.unitId = '';
35+
// #endif
36+
// #ifdef MP-TOUTIAO
37+
this.unitId = ''
38+
// #endif
39+
// #ifdef MP-QQ
40+
this.unitId = ''
41+
// #endif
42+
},
43+
methods: {
44+
adload() {
45+
this.isLoad = true;
46+
},
47+
gotoapi() {
48+
uni.navigateTo({
49+
url: "/pages/API/rewarded-video-ad/rewarded-video-ad"
50+
})
51+
}
52+
}
53+
}
54+
</script>
55+
56+
<style>
57+
.content {
58+
background-color: #DBDBDB;
59+
padding: 10px;
60+
}
61+
62+
.ad-view {
63+
background-color: #FFFFFF;
64+
margin-bottom: 10px;
65+
}
66+
67+
.ad-tips {
68+
color: #999;
69+
padding: 30px 0;
70+
text-align: center;
71+
}
72+
73+
.tips {
74+
margin-top: 30px;
75+
color: #999;
76+
text-align: center;
77+
}
78+
</style>

pages/tabBar/API/API.nvue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<view class="uni-panel" v-for="(item, index) in list" :key="item.id">
1616
<view class="uni-panel-h" :class="item.open ? 'uni-panel-h-on' : ''" @click="triggerCollapse(index)">
1717
<text class="uni-panel-text">{{item.name}}</text>
18-
<text class="uni-panel-icon uni-icon" :class="item.open ? 'uni-panel-icon-on' : ''">&#xe581;</text>
18+
<text class="uni-panel-icon uni-icon" :class="item.open ? 'uni-panel-icon-on' : ''">{{item.pages ? '&#xe581;' : '&#xe470;'}}</text>
1919
</view>
2020
<view class="uni-panel-c" v-if="item.open">
2121
<view class="uni-navigate-item" v-for="(item2,key) in item.pages" :key="key" :url="item.url" @click="goDetailPage(item2.url)">
@@ -300,6 +300,13 @@
300300
// #endif
301301
]
302302
},
303+
// #ifdef APP-PLUS || MP-WEIXIN
304+
{
305+
url: 'rewarded-video-ad',
306+
name: '激励视频广告',
307+
open: false
308+
},
309+
// #endif
303310
// #ifndef H5
304311
{
305312
id: 'login',

pages/tabBar/component/component.nvue

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<view class="uni-panel" v-for="(item, index) in list" :key="item.id">
1212
<view class="uni-panel-h" :class="item.open ? 'uni-panel-h-on' : ''" @click="triggerCollapse(index)">
1313
<text class="uni-panel-text">{{item.name}}</text>
14-
<text class="uni-panel-icon uni-icon" :class="item.open ? 'uni-panel-icon-on' : ''">&#xe581;</text>
14+
<text class="uni-panel-icon uni-icon" :class="item.open ? 'uni-panel-icon-on' : ''">{{item.pages ? '&#xe581;' : '&#xe470;'}}</text>
1515
</view>
1616
<view class="uni-panel-c" v-if="item.open">
1717
<view class="uni-navigate-item" v-for="(item2,key) in item.pages" :key="key" @click="goDetailPage(item2)">
@@ -100,7 +100,7 @@
100100
name: '画布',
101101
open: false,
102102
pages: ['canvas']
103-
103+
104104
},
105105
// #ifdef APP-PLUS
106106
{
@@ -124,6 +124,13 @@
124124
pages: ['web-view']
125125
},
126126
// #endif
127+
// #ifndef H5 || MP-BAIDU
128+
{
129+
url: 'ad',
130+
name: 'AD组件',
131+
open: false
132+
},
133+
// #endif
127134
],
128135
navigateFlag: false
129136
}

0 commit comments

Comments
 (0)