Skip to content

Commit fa31047

Browse files
author
youngboyliu
committed
fix: 广告
1 parent 79be7b8 commit fa31047

27 files changed

Lines changed: 999 additions & 209 deletions

miniprogram/app.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
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"
813
],
914
"usingComponents": {
1015
"mp-navigation-bar": "/component/navigation-bar/navigation-bar"
@@ -484,6 +489,12 @@
484489
"iconPath": "@iconPathCloud",
485490
"selectedIconPath": "@selectedIconPathCloud",
486491
"text": "云开发"
492+
},
493+
{
494+
"pagePath": "page/ad/index",
495+
"iconPath": "@iconPathAd",
496+
"selectedIconPath": "@selectedIconPathAd",
497+
"text": "广告"
487498
}
488499
]
489500
},

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

653 Bytes
Loading

miniprogram/image/icon_ad_HL.png

688 Bytes
Loading

miniprogram/image/icon_ad_dark.png

1.23 KB
Loading

miniprogram/page/ad/index.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
const typeMap = {
67+
optimize: '广告调优',
68+
hosting: '广告托管',
69+
custom: '自主开发'
70+
}
71+
wx.showToast({
72+
title: `点击了${typeMap[type]}`,
73+
icon: 'none'
74+
})
75+
}
76+
})
77+

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+
}
3 KB
Loading

0 commit comments

Comments
 (0)