jyj-components 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +9 -0
- package/README.md +223 -69
- package/miniprogram_dist/ad-banner/index.js +170 -27
- package/miniprogram_dist/ad-banner/index.js.map +1 -1
- package/miniprogram_dist/ad-interstitial/index.js +172 -29
- package/miniprogram_dist/ad-interstitial/index.js.map +1 -1
- package/miniprogram_dist/ad-rewarded-video/index.js +168 -26
- package/miniprogram_dist/ad-rewarded-video/index.js.map +1 -1
- package/miniprogram_dist/ad-splash/index.js +304 -39
- package/miniprogram_dist/ad-splash/index.js.map +1 -1
- package/miniprogram_dist/ad-splash/index.wxml +1 -1
- package/miniprogram_dist/ad-splash/index.wxss +0 -1
- package/package.json +1 -1
- package/src/ad-banner/index.js +16 -2
- package/src/ad-interstitial/index.js +18 -4
- package/src/ad-rewarded-video/index.js +14 -1
- package/src/ad-splash/index.js +83 -3
- package/src/ad-splash/index.wxml +1 -1
- package/src/ad-splash/index.wxss +0 -1
- package/src/mixins/ad-base.js +152 -25
- package/miniprogram_dist/assets/copy.wxss +0 -3
- package/miniprogram_dist/assets/icon.png +0 -0
- package/miniprogram_dist/utils.js +0 -5
- package/src/assets/copy.wxss +0 -3
- package/src/assets/icon.png +0 -0
- package/src/common.wxss +0 -5
- package/src/index.js +0 -24
- package/src/index.json +0 -9
- package/src/index.wxml +0 -2
- package/src/index.wxss +0 -6
- package/src/lib.ts +0 -5
- package/src/reset.wxss +0 -3
- package/src/utils.js +0 -5
|
@@ -22,7 +22,8 @@ Component({
|
|
|
22
22
|
ads: [],
|
|
23
23
|
currentAd: {},
|
|
24
24
|
currentAdIndex: 0,
|
|
25
|
-
currentAdShowCount: 0
|
|
25
|
+
currentAdShowCount: 0,
|
|
26
|
+
wxAdFailed: false // 微信广告失败标记(仅内存,不持久化)
|
|
26
27
|
},
|
|
27
28
|
lifetimes: {
|
|
28
29
|
async attached() {
|
|
@@ -31,6 +32,18 @@ Component({
|
|
|
31
32
|
}
|
|
32
33
|
},
|
|
33
34
|
methods: {
|
|
35
|
+
checkAndResetDaily() {
|
|
36
|
+
return adBase.checkAndResetDaily.call(this)
|
|
37
|
+
},
|
|
38
|
+
isWxAdFailed() {
|
|
39
|
+
return adBase.isWxAdFailed.call(this)
|
|
40
|
+
},
|
|
41
|
+
markWxAdFailed() {
|
|
42
|
+
adBase.markWxAdFailed.call(this)
|
|
43
|
+
},
|
|
44
|
+
isAllCustomAdsReachedLimit() {
|
|
45
|
+
return adBase.isAllCustomAdsReachedLimit.call(this)
|
|
46
|
+
},
|
|
34
47
|
restoreAdState() {
|
|
35
48
|
adBase.restoreAdState.call(this)
|
|
36
49
|
},
|
package/src/ad-splash/index.js
CHANGED
|
@@ -14,15 +14,52 @@ Component({
|
|
|
14
14
|
currentAdIndex: 0,
|
|
15
15
|
currentAdShowCount: 0,
|
|
16
16
|
countDown: 5,
|
|
17
|
-
splashStatus: true
|
|
17
|
+
splashStatus: true,
|
|
18
|
+
adBannerTop: 60,
|
|
19
|
+
wxAdFailed: false // 微信广告失败标记(仅内存,不持久化)
|
|
18
20
|
},
|
|
19
21
|
lifetimes: {
|
|
20
22
|
async attached() {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
this.calculateAdBannerTop()
|
|
24
|
+
|
|
25
|
+
const canUse = this.canUseCoverAdAPI()
|
|
26
|
+
|
|
27
|
+
if (canUse){
|
|
28
|
+
setTimeout(() => {
|
|
29
|
+
wx.getShowSplashAdStatus({
|
|
30
|
+
success: async res => {
|
|
31
|
+
if (res.status === 'fail'){
|
|
32
|
+
await adBase.initAds.call(this)
|
|
33
|
+
this.startCountDown()
|
|
34
|
+
} else {
|
|
35
|
+
this.jump()
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
fail: async err => {
|
|
39
|
+
await adBase.initAds.call(this)
|
|
40
|
+
this.startCountDown()
|
|
41
|
+
}
|
|
42
|
+
})
|
|
43
|
+
}, 100)
|
|
44
|
+
} else {
|
|
45
|
+
await adBase.initAds.call(this)
|
|
46
|
+
this.startCountDown()
|
|
47
|
+
}
|
|
23
48
|
}
|
|
24
49
|
},
|
|
25
50
|
methods: {
|
|
51
|
+
checkAndResetDaily() {
|
|
52
|
+
return adBase.checkAndResetDaily.call(this)
|
|
53
|
+
},
|
|
54
|
+
isWxAdFailed() {
|
|
55
|
+
return adBase.isWxAdFailed.call(this)
|
|
56
|
+
},
|
|
57
|
+
markWxAdFailed() {
|
|
58
|
+
adBase.markWxAdFailed.call(this)
|
|
59
|
+
},
|
|
60
|
+
isAllCustomAdsReachedLimit() {
|
|
61
|
+
return adBase.isAllCustomAdsReachedLimit.call(this)
|
|
62
|
+
},
|
|
26
63
|
restoreAdState() {
|
|
27
64
|
adBase.restoreAdState.call(this)
|
|
28
65
|
},
|
|
@@ -55,6 +92,49 @@ Component({
|
|
|
55
92
|
}, 1100)
|
|
56
93
|
},
|
|
57
94
|
|
|
95
|
+
calculateAdBannerTop() {
|
|
96
|
+
try {
|
|
97
|
+
const menuRect = wx.getMenuButtonBoundingClientRect();
|
|
98
|
+
const systemInfo = wx.getSystemInfoSync();
|
|
99
|
+
|
|
100
|
+
const isCustomNavBar = (systemInfo.screenHeight === systemInfo.windowHeight);
|
|
101
|
+
|
|
102
|
+
let top
|
|
103
|
+
if (isCustomNavBar) {
|
|
104
|
+
top = menuRect.bottom + 10
|
|
105
|
+
} else {
|
|
106
|
+
top = systemInfo.statusBarHeight + 20
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const topInRpx = top * 750 / systemInfo.windowWidth
|
|
110
|
+
|
|
111
|
+
this.setData({
|
|
112
|
+
adBannerTop: topInRpx
|
|
113
|
+
})
|
|
114
|
+
} catch (err) {
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
|
|
118
|
+
compareVersion(v1, v2) {
|
|
119
|
+
const s1 = v1.split('.').map(Number);
|
|
120
|
+
const s2 = v2.split('.').map(Number);
|
|
121
|
+
const len = Math.max(s1.length, s2.length);
|
|
122
|
+
|
|
123
|
+
for (let i = 0; i < len; i++) {
|
|
124
|
+
const n1 = s1[i] || 0;
|
|
125
|
+
const n2 = s2[i] || 0;
|
|
126
|
+
if (n1 > n2) return 1;
|
|
127
|
+
if (n1 < n2) return -1;
|
|
128
|
+
}
|
|
129
|
+
return 0;
|
|
130
|
+
},
|
|
131
|
+
canUseCoverAdAPI() {
|
|
132
|
+
const REQUIRED_VERSION = '3.7.8';
|
|
133
|
+
const systemInfo = wx.getSystemInfoSync();
|
|
134
|
+
const sdkVersion = systemInfo.SDKVersion;
|
|
135
|
+
return this.compareVersion(sdkVersion, REQUIRED_VERSION) >= 0;
|
|
136
|
+
},
|
|
137
|
+
|
|
58
138
|
jump() {
|
|
59
139
|
this.setData({
|
|
60
140
|
splashStatus: false
|
package/src/ad-splash/index.wxml
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<view wx:if="{{splashStatus && currentAd.splash.unitId}}" class="splash-container">
|
|
2
|
-
<view class="ad-banner-top">
|
|
2
|
+
<view class="ad-banner-top" style="top: {{adBannerTop}}rpx;">
|
|
3
3
|
<text class="ad-tag">广告</text>
|
|
4
4
|
<text class="ad-timer">{{countDown}} 秒</text>
|
|
5
5
|
<view class="skip-btn" bindtap="jump">跳过</view>
|
package/src/ad-splash/index.wxss
CHANGED
package/src/mixins/ad-base.js
CHANGED
|
@@ -1,55 +1,159 @@
|
|
|
1
1
|
const {getAds} = require('../request.js')
|
|
2
2
|
|
|
3
3
|
module.exports = {
|
|
4
|
-
|
|
4
|
+
// 检查并重置每日数据
|
|
5
|
+
checkAndResetDaily() {
|
|
5
6
|
const slotId = this.properties.slotId
|
|
6
7
|
const type = this.properties.type
|
|
7
|
-
const
|
|
8
|
-
const adShowCountKey = `adShowCount_${slotId}_${type}`
|
|
8
|
+
const dateKey = `adDate_${slotId}_${type}`
|
|
9
9
|
|
|
10
|
-
const
|
|
11
|
-
const
|
|
10
|
+
const today = new Date().toDateString()
|
|
11
|
+
const savedDate = wx.getStorageSync(dateKey)
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
// 如果日期不同,重置所有数据
|
|
14
|
+
if (savedDate !== today) {
|
|
15
|
+
const customAdIndexKey = `customAdIndex_${slotId}_${type}`
|
|
16
|
+
const customAdShowCountKey = `customAdShowCount_${slotId}_${type}`
|
|
17
|
+
|
|
18
|
+
wx.setStorageSync(dateKey, today)
|
|
19
|
+
wx.setStorageSync(customAdIndexKey, 1) // 自有广告从索引1开始
|
|
20
|
+
wx.setStorageSync(customAdShowCountKey, 0)
|
|
21
|
+
|
|
22
|
+
return true // 表示已重置
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return false // 表示未重置
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
restoreAdState() {
|
|
29
|
+
// 检查并重置每日数据
|
|
30
|
+
this.checkAndResetDaily()
|
|
17
31
|
},
|
|
18
32
|
|
|
19
33
|
saveAdState() {
|
|
20
34
|
const slotId = this.properties.slotId
|
|
21
35
|
const type = this.properties.type
|
|
22
|
-
const
|
|
23
|
-
const
|
|
36
|
+
const customAdIndexKey = `customAdIndex_${slotId}_${type}`
|
|
37
|
+
const customAdShowCountKey = `customAdShowCount_${slotId}_${type}`
|
|
24
38
|
|
|
25
|
-
|
|
26
|
-
|
|
39
|
+
// 只保存自有广告的状态(索引>0)
|
|
40
|
+
if (this.data.currentAdIndex > 0) {
|
|
41
|
+
wx.setStorageSync(customAdIndexKey, this.data.currentAdIndex)
|
|
42
|
+
wx.setStorageSync(customAdShowCountKey, this.data.currentAdShowCount)
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
// 检查微信广告是否失败(只在内存中,不持久化)
|
|
47
|
+
isWxAdFailed() {
|
|
48
|
+
return this.data.wxAdFailed || false
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
// 标记微信广告失败(只在内存中,不持久化)
|
|
52
|
+
markWxAdFailed() {
|
|
53
|
+
this.setData({
|
|
54
|
+
wxAdFailed: true
|
|
55
|
+
})
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
// 检查所有自有广告是否都达到上限
|
|
59
|
+
isAllCustomAdsReachedLimit() {
|
|
60
|
+
const ads = this.data.ads
|
|
61
|
+
if (!ads || ads.length <= 1) return true // 只有微信广告或没有广告
|
|
62
|
+
|
|
63
|
+
const currentIndex = this.data.currentAdIndex
|
|
64
|
+
const showCount = this.data.currentAdShowCount
|
|
65
|
+
|
|
66
|
+
// 如果当前不是自有广告,返回false
|
|
67
|
+
if (currentIndex === 0) return false
|
|
68
|
+
|
|
69
|
+
// 找到最后一个有效的自有广告索引
|
|
70
|
+
let lastValidAdIndex = -1
|
|
71
|
+
for (let i = ads.length - 1; i >= 1; i--) {
|
|
72
|
+
if (ads[i][this.properties.type] !== undefined) {
|
|
73
|
+
lastValidAdIndex = i
|
|
74
|
+
break
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// 如果没有有效的自有广告,返回true
|
|
79
|
+
if (lastValidAdIndex === -1) return true
|
|
80
|
+
|
|
81
|
+
// 如果当前索引已经是最后一个有效广告,且达到展示上限,返回true
|
|
82
|
+
if (currentIndex === lastValidAdIndex) {
|
|
83
|
+
const ad = ads[currentIndex]
|
|
84
|
+
const maxShowCount = ad.showCount || 1
|
|
85
|
+
return showCount >= maxShowCount
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return false
|
|
27
89
|
},
|
|
28
90
|
|
|
29
91
|
loadNextAd() {
|
|
30
92
|
const ads = this.data.ads
|
|
31
93
|
if (!ads || ads.length === 0) return
|
|
32
94
|
|
|
95
|
+
// 检查并重置每日数据
|
|
96
|
+
this.checkAndResetDaily()
|
|
97
|
+
|
|
33
98
|
let currentIndex = this.data.currentAdIndex
|
|
34
99
|
let showCount = this.data.currentAdShowCount
|
|
35
100
|
|
|
36
|
-
|
|
101
|
+
// 如果是微信广告(索引0)且未失败,直接加载微信广告
|
|
102
|
+
if (currentIndex === 0 && !this.isWxAdFailed()) {
|
|
103
|
+
const wxAd = ads[0]
|
|
104
|
+
if (wxAd && wxAd[this.properties.type] !== undefined) {
|
|
105
|
+
this.setData({currentAd: wxAd})
|
|
106
|
+
return
|
|
107
|
+
} else {
|
|
108
|
+
// 微信广告没有配置,标记为失败,切换到自有广告
|
|
109
|
+
this.markWxAdFailed()
|
|
110
|
+
currentIndex = 1
|
|
111
|
+
showCount = 0
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// 如果微信广告失败,从自有广告开始
|
|
116
|
+
if (currentIndex === 0 && this.isWxAdFailed()) {
|
|
117
|
+
// 从存储中恢复自有广告的状态
|
|
118
|
+
const slotId = this.properties.slotId
|
|
119
|
+
const type = this.properties.type
|
|
120
|
+
const customAdIndexKey = `customAdIndex_${slotId}_${type}`
|
|
121
|
+
const customAdShowCountKey = `customAdShowCount_${slotId}_${type}`
|
|
122
|
+
|
|
123
|
+
currentIndex = wx.getStorageSync(customAdIndexKey) || 1
|
|
124
|
+
showCount = wx.getStorageSync(customAdShowCountKey) || 0
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// 如果没有自有广告,不展示任何广告
|
|
128
|
+
if (ads.length <= 1) {
|
|
129
|
+
return
|
|
130
|
+
}
|
|
37
131
|
|
|
38
|
-
|
|
132
|
+
// 检查所有自有广告是否都达到上限
|
|
133
|
+
if (this.isAllCustomAdsReachedLimit()) {
|
|
134
|
+
return
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// 处理自有广告的展示次数限制
|
|
138
|
+
let ad = ads[currentIndex]
|
|
139
|
+
const maxShowCount = ad.showCount || 1
|
|
140
|
+
|
|
141
|
+
// 如果当前自有广告达到展示上限,切换到下一个
|
|
39
142
|
if (showCount >= maxShowCount) {
|
|
40
143
|
currentIndex = currentIndex + 1
|
|
41
144
|
showCount = 0
|
|
42
|
-
this.setData({
|
|
43
|
-
currentAdIndex: currentIndex,
|
|
44
|
-
currentAdShowCount: showCount
|
|
45
|
-
})
|
|
46
|
-
this.saveAdState()
|
|
47
|
-
}
|
|
48
145
|
|
|
49
|
-
|
|
50
|
-
|
|
146
|
+
// 如果超出广告列表范围,说明所有广告都达到上限
|
|
147
|
+
if (currentIndex >= ads.length) {
|
|
148
|
+
return
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
ad = ads[currentIndex]
|
|
152
|
+
}
|
|
51
153
|
|
|
154
|
+
// 检查当前广告是否有配置
|
|
52
155
|
if (ad[this.properties.type] === undefined) {
|
|
156
|
+
// 没有配置,跳过并尝试下一个
|
|
53
157
|
this.setData({
|
|
54
158
|
currentAdIndex: currentIndex + 1,
|
|
55
159
|
currentAdShowCount: 0
|
|
@@ -59,8 +163,11 @@ module.exports = {
|
|
|
59
163
|
return
|
|
60
164
|
}
|
|
61
165
|
|
|
166
|
+
// 设置当前广告
|
|
62
167
|
this.setData({
|
|
63
|
-
|
|
168
|
+
currentAd: ad,
|
|
169
|
+
currentAdIndex: currentIndex,
|
|
170
|
+
currentAdShowCount: showCount
|
|
64
171
|
})
|
|
65
172
|
this.saveAdState()
|
|
66
173
|
},
|
|
@@ -86,9 +193,23 @@ module.exports = {
|
|
|
86
193
|
this.triggerEvent('adLoad', e.detail || {})
|
|
87
194
|
}
|
|
88
195
|
this.report('load')
|
|
196
|
+
|
|
197
|
+
// 只有自有广告(索引>0)才增加展示计数
|
|
198
|
+
if (this.data.currentAdIndex > 0) {
|
|
199
|
+
const showCount = this.data.currentAdShowCount
|
|
200
|
+
this.setData({
|
|
201
|
+
currentAdShowCount: showCount + 1
|
|
202
|
+
})
|
|
203
|
+
this.saveAdState()
|
|
204
|
+
}
|
|
89
205
|
},
|
|
90
206
|
|
|
91
207
|
adError(e) {
|
|
208
|
+
// 如果是微信广告(索引0)失败,标记为失败状态
|
|
209
|
+
if (this.data.currentAdIndex === 0) {
|
|
210
|
+
this.markWxAdFailed()
|
|
211
|
+
}
|
|
212
|
+
|
|
92
213
|
if (e === 'undefined') {
|
|
93
214
|
this.triggerEvent('adError', {msg: 'ad adError'})
|
|
94
215
|
} else {
|
|
@@ -119,7 +240,13 @@ module.exports = {
|
|
|
119
240
|
const slotId = this.properties.slotId
|
|
120
241
|
const ads = await getAds(slotId)
|
|
121
242
|
this.setData({ads})
|
|
122
|
-
|
|
243
|
+
|
|
244
|
+
// 每次初始化时,总是从微信广告开始(索引0)
|
|
245
|
+
this.setData({
|
|
246
|
+
currentAdIndex: 0,
|
|
247
|
+
currentAdShowCount: 0
|
|
248
|
+
})
|
|
249
|
+
|
|
123
250
|
this.loadNextAd()
|
|
124
251
|
}
|
|
125
252
|
}
|
|
Binary file
|
package/src/assets/copy.wxss
DELETED
package/src/assets/icon.png
DELETED
|
Binary file
|
package/src/common.wxss
DELETED
package/src/index.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
const _ = require('./utils')
|
|
2
|
-
|
|
3
|
-
Component({
|
|
4
|
-
properties: {
|
|
5
|
-
prop: {
|
|
6
|
-
type: String,
|
|
7
|
-
value: 'index.properties'
|
|
8
|
-
},
|
|
9
|
-
},
|
|
10
|
-
data: {
|
|
11
|
-
flag: false,
|
|
12
|
-
},
|
|
13
|
-
lifetimes: {
|
|
14
|
-
attached() {
|
|
15
|
-
wx.getSystemInfo({
|
|
16
|
-
success: () => {
|
|
17
|
-
this.setData({
|
|
18
|
-
flag: _.getFlag(),
|
|
19
|
-
})
|
|
20
|
-
}
|
|
21
|
-
})
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
})
|
package/src/index.json
DELETED
package/src/index.wxml
DELETED
package/src/index.wxss
DELETED
package/src/lib.ts
DELETED
package/src/reset.wxss
DELETED