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
|
@@ -98,53 +98,159 @@ var _require = __webpack_require__(1),
|
|
|
98
98
|
getAds = _require.getAds;
|
|
99
99
|
|
|
100
100
|
module.exports = {
|
|
101
|
-
|
|
101
|
+
// 检查并重置每日数据
|
|
102
|
+
checkAndResetDaily: function checkAndResetDaily() {
|
|
102
103
|
var slotId = this.properties.slotId;
|
|
103
104
|
var type = this.properties.type;
|
|
104
|
-
var
|
|
105
|
-
var adShowCountKey = 'adShowCount_' + slotId + '_' + type;
|
|
105
|
+
var dateKey = 'adDate_' + slotId + '_' + type;
|
|
106
106
|
|
|
107
|
-
var
|
|
108
|
-
var
|
|
107
|
+
var today = new Date().toDateString();
|
|
108
|
+
var savedDate = wx.getStorageSync(dateKey);
|
|
109
109
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
110
|
+
// 如果日期不同,重置所有数据
|
|
111
|
+
if (savedDate !== today) {
|
|
112
|
+
var customAdIndexKey = 'customAdIndex_' + slotId + '_' + type;
|
|
113
|
+
var customAdShowCountKey = 'customAdShowCount_' + slotId + '_' + type;
|
|
114
|
+
|
|
115
|
+
wx.setStorageSync(dateKey, today);
|
|
116
|
+
wx.setStorageSync(customAdIndexKey, 1); // 自有广告从索引1开始
|
|
117
|
+
wx.setStorageSync(customAdShowCountKey, 0);
|
|
118
|
+
|
|
119
|
+
return true; // 表示已重置
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return false; // 表示未重置
|
|
123
|
+
},
|
|
124
|
+
restoreAdState: function restoreAdState() {
|
|
125
|
+
// 检查并重置每日数据
|
|
126
|
+
this.checkAndResetDaily();
|
|
114
127
|
},
|
|
115
128
|
saveAdState: function saveAdState() {
|
|
116
129
|
var slotId = this.properties.slotId;
|
|
117
130
|
var type = this.properties.type;
|
|
118
|
-
var
|
|
119
|
-
var
|
|
131
|
+
var customAdIndexKey = 'customAdIndex_' + slotId + '_' + type;
|
|
132
|
+
var customAdShowCountKey = 'customAdShowCount_' + slotId + '_' + type;
|
|
133
|
+
|
|
134
|
+
// 只保存自有广告的状态(索引>0)
|
|
135
|
+
if (this.data.currentAdIndex > 0) {
|
|
136
|
+
wx.setStorageSync(customAdIndexKey, this.data.currentAdIndex);
|
|
137
|
+
wx.setStorageSync(customAdShowCountKey, this.data.currentAdShowCount);
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
// 检查微信广告是否失败(只在内存中,不持久化)
|
|
143
|
+
isWxAdFailed: function isWxAdFailed() {
|
|
144
|
+
return this.data.wxAdFailed || false;
|
|
145
|
+
},
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
// 标记微信广告失败(只在内存中,不持久化)
|
|
149
|
+
markWxAdFailed: function markWxAdFailed() {
|
|
150
|
+
this.setData({
|
|
151
|
+
wxAdFailed: true
|
|
152
|
+
});
|
|
153
|
+
},
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
// 检查所有自有广告是否都达到上限
|
|
157
|
+
isAllCustomAdsReachedLimit: function isAllCustomAdsReachedLimit() {
|
|
158
|
+
var ads = this.data.ads;
|
|
159
|
+
if (!ads || ads.length <= 1) return true; // 只有微信广告或没有广告
|
|
160
|
+
|
|
161
|
+
var currentIndex = this.data.currentAdIndex;
|
|
162
|
+
var showCount = this.data.currentAdShowCount;
|
|
163
|
+
|
|
164
|
+
// 如果当前不是自有广告,返回false
|
|
165
|
+
if (currentIndex === 0) return false;
|
|
166
|
+
|
|
167
|
+
// 找到最后一个有效的自有广告索引
|
|
168
|
+
var lastValidAdIndex = -1;
|
|
169
|
+
for (var i = ads.length - 1; i >= 1; i--) {
|
|
170
|
+
if (ads[i][this.properties.type] !== undefined) {
|
|
171
|
+
lastValidAdIndex = i;
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// 如果没有有效的自有广告,返回true
|
|
177
|
+
if (lastValidAdIndex === -1) return true;
|
|
178
|
+
|
|
179
|
+
// 如果当前索引已经是最后一个有效广告,且达到展示上限,返回true
|
|
180
|
+
if (currentIndex === lastValidAdIndex) {
|
|
181
|
+
var ad = ads[currentIndex];
|
|
182
|
+
var maxShowCount = ad.showCount || 1;
|
|
183
|
+
return showCount >= maxShowCount;
|
|
184
|
+
}
|
|
120
185
|
|
|
121
|
-
|
|
122
|
-
wx.setStorageSync(adShowCountKey, this.data.currentAdShowCount);
|
|
186
|
+
return false;
|
|
123
187
|
},
|
|
124
188
|
loadNextAd: function loadNextAd() {
|
|
125
189
|
var ads = this.data.ads;
|
|
126
190
|
if (!ads || ads.length === 0) return;
|
|
127
191
|
|
|
192
|
+
// 检查并重置每日数据
|
|
193
|
+
this.checkAndResetDaily();
|
|
194
|
+
|
|
128
195
|
var currentIndex = this.data.currentAdIndex;
|
|
129
196
|
var showCount = this.data.currentAdShowCount;
|
|
130
197
|
|
|
131
|
-
|
|
198
|
+
// 如果是微信广告(索引0)且未失败,直接加载微信广告
|
|
199
|
+
if (currentIndex === 0 && !this.isWxAdFailed()) {
|
|
200
|
+
var wxAd = ads[0];
|
|
201
|
+
if (wxAd && wxAd[this.properties.type] !== undefined) {
|
|
202
|
+
this.setData({ currentAd: wxAd });
|
|
203
|
+
return;
|
|
204
|
+
} else {
|
|
205
|
+
// 微信广告没有配置,标记为失败,切换到自有广告
|
|
206
|
+
this.markWxAdFailed();
|
|
207
|
+
currentIndex = 1;
|
|
208
|
+
showCount = 0;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// 如果微信广告失败,从自有广告开始
|
|
213
|
+
if (currentIndex === 0 && this.isWxAdFailed()) {
|
|
214
|
+
// 从存储中恢复自有广告的状态
|
|
215
|
+
var slotId = this.properties.slotId;
|
|
216
|
+
var type = this.properties.type;
|
|
217
|
+
var customAdIndexKey = 'customAdIndex_' + slotId + '_' + type;
|
|
218
|
+
var customAdShowCountKey = 'customAdShowCount_' + slotId + '_' + type;
|
|
219
|
+
|
|
220
|
+
currentIndex = wx.getStorageSync(customAdIndexKey) || 1;
|
|
221
|
+
showCount = wx.getStorageSync(customAdShowCountKey) || 0;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// 如果没有自有广告,不展示任何广告
|
|
225
|
+
if (ads.length <= 1) {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
132
228
|
|
|
133
|
-
|
|
229
|
+
// 检查所有自有广告是否都达到上限
|
|
230
|
+
if (this.isAllCustomAdsReachedLimit()) {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// 处理自有广告的展示次数限制
|
|
235
|
+
var ad = ads[currentIndex];
|
|
236
|
+
var maxShowCount = ad.showCount || 1;
|
|
237
|
+
|
|
238
|
+
// 如果当前自有广告达到展示上限,切换到下一个
|
|
134
239
|
if (showCount >= maxShowCount) {
|
|
135
240
|
currentIndex = currentIndex + 1;
|
|
136
241
|
showCount = 0;
|
|
137
|
-
this.setData({
|
|
138
|
-
currentAdIndex: currentIndex,
|
|
139
|
-
currentAdShowCount: showCount
|
|
140
|
-
});
|
|
141
|
-
this.saveAdState();
|
|
142
|
-
}
|
|
143
242
|
|
|
144
|
-
|
|
145
|
-
|
|
243
|
+
// 如果超出广告列表范围,说明所有广告都达到上限
|
|
244
|
+
if (currentIndex >= ads.length) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
ad = ads[currentIndex];
|
|
249
|
+
}
|
|
146
250
|
|
|
251
|
+
// 检查当前广告是否有配置
|
|
147
252
|
if (ad[this.properties.type] === undefined) {
|
|
253
|
+
// 没有配置,跳过并尝试下一个
|
|
148
254
|
this.setData({
|
|
149
255
|
currentAdIndex: currentIndex + 1,
|
|
150
256
|
currentAdShowCount: 0
|
|
@@ -154,8 +260,11 @@ module.exports = {
|
|
|
154
260
|
return;
|
|
155
261
|
}
|
|
156
262
|
|
|
263
|
+
// 设置当前广告
|
|
157
264
|
this.setData({
|
|
158
|
-
|
|
265
|
+
currentAd: ad,
|
|
266
|
+
currentAdIndex: currentIndex,
|
|
267
|
+
currentAdShowCount: showCount
|
|
159
268
|
});
|
|
160
269
|
this.saveAdState();
|
|
161
270
|
},
|
|
@@ -179,8 +288,22 @@ module.exports = {
|
|
|
179
288
|
this.triggerEvent('adLoad', e.detail || {});
|
|
180
289
|
}
|
|
181
290
|
this.report('load');
|
|
291
|
+
|
|
292
|
+
// 只有自有广告(索引>0)才增加展示计数
|
|
293
|
+
if (this.data.currentAdIndex > 0) {
|
|
294
|
+
var showCount = this.data.currentAdShowCount;
|
|
295
|
+
this.setData({
|
|
296
|
+
currentAdShowCount: showCount + 1
|
|
297
|
+
});
|
|
298
|
+
this.saveAdState();
|
|
299
|
+
}
|
|
182
300
|
},
|
|
183
301
|
adError: function adError(e) {
|
|
302
|
+
// 如果是微信广告(索引0)失败,标记为失败状态
|
|
303
|
+
if (this.data.currentAdIndex === 0) {
|
|
304
|
+
this.markWxAdFailed();
|
|
305
|
+
}
|
|
306
|
+
|
|
184
307
|
if (e === 'undefined') {
|
|
185
308
|
this.triggerEvent('adError', { msg: 'ad adError' });
|
|
186
309
|
} else {
|
|
@@ -222,7 +345,13 @@ module.exports = {
|
|
|
222
345
|
ads = _context.sent;
|
|
223
346
|
|
|
224
347
|
this.setData({ ads: ads });
|
|
225
|
-
|
|
348
|
+
|
|
349
|
+
// 每次初始化时,总是从微信广告开始(索引0)
|
|
350
|
+
this.setData({
|
|
351
|
+
currentAdIndex: 0,
|
|
352
|
+
currentAdShowCount: 0
|
|
353
|
+
});
|
|
354
|
+
|
|
226
355
|
this.loadNextAd();
|
|
227
356
|
|
|
228
357
|
case 7:
|
|
@@ -312,7 +441,8 @@ Component({
|
|
|
312
441
|
ads: [],
|
|
313
442
|
currentAd: {},
|
|
314
443
|
currentAdIndex: 0,
|
|
315
|
-
currentAdShowCount: 0
|
|
444
|
+
currentAdShowCount: 0,
|
|
445
|
+
wxAdFailed: false // 微信广告失败标记(仅内存,不持久化)
|
|
316
446
|
},
|
|
317
447
|
lifetimes: {
|
|
318
448
|
attached: function () {
|
|
@@ -340,6 +470,18 @@ Component({
|
|
|
340
470
|
}()
|
|
341
471
|
},
|
|
342
472
|
methods: {
|
|
473
|
+
checkAndResetDaily: function checkAndResetDaily() {
|
|
474
|
+
return adBase.checkAndResetDaily.call(this);
|
|
475
|
+
},
|
|
476
|
+
isWxAdFailed: function isWxAdFailed() {
|
|
477
|
+
return adBase.isWxAdFailed.call(this);
|
|
478
|
+
},
|
|
479
|
+
markWxAdFailed: function markWxAdFailed() {
|
|
480
|
+
adBase.markWxAdFailed.call(this);
|
|
481
|
+
},
|
|
482
|
+
isAllCustomAdsReachedLimit: function isAllCustomAdsReachedLimit() {
|
|
483
|
+
return adBase.isAllCustomAdsReachedLimit.call(this);
|
|
484
|
+
},
|
|
343
485
|
restoreAdState: function restoreAdState() {
|
|
344
486
|
adBase.restoreAdState.call(this);
|
|
345
487
|
},
|
|
@@ -356,7 +498,8 @@ Component({
|
|
|
356
498
|
adBase.adLoad.call(this, e);
|
|
357
499
|
},
|
|
358
500
|
adError: function adError(e) {
|
|
359
|
-
adBase.adError.call(this, e);
|
|
501
|
+
adBase.adError.call(this, e); // 先标记失败
|
|
502
|
+
this.loadNextAd(); // 再切换广告
|
|
360
503
|
},
|
|
361
504
|
adOpenMiniProgram: function adOpenMiniProgram() {
|
|
362
505
|
adBase.adOpenMiniProgram.call(this);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["webpack:///webpack/bootstrap","webpack:///./src/mixins/ad-base.js","webpack:///./src/request.js","webpack:///./src/ad-banner/index.js"],"names":["require","getAds","module","exports","restoreAdState","slotId","properties","type","adIndexKey","adShowCountKey","savedIndex","wx","getStorageSync","savedShowCount","setData","currentAdIndex","currentAdShowCount","saveAdState","setStorageSync","data","loadNextAd","ads","length","currentIndex","showCount","currentAd","maxShowCount","ad","undefined","report","actionType","source","adId","id","time","Date","getTime","request","url","method","success","fail","adLoad","e","triggerEvent","msg","detail","adError","adOpenMiniProgram","appId","appid","path","navigateToMiniProgram","err","console","error","initAds","pendingRequests","requestCache","Promise","resolve","requestPromise","reject","res","statusCode","Error","errMsg","complete","adBase","Component","String","value","lifetimes","attached","call","methods"],"mappings":";;QAAA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;;QAEA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;;;QAGA;QAC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PY,UAbO,kBAaAC,CAbA,EAaG;AACRyB,aAAO1B,MAAP,CAAcgC,IAAd,CAAmB,IAAnB,EAAyB/B,CAAzB;AACD,KAfM;AAgBPI,WAhBO,mBAgBCJ,CAhBD,EAgBI;AACTyB,aAAOrB,OAAP,CAAe2B,IAAf,CAAoB,IAApB,EAA0B/B,CAA1B;AACD,KAlBM;AAmBPK,qBAnBO,+BAmBa;AAClBoB,aAAOpB,iBAAP,CAAyB0B,IAAzB,CAA8B,IAA9B;AACD;AArBM;AAnBD,CAAV,E","file":"ad-banner\\index.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 2);\n","const {getAds} = require('../request.js')\r\n\r\nmodule.exports = {\r\n restoreAdState() {\r\n const slotId = this.properties.slotId\r\n const type = this.properties.type\r\n const adIndexKey = `adIndex_${slotId}_${type}`\r\n const adShowCountKey = `adShowCount_${slotId}_${type}`\r\n\r\n const savedIndex = wx.getStorageSync(adIndexKey) || 0\r\n const savedShowCount = wx.getStorageSync(adShowCountKey) || 0\r\n\r\n this.setData({\r\n currentAdIndex: savedIndex,\r\n currentAdShowCount: savedShowCount\r\n })\r\n },\r\n\r\n saveAdState() {\r\n const slotId = this.properties.slotId\r\n const type = this.properties.type\r\n const adIndexKey = `adIndex_${slotId}_${type}`\r\n const adShowCountKey = `adShowCount_${slotId}_${type}`\r\n\r\n wx.setStorageSync(adIndexKey, this.data.currentAdIndex)\r\n wx.setStorageSync(adShowCountKey, this.data.currentAdShowCount)\r\n },\r\n\r\n loadNextAd() {\r\n const ads = this.data.ads\r\n if (!ads || ads.length === 0) return\r\n\r\n let currentIndex = this.data.currentAdIndex\r\n let showCount = this.data.currentAdShowCount\r\n\r\n const currentAd = ads[currentIndex % ads.length]\r\n\r\n const maxShowCount = currentAd.showCount || 1\r\n if (showCount >= maxShowCount) {\r\n currentIndex = currentIndex + 1\r\n showCount = 0\r\n this.setData({\r\n currentAdIndex: currentIndex,\r\n currentAdShowCount: showCount\r\n })\r\n this.saveAdState()\r\n }\r\n\r\n const ad = ads[currentIndex % ads.length]\r\n this.setData({currentAd: ad})\r\n\r\n if (ad[this.properties.type] === undefined) {\r\n this.setData({\r\n currentAdIndex: currentIndex + 1,\r\n currentAdShowCount: 0\r\n })\r\n this.saveAdState()\r\n this.loadNextAd()\r\n return\r\n }\r\n\r\n this.setData({\r\n currentAdShowCount: showCount + 1\r\n })\r\n this.saveAdState()\r\n },\r\n\r\n report(actionType) {\r\n const slotId = this.properties.slotId\r\n const type = this.properties.type\r\n const source = this.data.currentAd.source\r\n const adId = this.data.currentAd.id\r\n const time = new Date().getTime()\r\n wx.request({\r\n url: `https://wxgo.adwke.com/api/miniapp/report?slotId=${slotId}&type=${type}&source=${source}&actionType=${actionType}&adId=${adId}&time=${time}`,\r\n method: 'GET',\r\n success() {},\r\n fail() {}\r\n })\r\n },\r\n\r\n adLoad(e) {\r\n if (e === 'undefined') {\r\n this.triggerEvent('adClose', {msg: '广告加载成功'})\r\n } else {\r\n this.triggerEvent('adLoad', e.detail || {})\r\n }\r\n this.report('load')\r\n },\r\n\r\n adError(e) {\r\n if (e === 'undefined') {\r\n this.triggerEvent('adError', {msg: 'ad adError'})\r\n } else {\r\n this.triggerEvent('adError', e)\r\n }\r\n },\r\n\r\n adOpenMiniProgram() {\r\n const ad = this.data.currentAd\r\n const appId = ad[this.properties.type].appid || ''\r\n const path = ad[this.properties.type].path || ''\r\n if (appId) {\r\n wx.navigateToMiniProgram({\r\n appId: appId,\r\n path: path,\r\n success: () => {\r\n this.triggerEvent('adOpenMiniProgram', {appId, path})\r\n },\r\n fail: (err) => {\r\n console.error('跳转小程序失败', err)\r\n }\r\n })\r\n }\r\n this.report('click')\r\n },\r\n\r\n async initAds() {\r\n const slotId = this.properties.slotId\r\n const ads = await getAds(slotId)\r\n this.setData({ads})\r\n this.restoreAdState()\r\n this.loadNextAd()\r\n }\r\n}\r\n","const pendingRequests = {}\r\nconst requestCache = {}\r\n\r\nconst getAds = (slotId) => {\r\n if (requestCache[slotId]) {\r\n return Promise.resolve(requestCache[slotId])\r\n }\r\n\r\n if (pendingRequests[slotId]) {\r\n return pendingRequests[slotId]\r\n }\r\n\r\n const requestPromise = new Promise((resolve, reject) => {\r\n wx.request({\r\n url: `https://wxgo.adwke.com/api/miniapp/getads?slotId=${slotId}`,\r\n method: 'GET',\r\n success: (res) => {\r\n if (res.statusCode === 200 && res.data) {\r\n requestCache[slotId] = res.data.data\r\n resolve(res.data.data)\r\n } else {\r\n reject(new Error(`请求失败: ${res.statusCode} - ${res.errMsg}`))\r\n }\r\n },\r\n fail: (err) => {\r\n reject(err)\r\n },\r\n complete: () => {\r\n delete pendingRequests[slotId]\r\n }\r\n })\r\n })\r\n\r\n pendingRequests[slotId] = requestPromise\r\n return requestPromise\r\n}\r\n\r\nmodule.exports = {\r\n getAds\r\n}\r\n","const adBase = require('../mixins/ad-base.js')\r\n\r\nComponent({\r\n properties: {\r\n slotId: String,\r\n type: {\r\n type: String,\r\n value: 'banner'\r\n }\r\n },\r\n data: {\r\n ads: [],\r\n currentAd: {},\r\n currentAdIndex: 0,\r\n currentAdShowCount: 0\r\n },\r\n lifetimes: {\r\n async attached() {\r\n await adBase.initAds.call(this)\r\n }\r\n },\r\n methods: {\r\n restoreAdState() {\r\n adBase.restoreAdState.call(this)\r\n },\r\n saveAdState() {\r\n adBase.saveAdState.call(this)\r\n },\r\n loadNextAd() {\r\n adBase.loadNextAd.call(this)\r\n },\r\n report(actionType) {\r\n adBase.report.call(this, actionType)\r\n },\r\n adLoad(e) {\r\n adBase.adLoad.call(this, e)\r\n },\r\n adError(e) {\r\n adBase.adError.call(this, e)\r\n },\r\n adOpenMiniProgram() {\r\n adBase.adOpenMiniProgram.call(this)\r\n }\r\n }\r\n})\r\n"],"sourceRoot":""}
|
|
1
|
+
{"version":3,"sources":["webpack:///webpack/bootstrap","webpack:///./src/mixins/ad-base.js","webpack:///./src/request.js","webpack:///./src/ad-banner/index.js"],"names":["require","getAds","module","exports","checkAndResetDaily","slotId","properties","type","dateKey","today","Date","toDateString","savedDate","wx","getStorageSync","customAdIndexKey","customAdShowCountKey","setStorageSync","restoreAdState","saveAdState","data","currentAdIndex","currentAdShowCount","isWxAdFailed","wxAdFailed","markWxAdFailed","setData","isAllCustomAdsReachedLimit","ads","length","currentIndex","showCount","lastValidAdIndex","i","undefined","ad","maxShowCount","loadNextAd","wxAd","currentAd","report","actionType","source","adId","id","time","getTime","request","url","method","success","fail","adLoad","e","triggerEvent","msg","detail","adError","adOpenMiniProgram","appId","appid","path","navigateToMiniProgram","err","console","error","initAds","pendingRequests","requestCache","Promise","resolve","requestPromise","reject","res","statusCode","Error","errMsg","complete","adBase","Component","String","value","lifetimes","attached","call","methods"],"mappings":";;QAAA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;;QAEA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;;;QAGA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA,0CAA0C,gCAAgC;QAC1E;QACA;;QAEA;QACA;QACA;QACA,wDAAwD,kBAAkB;QAC1E;QACA,iDAAiD,cAAc;QAC/D;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA,yCAAyC,iCAAiC;QAC1E,gHAAgH,mBAAmB,EAAE;QACrI;QACA;;QAEA;QACA;QACA;QACA,2BAA2B,0BAA0B,EAAE;QACvD,iCAAiC,eAAe;QAChD;QACA;QACA;;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mBP/C,cAnBO,wBAmBM;AACXyC,aAAOzC,UAAP,CAAkB+C,IAAlB,CAAuB,IAAvB;AACD,KArBM;AAsBP5C,UAtBO,kBAsBAC,UAtBA,EAsBY;AACjBqC,aAAOtC,MAAP,CAAc4C,IAAd,CAAmB,IAAnB,EAAyB3C,UAAzB;AACD,KAxBM;AAyBPW,UAzBO,kBAyBAC,CAzBA,EAyBG;AACRyB,aAAO1B,MAAP,CAAcgC,IAAd,CAAmB,IAAnB,EAAyB/B,CAAzB;AACD,KA3BM;AA4BPI,WA5BO,mBA4BCJ,CA5BD,EA4BI;AACTyB,aAAOrB,OAAP,CAAe2B,IAAf,CAAoB,IAApB,EAA0B/B,CAA1B,EADS,CACqB;AAC9B,WAAKhB,UAAL,GAFS,CAEsB;AAChC,KA/BM;AAgCPqB,qBAhCO,+BAgCa;AAClBoB,aAAOpB,iBAAP,CAAyB0B,IAAzB,CAA8B,IAA9B;AACD;AAlCM;AApBD,CAAV,E","file":"ad-banner\\index.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 2);\n","const {getAds} = require('../request.js')\r\n\r\nmodule.exports = {\r\n // 检查并重置每日数据\r\n checkAndResetDaily() {\r\n const slotId = this.properties.slotId\r\n const type = this.properties.type\r\n const dateKey = `adDate_${slotId}_${type}`\r\n\r\n const today = new Date().toDateString()\r\n const savedDate = wx.getStorageSync(dateKey)\r\n\r\n // 如果日期不同,重置所有数据\r\n if (savedDate !== today) {\r\n const customAdIndexKey = `customAdIndex_${slotId}_${type}`\r\n const customAdShowCountKey = `customAdShowCount_${slotId}_${type}`\r\n\r\n wx.setStorageSync(dateKey, today)\r\n wx.setStorageSync(customAdIndexKey, 1) // 自有广告从索引1开始\r\n wx.setStorageSync(customAdShowCountKey, 0)\r\n\r\n return true // 表示已重置\r\n }\r\n\r\n return false // 表示未重置\r\n },\r\n\r\n restoreAdState() {\r\n // 检查并重置每日数据\r\n this.checkAndResetDaily()\r\n },\r\n\r\n saveAdState() {\r\n const slotId = this.properties.slotId\r\n const type = this.properties.type\r\n const customAdIndexKey = `customAdIndex_${slotId}_${type}`\r\n const customAdShowCountKey = `customAdShowCount_${slotId}_${type}`\r\n\r\n // 只保存自有广告的状态(索引>0)\r\n if (this.data.currentAdIndex > 0) {\r\n wx.setStorageSync(customAdIndexKey, this.data.currentAdIndex)\r\n wx.setStorageSync(customAdShowCountKey, this.data.currentAdShowCount)\r\n }\r\n },\r\n\r\n // 检查微信广告是否失败(只在内存中,不持久化)\r\n isWxAdFailed() {\r\n return this.data.wxAdFailed || false\r\n },\r\n\r\n // 标记微信广告失败(只在内存中,不持久化)\r\n markWxAdFailed() {\r\n this.setData({\r\n wxAdFailed: true\r\n })\r\n },\r\n\r\n // 检查所有自有广告是否都达到上限\r\n isAllCustomAdsReachedLimit() {\r\n const ads = this.data.ads\r\n if (!ads || ads.length <= 1) return true // 只有微信广告或没有广告\r\n\r\n const currentIndex = this.data.currentAdIndex\r\n const showCount = this.data.currentAdShowCount\r\n\r\n // 如果当前不是自有广告,返回false\r\n if (currentIndex === 0) return false\r\n\r\n // 找到最后一个有效的自有广告索引\r\n let lastValidAdIndex = -1\r\n for (let i = ads.length - 1; i >= 1; i--) {\r\n if (ads[i][this.properties.type] !== undefined) {\r\n lastValidAdIndex = i\r\n break\r\n }\r\n }\r\n\r\n // 如果没有有效的自有广告,返回true\r\n if (lastValidAdIndex === -1) return true\r\n\r\n // 如果当前索引已经是最后一个有效广告,且达到展示上限,返回true\r\n if (currentIndex === lastValidAdIndex) {\r\n const ad = ads[currentIndex]\r\n const maxShowCount = ad.showCount || 1\r\n return showCount >= maxShowCount\r\n }\r\n\r\n return false\r\n },\r\n\r\n loadNextAd() {\r\n const ads = this.data.ads\r\n if (!ads || ads.length === 0) return\r\n\r\n // 检查并重置每日数据\r\n this.checkAndResetDaily()\r\n\r\n let currentIndex = this.data.currentAdIndex\r\n let showCount = this.data.currentAdShowCount\r\n\r\n // 如果是微信广告(索引0)且未失败,直接加载微信广告\r\n if (currentIndex === 0 && !this.isWxAdFailed()) {\r\n const wxAd = ads[0]\r\n if (wxAd && wxAd[this.properties.type] !== undefined) {\r\n this.setData({currentAd: wxAd})\r\n return\r\n } else {\r\n // 微信广告没有配置,标记为失败,切换到自有广告\r\n this.markWxAdFailed()\r\n currentIndex = 1\r\n showCount = 0\r\n }\r\n }\r\n\r\n // 如果微信广告失败,从自有广告开始\r\n if (currentIndex === 0 && this.isWxAdFailed()) {\r\n // 从存储中恢复自有广告的状态\r\n const slotId = this.properties.slotId\r\n const type = this.properties.type\r\n const customAdIndexKey = `customAdIndex_${slotId}_${type}`\r\n const customAdShowCountKey = `customAdShowCount_${slotId}_${type}`\r\n\r\n currentIndex = wx.getStorageSync(customAdIndexKey) || 1\r\n showCount = wx.getStorageSync(customAdShowCountKey) || 0\r\n }\r\n\r\n // 如果没有自有广告,不展示任何广告\r\n if (ads.length <= 1) {\r\n return\r\n }\r\n\r\n // 检查所有自有广告是否都达到上限\r\n if (this.isAllCustomAdsReachedLimit()) {\r\n return\r\n }\r\n\r\n // 处理自有广告的展示次数限制\r\n let ad = ads[currentIndex]\r\n const maxShowCount = ad.showCount || 1\r\n\r\n // 如果当前自有广告达到展示上限,切换到下一个\r\n if (showCount >= maxShowCount) {\r\n currentIndex = currentIndex + 1\r\n showCount = 0\r\n\r\n // 如果超出广告列表范围,说明所有广告都达到上限\r\n if (currentIndex >= ads.length) {\r\n return\r\n }\r\n\r\n ad = ads[currentIndex]\r\n }\r\n\r\n // 检查当前广告是否有配置\r\n if (ad[this.properties.type] === undefined) {\r\n // 没有配置,跳过并尝试下一个\r\n this.setData({\r\n currentAdIndex: currentIndex + 1,\r\n currentAdShowCount: 0\r\n })\r\n this.saveAdState()\r\n this.loadNextAd()\r\n return\r\n }\r\n\r\n // 设置当前广告\r\n this.setData({\r\n currentAd: ad,\r\n currentAdIndex: currentIndex,\r\n currentAdShowCount: showCount\r\n })\r\n this.saveAdState()\r\n },\r\n\r\n report(actionType) {\r\n const slotId = this.properties.slotId\r\n const type = this.properties.type\r\n const source = this.data.currentAd.source\r\n const adId = this.data.currentAd.id\r\n const time = new Date().getTime()\r\n wx.request({\r\n url: `https://wxgo.adwke.com/api/miniapp/report?slotId=${slotId}&type=${type}&source=${source}&actionType=${actionType}&adId=${adId}&time=${time}`,\r\n method: 'GET',\r\n success() {},\r\n fail() {}\r\n })\r\n },\r\n\r\n adLoad(e) {\r\n if (e === 'undefined') {\r\n this.triggerEvent('adClose', {msg: '广告加载成功'})\r\n } else {\r\n this.triggerEvent('adLoad', e.detail || {})\r\n }\r\n this.report('load')\r\n\r\n // 只有自有广告(索引>0)才增加展示计数\r\n if (this.data.currentAdIndex > 0) {\r\n const showCount = this.data.currentAdShowCount\r\n this.setData({\r\n currentAdShowCount: showCount + 1\r\n })\r\n this.saveAdState()\r\n }\r\n },\r\n\r\n adError(e) {\r\n // 如果是微信广告(索引0)失败,标记为失败状态\r\n if (this.data.currentAdIndex === 0) {\r\n this.markWxAdFailed()\r\n }\r\n\r\n if (e === 'undefined') {\r\n this.triggerEvent('adError', {msg: 'ad adError'})\r\n } else {\r\n this.triggerEvent('adError', e)\r\n }\r\n },\r\n\r\n adOpenMiniProgram() {\r\n const ad = this.data.currentAd\r\n const appId = ad[this.properties.type].appid || ''\r\n const path = ad[this.properties.type].path || ''\r\n if (appId) {\r\n wx.navigateToMiniProgram({\r\n appId: appId,\r\n path: path,\r\n success: () => {\r\n this.triggerEvent('adOpenMiniProgram', {appId, path})\r\n },\r\n fail: (err) => {\r\n console.error('跳转小程序失败', err)\r\n }\r\n })\r\n }\r\n this.report('click')\r\n },\r\n\r\n async initAds() {\r\n const slotId = this.properties.slotId\r\n const ads = await getAds(slotId)\r\n this.setData({ads})\r\n\r\n // 每次初始化时,总是从微信广告开始(索引0)\r\n this.setData({\r\n currentAdIndex: 0,\r\n currentAdShowCount: 0\r\n })\r\n\r\n this.loadNextAd()\r\n }\r\n}\r\n","const pendingRequests = {}\r\nconst requestCache = {}\r\n\r\nconst getAds = (slotId) => {\r\n if (requestCache[slotId]) {\r\n return Promise.resolve(requestCache[slotId])\r\n }\r\n\r\n if (pendingRequests[slotId]) {\r\n return pendingRequests[slotId]\r\n }\r\n\r\n const requestPromise = new Promise((resolve, reject) => {\r\n wx.request({\r\n url: `https://wxgo.adwke.com/api/miniapp/getads?slotId=${slotId}`,\r\n method: 'GET',\r\n success: (res) => {\r\n if (res.statusCode === 200 && res.data) {\r\n requestCache[slotId] = res.data.data\r\n resolve(res.data.data)\r\n } else {\r\n reject(new Error(`请求失败: ${res.statusCode} - ${res.errMsg}`))\r\n }\r\n },\r\n fail: (err) => {\r\n reject(err)\r\n },\r\n complete: () => {\r\n delete pendingRequests[slotId]\r\n }\r\n })\r\n })\r\n\r\n pendingRequests[slotId] = requestPromise\r\n return requestPromise\r\n}\r\n\r\nmodule.exports = {\r\n getAds\r\n}\r\n","const adBase = require('../mixins/ad-base.js')\r\n\r\nComponent({\r\n properties: {\r\n slotId: String,\r\n type: {\r\n type: String,\r\n value: 'banner'\r\n }\r\n },\r\n data: {\r\n ads: [],\r\n currentAd: {},\r\n currentAdIndex: 0,\r\n currentAdShowCount: 0,\r\n wxAdFailed: false // 微信广告失败标记(仅内存,不持久化)\r\n },\r\n lifetimes: {\r\n async attached() {\r\n await adBase.initAds.call(this)\r\n }\r\n },\r\n methods: {\r\n checkAndResetDaily() {\r\n return adBase.checkAndResetDaily.call(this)\r\n },\r\n isWxAdFailed() {\r\n return adBase.isWxAdFailed.call(this)\r\n },\r\n markWxAdFailed() {\r\n adBase.markWxAdFailed.call(this)\r\n },\r\n isAllCustomAdsReachedLimit() {\r\n return adBase.isAllCustomAdsReachedLimit.call(this)\r\n },\r\n restoreAdState() {\r\n adBase.restoreAdState.call(this)\r\n },\r\n saveAdState() {\r\n adBase.saveAdState.call(this)\r\n },\r\n loadNextAd() {\r\n adBase.loadNextAd.call(this)\r\n },\r\n report(actionType) {\r\n adBase.report.call(this, actionType)\r\n },\r\n adLoad(e) {\r\n adBase.adLoad.call(this, e)\r\n },\r\n adError(e) {\r\n adBase.adError.call(this, e) // 先标记失败\r\n this.loadNextAd(); // 再切换广告\r\n },\r\n adOpenMiniProgram() {\r\n adBase.adOpenMiniProgram.call(this)\r\n }\r\n }\r\n})\r\n"],"sourceRoot":""}
|
|
@@ -98,53 +98,159 @@ var _require = __webpack_require__(1),
|
|
|
98
98
|
getAds = _require.getAds;
|
|
99
99
|
|
|
100
100
|
module.exports = {
|
|
101
|
-
|
|
101
|
+
// 检查并重置每日数据
|
|
102
|
+
checkAndResetDaily: function checkAndResetDaily() {
|
|
102
103
|
var slotId = this.properties.slotId;
|
|
103
104
|
var type = this.properties.type;
|
|
104
|
-
var
|
|
105
|
-
var adShowCountKey = 'adShowCount_' + slotId + '_' + type;
|
|
105
|
+
var dateKey = 'adDate_' + slotId + '_' + type;
|
|
106
106
|
|
|
107
|
-
var
|
|
108
|
-
var
|
|
107
|
+
var today = new Date().toDateString();
|
|
108
|
+
var savedDate = wx.getStorageSync(dateKey);
|
|
109
109
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
110
|
+
// 如果日期不同,重置所有数据
|
|
111
|
+
if (savedDate !== today) {
|
|
112
|
+
var customAdIndexKey = 'customAdIndex_' + slotId + '_' + type;
|
|
113
|
+
var customAdShowCountKey = 'customAdShowCount_' + slotId + '_' + type;
|
|
114
|
+
|
|
115
|
+
wx.setStorageSync(dateKey, today);
|
|
116
|
+
wx.setStorageSync(customAdIndexKey, 1); // 自有广告从索引1开始
|
|
117
|
+
wx.setStorageSync(customAdShowCountKey, 0);
|
|
118
|
+
|
|
119
|
+
return true; // 表示已重置
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return false; // 表示未重置
|
|
123
|
+
},
|
|
124
|
+
restoreAdState: function restoreAdState() {
|
|
125
|
+
// 检查并重置每日数据
|
|
126
|
+
this.checkAndResetDaily();
|
|
114
127
|
},
|
|
115
128
|
saveAdState: function saveAdState() {
|
|
116
129
|
var slotId = this.properties.slotId;
|
|
117
130
|
var type = this.properties.type;
|
|
118
|
-
var
|
|
119
|
-
var
|
|
131
|
+
var customAdIndexKey = 'customAdIndex_' + slotId + '_' + type;
|
|
132
|
+
var customAdShowCountKey = 'customAdShowCount_' + slotId + '_' + type;
|
|
133
|
+
|
|
134
|
+
// 只保存自有广告的状态(索引>0)
|
|
135
|
+
if (this.data.currentAdIndex > 0) {
|
|
136
|
+
wx.setStorageSync(customAdIndexKey, this.data.currentAdIndex);
|
|
137
|
+
wx.setStorageSync(customAdShowCountKey, this.data.currentAdShowCount);
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
// 检查微信广告是否失败(只在内存中,不持久化)
|
|
143
|
+
isWxAdFailed: function isWxAdFailed() {
|
|
144
|
+
return this.data.wxAdFailed || false;
|
|
145
|
+
},
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
// 标记微信广告失败(只在内存中,不持久化)
|
|
149
|
+
markWxAdFailed: function markWxAdFailed() {
|
|
150
|
+
this.setData({
|
|
151
|
+
wxAdFailed: true
|
|
152
|
+
});
|
|
153
|
+
},
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
// 检查所有自有广告是否都达到上限
|
|
157
|
+
isAllCustomAdsReachedLimit: function isAllCustomAdsReachedLimit() {
|
|
158
|
+
var ads = this.data.ads;
|
|
159
|
+
if (!ads || ads.length <= 1) return true; // 只有微信广告或没有广告
|
|
160
|
+
|
|
161
|
+
var currentIndex = this.data.currentAdIndex;
|
|
162
|
+
var showCount = this.data.currentAdShowCount;
|
|
120
163
|
|
|
121
|
-
|
|
122
|
-
|
|
164
|
+
// 如果当前不是自有广告,返回false
|
|
165
|
+
if (currentIndex === 0) return false;
|
|
166
|
+
|
|
167
|
+
// 找到最后一个有效的自有广告索引
|
|
168
|
+
var lastValidAdIndex = -1;
|
|
169
|
+
for (var i = ads.length - 1; i >= 1; i--) {
|
|
170
|
+
if (ads[i][this.properties.type] !== undefined) {
|
|
171
|
+
lastValidAdIndex = i;
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// 如果没有有效的自有广告,返回true
|
|
177
|
+
if (lastValidAdIndex === -1) return true;
|
|
178
|
+
|
|
179
|
+
// 如果当前索引已经是最后一个有效广告,且达到展示上限,返回true
|
|
180
|
+
if (currentIndex === lastValidAdIndex) {
|
|
181
|
+
var ad = ads[currentIndex];
|
|
182
|
+
var maxShowCount = ad.showCount || 1;
|
|
183
|
+
return showCount >= maxShowCount;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return false;
|
|
123
187
|
},
|
|
124
188
|
loadNextAd: function loadNextAd() {
|
|
125
189
|
var ads = this.data.ads;
|
|
126
190
|
if (!ads || ads.length === 0) return;
|
|
127
191
|
|
|
192
|
+
// 检查并重置每日数据
|
|
193
|
+
this.checkAndResetDaily();
|
|
194
|
+
|
|
128
195
|
var currentIndex = this.data.currentAdIndex;
|
|
129
196
|
var showCount = this.data.currentAdShowCount;
|
|
130
197
|
|
|
131
|
-
|
|
198
|
+
// 如果是微信广告(索引0)且未失败,直接加载微信广告
|
|
199
|
+
if (currentIndex === 0 && !this.isWxAdFailed()) {
|
|
200
|
+
var wxAd = ads[0];
|
|
201
|
+
if (wxAd && wxAd[this.properties.type] !== undefined) {
|
|
202
|
+
this.setData({ currentAd: wxAd });
|
|
203
|
+
return;
|
|
204
|
+
} else {
|
|
205
|
+
// 微信广告没有配置,标记为失败,切换到自有广告
|
|
206
|
+
this.markWxAdFailed();
|
|
207
|
+
currentIndex = 1;
|
|
208
|
+
showCount = 0;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// 如果微信广告失败,从自有广告开始
|
|
213
|
+
if (currentIndex === 0 && this.isWxAdFailed()) {
|
|
214
|
+
// 从存储中恢复自有广告的状态
|
|
215
|
+
var slotId = this.properties.slotId;
|
|
216
|
+
var type = this.properties.type;
|
|
217
|
+
var customAdIndexKey = 'customAdIndex_' + slotId + '_' + type;
|
|
218
|
+
var customAdShowCountKey = 'customAdShowCount_' + slotId + '_' + type;
|
|
219
|
+
|
|
220
|
+
currentIndex = wx.getStorageSync(customAdIndexKey) || 1;
|
|
221
|
+
showCount = wx.getStorageSync(customAdShowCountKey) || 0;
|
|
222
|
+
}
|
|
132
223
|
|
|
133
|
-
|
|
224
|
+
// 如果没有自有广告,不展示任何广告
|
|
225
|
+
if (ads.length <= 1) {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// 检查所有自有广告是否都达到上限
|
|
230
|
+
if (this.isAllCustomAdsReachedLimit()) {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// 处理自有广告的展示次数限制
|
|
235
|
+
var ad = ads[currentIndex];
|
|
236
|
+
var maxShowCount = ad.showCount || 1;
|
|
237
|
+
|
|
238
|
+
// 如果当前自有广告达到展示上限,切换到下一个
|
|
134
239
|
if (showCount >= maxShowCount) {
|
|
135
240
|
currentIndex = currentIndex + 1;
|
|
136
241
|
showCount = 0;
|
|
137
|
-
this.setData({
|
|
138
|
-
currentAdIndex: currentIndex,
|
|
139
|
-
currentAdShowCount: showCount
|
|
140
|
-
});
|
|
141
|
-
this.saveAdState();
|
|
142
|
-
}
|
|
143
242
|
|
|
144
|
-
|
|
145
|
-
|
|
243
|
+
// 如果超出广告列表范围,说明所有广告都达到上限
|
|
244
|
+
if (currentIndex >= ads.length) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
146
247
|
|
|
248
|
+
ad = ads[currentIndex];
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// 检查当前广告是否有配置
|
|
147
252
|
if (ad[this.properties.type] === undefined) {
|
|
253
|
+
// 没有配置,跳过并尝试下一个
|
|
148
254
|
this.setData({
|
|
149
255
|
currentAdIndex: currentIndex + 1,
|
|
150
256
|
currentAdShowCount: 0
|
|
@@ -154,8 +260,11 @@ module.exports = {
|
|
|
154
260
|
return;
|
|
155
261
|
}
|
|
156
262
|
|
|
263
|
+
// 设置当前广告
|
|
157
264
|
this.setData({
|
|
158
|
-
|
|
265
|
+
currentAd: ad,
|
|
266
|
+
currentAdIndex: currentIndex,
|
|
267
|
+
currentAdShowCount: showCount
|
|
159
268
|
});
|
|
160
269
|
this.saveAdState();
|
|
161
270
|
},
|
|
@@ -179,8 +288,22 @@ module.exports = {
|
|
|
179
288
|
this.triggerEvent('adLoad', e.detail || {});
|
|
180
289
|
}
|
|
181
290
|
this.report('load');
|
|
291
|
+
|
|
292
|
+
// 只有自有广告(索引>0)才增加展示计数
|
|
293
|
+
if (this.data.currentAdIndex > 0) {
|
|
294
|
+
var showCount = this.data.currentAdShowCount;
|
|
295
|
+
this.setData({
|
|
296
|
+
currentAdShowCount: showCount + 1
|
|
297
|
+
});
|
|
298
|
+
this.saveAdState();
|
|
299
|
+
}
|
|
182
300
|
},
|
|
183
301
|
adError: function adError(e) {
|
|
302
|
+
// 如果是微信广告(索引0)失败,标记为失败状态
|
|
303
|
+
if (this.data.currentAdIndex === 0) {
|
|
304
|
+
this.markWxAdFailed();
|
|
305
|
+
}
|
|
306
|
+
|
|
184
307
|
if (e === 'undefined') {
|
|
185
308
|
this.triggerEvent('adError', { msg: 'ad adError' });
|
|
186
309
|
} else {
|
|
@@ -222,7 +345,13 @@ module.exports = {
|
|
|
222
345
|
ads = _context.sent;
|
|
223
346
|
|
|
224
347
|
this.setData({ ads: ads });
|
|
225
|
-
|
|
348
|
+
|
|
349
|
+
// 每次初始化时,总是从微信广告开始(索引0)
|
|
350
|
+
this.setData({
|
|
351
|
+
currentAdIndex: 0,
|
|
352
|
+
currentAdShowCount: 0
|
|
353
|
+
});
|
|
354
|
+
|
|
226
355
|
this.loadNextAd();
|
|
227
356
|
|
|
228
357
|
case 7:
|
|
@@ -324,7 +453,8 @@ Component({
|
|
|
324
453
|
currentAd: {},
|
|
325
454
|
currentAdIndex: 0,
|
|
326
455
|
currentAdShowCount: 0,
|
|
327
|
-
isshow: false
|
|
456
|
+
isshow: false,
|
|
457
|
+
wxAdFailed: false // 微信广告失败标记(仅内存,不持久化)
|
|
328
458
|
},
|
|
329
459
|
lifetimes: {
|
|
330
460
|
attached: function () {
|
|
@@ -355,6 +485,18 @@ Component({
|
|
|
355
485
|
}()
|
|
356
486
|
},
|
|
357
487
|
methods: {
|
|
488
|
+
checkAndResetDaily: function checkAndResetDaily() {
|
|
489
|
+
return adBase.checkAndResetDaily.call(this);
|
|
490
|
+
},
|
|
491
|
+
isWxAdFailed: function isWxAdFailed() {
|
|
492
|
+
return adBase.isWxAdFailed.call(this);
|
|
493
|
+
},
|
|
494
|
+
markWxAdFailed: function markWxAdFailed() {
|
|
495
|
+
adBase.markWxAdFailed.call(this);
|
|
496
|
+
},
|
|
497
|
+
isAllCustomAdsReachedLimit: function isAllCustomAdsReachedLimit() {
|
|
498
|
+
return adBase.isAllCustomAdsReachedLimit.call(this);
|
|
499
|
+
},
|
|
358
500
|
restoreAdState: function restoreAdState() {
|
|
359
501
|
adBase.restoreAdState.call(this);
|
|
360
502
|
},
|
|
@@ -371,7 +513,8 @@ Component({
|
|
|
371
513
|
adBase.adLoad.call(this, e);
|
|
372
514
|
},
|
|
373
515
|
adError: function adError(e) {
|
|
374
|
-
adBase.adError.call(this, e);
|
|
516
|
+
adBase.adError.call(this, e); // 先标记失败
|
|
517
|
+
this.loadNextAd(); // 再切换广告
|
|
375
518
|
},
|
|
376
519
|
adOpenMiniProgram: function adOpenMiniProgram() {
|
|
377
520
|
adBase.adOpenMiniProgram.call(this);
|
|
@@ -416,8 +559,8 @@ Component({
|
|
|
416
559
|
this.interstitialAd.destroy();
|
|
417
560
|
this.interstitialAd = null;
|
|
418
561
|
}
|
|
419
|
-
this.loadNextAd()
|
|
420
|
-
this.loadInterstitial()
|
|
562
|
+
// this.loadNextAd()
|
|
563
|
+
// this.loadInterstitial()
|
|
421
564
|
},
|
|
422
565
|
handleClose: function handleClose() {
|
|
423
566
|
this.setData({ isshow: false });
|