@dcloudio/uni-cli-shared 2.0.2-alpha-5010420260626002 → 2.0.2-alpha-5020120260710001
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/components/ad.mixin.mp-weixin.js +372 -20
- package/components/half-screen-modal.js +121 -0
- package/components/uniad.vue +5 -2
- package/package.json +2 -2
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
/* eslint-disable no-undef */
|
|
2
|
+
import {
|
|
3
|
+
canShowHalfScreenModal,
|
|
4
|
+
isHalfScreenModalShowing,
|
|
5
|
+
markHalfScreenModalConfirmed,
|
|
6
|
+
markHalfScreenModalDismissed,
|
|
7
|
+
markHalfScreenModalShowing,
|
|
8
|
+
queueHalfScreenModalOpenOptions,
|
|
9
|
+
resetHalfScreenModalSession,
|
|
10
|
+
resolveHalfScreenModalContent,
|
|
11
|
+
takePendingHalfScreenModalOpenOptions,
|
|
12
|
+
unlockHalfScreenModalShowing
|
|
13
|
+
} from './half-screen-modal.js'
|
|
14
|
+
|
|
2
15
|
const adPlugin = requirePlugin('uni-ad')
|
|
3
16
|
|
|
4
17
|
const EventType = {
|
|
@@ -16,7 +29,8 @@ const AdType = {
|
|
|
16
29
|
const ProviderType = {
|
|
17
30
|
WeChat: 10018,
|
|
18
31
|
UserWeChat: 10017,
|
|
19
|
-
ShanHu: 10020
|
|
32
|
+
ShanHu: 10020,
|
|
33
|
+
HalfScreen: 10032
|
|
20
34
|
}
|
|
21
35
|
|
|
22
36
|
const ActionType = {
|
|
@@ -26,6 +40,11 @@ const ActionType = {
|
|
|
26
40
|
Click: '41'
|
|
27
41
|
}
|
|
28
42
|
|
|
43
|
+
/** 微信广告无填充错误码 */
|
|
44
|
+
const WxAdErrorCode = {
|
|
45
|
+
NoFill: 1004
|
|
46
|
+
}
|
|
47
|
+
|
|
29
48
|
export default {
|
|
30
49
|
options: {
|
|
31
50
|
virtualHost: true
|
|
@@ -75,16 +94,20 @@ export default {
|
|
|
75
94
|
userUnitId: '',
|
|
76
95
|
customFullscreen: '',
|
|
77
96
|
wxchannel: false,
|
|
78
|
-
errorMessage: null
|
|
97
|
+
errorMessage: null,
|
|
98
|
+
isHalfScreen: false
|
|
79
99
|
}
|
|
80
100
|
},
|
|
81
101
|
created () {
|
|
102
|
+
resetHalfScreenModalSession()
|
|
82
103
|
this._ad = null
|
|
83
104
|
this._loading = false
|
|
84
105
|
this._wxRewardedAd = null
|
|
85
106
|
this._wxInterstitialAd = null
|
|
86
107
|
this._userInvokeShowFlag = false
|
|
87
108
|
this._providerType = ProviderType.ShanHu
|
|
109
|
+
this._halfScreenOpening = false
|
|
110
|
+
this._halfScreenOpeningTimer = null
|
|
88
111
|
if (this.preload && this._canCreateAd()) {
|
|
89
112
|
this.load()
|
|
90
113
|
}
|
|
@@ -106,6 +129,11 @@ export default {
|
|
|
106
129
|
|
|
107
130
|
show (e) {
|
|
108
131
|
this.errorMessage = null
|
|
132
|
+
const plugin = this.selectComponent('.uniad-plugin')
|
|
133
|
+
if (this._isHalfScreenAd(plugin)) {
|
|
134
|
+
this._userInvokeShowFlag = false
|
|
135
|
+
return
|
|
136
|
+
}
|
|
109
137
|
if (this.loading) {
|
|
110
138
|
this._userInvokeShowFlag = true
|
|
111
139
|
return
|
|
@@ -120,6 +148,9 @@ export default {
|
|
|
120
148
|
},
|
|
121
149
|
|
|
122
150
|
_onclick () {
|
|
151
|
+
if (this.isHalfScreen) {
|
|
152
|
+
return
|
|
153
|
+
}
|
|
123
154
|
this.show()
|
|
124
155
|
},
|
|
125
156
|
|
|
@@ -142,12 +173,334 @@ export default {
|
|
|
142
173
|
return (typeof this.urlCallback === 'object' && Object.keys(this.urlCallback).length > 0)
|
|
143
174
|
},
|
|
144
175
|
|
|
176
|
+
/**
|
|
177
|
+
* 按 provider 从 acsv4 配置列表查找广告项
|
|
178
|
+
* @param {Array} list 配置数组
|
|
179
|
+
* @param {number} provider 渠道 provider
|
|
180
|
+
*/
|
|
181
|
+
_findAdItemByProvider (list, provider) {
|
|
182
|
+
if (!Array.isArray(list)) {
|
|
183
|
+
return null
|
|
184
|
+
}
|
|
185
|
+
return list.find(item => Number(item.provider) === Number(provider)) || null
|
|
186
|
+
},
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* 是否为微信广告无填充 errCode 1004
|
|
190
|
+
* @param {Object} err 错误对象
|
|
191
|
+
*/
|
|
192
|
+
_isWxAdNoFillError (err) {
|
|
193
|
+
if (!err) {
|
|
194
|
+
return false
|
|
195
|
+
}
|
|
196
|
+
const detail = err.detail || err
|
|
197
|
+
return Number(detail.errCode) === WxAdErrorCode.NoFill
|
|
198
|
+
},
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* 代运营无填充时尝试半屏兜底
|
|
202
|
+
* @param {Object} plugin uniad-plugin 实例
|
|
203
|
+
* @param {Object} err 错误对象
|
|
204
|
+
*/
|
|
205
|
+
_tryHalfScreenFallback (plugin, err) {
|
|
206
|
+
if (!plugin || !plugin.tryHalfScreenFallback) {
|
|
207
|
+
return false
|
|
208
|
+
}
|
|
209
|
+
const detail = err && (err.detail || err)
|
|
210
|
+
if (!this._isWxAdNoFillError(detail)) {
|
|
211
|
+
return false
|
|
212
|
+
}
|
|
213
|
+
// 半屏切换与 load 事件由插件 triggerEvent(load) → _onmpload 统一处理
|
|
214
|
+
return plugin.tryHalfScreenFallback(detail)
|
|
215
|
+
},
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* 处理代运营微信广告错误,无填充时走半屏兜底
|
|
219
|
+
* @param {Object} err 错误对象
|
|
220
|
+
* @param {string} reportType 上报类型
|
|
221
|
+
*/
|
|
222
|
+
_handleUserWxAdError (err, reportType) {
|
|
223
|
+
this.loading = false
|
|
224
|
+
const plugin = this.selectComponent('.uniad-plugin')
|
|
225
|
+
if (this._tryHalfScreenFallback(plugin, err)) {
|
|
226
|
+
return true
|
|
227
|
+
}
|
|
228
|
+
this.errorMessage = JSON.stringify(err)
|
|
229
|
+
this._dispatchEvent(EventType.Error, err)
|
|
230
|
+
if (reportType) {
|
|
231
|
+
this._report(reportType, err)
|
|
232
|
+
}
|
|
233
|
+
return false
|
|
234
|
+
},
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* 切换为半屏广告模式
|
|
238
|
+
*/
|
|
239
|
+
_setHalfScreenMode () {
|
|
240
|
+
this.isHalfScreen = true
|
|
241
|
+
this._providerType = ProviderType.HalfScreen
|
|
242
|
+
this.userwx = false
|
|
243
|
+
this.wxchannel = false
|
|
244
|
+
this.loading = false
|
|
245
|
+
this._userInvokeShowFlag = false
|
|
246
|
+
},
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* 是否半屏广告
|
|
250
|
+
* @param {Object} plugin uniad-plugin 实例
|
|
251
|
+
*/
|
|
252
|
+
_isHalfScreenAd (plugin) {
|
|
253
|
+
return this._providerType === ProviderType.HalfScreen || !!(
|
|
254
|
+
plugin &&
|
|
255
|
+
plugin.getHalfScreenConfig &&
|
|
256
|
+
plugin.getHalfScreenConfig()
|
|
257
|
+
)
|
|
258
|
+
},
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* 用户点击半屏占位(插件 halfScreenTap 事件)
|
|
262
|
+
* @param {Object} e 事件对象
|
|
263
|
+
*/
|
|
264
|
+
_onHalfScreenTap (e) {
|
|
265
|
+
const openOptions = e.detail && e.detail.openOptions
|
|
266
|
+
if (!openOptions) {
|
|
267
|
+
return
|
|
268
|
+
}
|
|
269
|
+
this._openTargetMiniProgramInHost(openOptions)
|
|
270
|
+
},
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* 开始打开小程序防抖锁
|
|
274
|
+
*/
|
|
275
|
+
_beginMiniProgramOpening () {
|
|
276
|
+
this._halfScreenOpening = true
|
|
277
|
+
this._halfScreenOpeningTimer = setTimeout(() => {
|
|
278
|
+
this._resetHalfScreenOpening()
|
|
279
|
+
}, 3000)
|
|
280
|
+
},
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* 用户手动触发:优先半屏打开,失败则 navigateToMiniProgram 兜底
|
|
284
|
+
* @param {Object} openOptions 打开参数
|
|
285
|
+
*/
|
|
286
|
+
_openTargetMiniProgramInHost (openOptions) {
|
|
287
|
+
if (this._halfScreenOpening) {
|
|
288
|
+
return
|
|
289
|
+
}
|
|
290
|
+
if (!openOptions || !openOptions.appId) {
|
|
291
|
+
this._dispatchEvent(EventType.Error, {
|
|
292
|
+
errMsg: 'mini program openOptions unavailable'
|
|
293
|
+
})
|
|
294
|
+
return
|
|
295
|
+
}
|
|
296
|
+
const plugin = this.selectComponent('.uniad-plugin')
|
|
297
|
+
this._openHalfScreenEmbeddedInHost(openOptions, plugin)
|
|
298
|
+
},
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* 半屏嵌入打开 wx.openEmbeddedMiniProgram
|
|
302
|
+
* @param {Object} openOptions 打开参数
|
|
303
|
+
* @param {Object} plugin uniad-plugin 实例
|
|
304
|
+
*/
|
|
305
|
+
_openHalfScreenEmbeddedInHost (openOptions, plugin) {
|
|
306
|
+
if (typeof wx.openEmbeddedMiniProgram !== 'function') {
|
|
307
|
+
this._openMiniProgramDirectInHost(openOptions, plugin)
|
|
308
|
+
return
|
|
309
|
+
}
|
|
310
|
+
this._beginMiniProgramOpening()
|
|
311
|
+
wx.openEmbeddedMiniProgram({
|
|
312
|
+
appId: openOptions.appId,
|
|
313
|
+
path: openOptions.path,
|
|
314
|
+
extraData: openOptions.extraData || {},
|
|
315
|
+
success: (res) => {
|
|
316
|
+
this._resetHalfScreenOpening()
|
|
317
|
+
if (plugin && plugin.notifyHalfScreenOpenSuccess) {
|
|
318
|
+
plugin.notifyHalfScreenOpenSuccess(res)
|
|
319
|
+
}
|
|
320
|
+
},
|
|
321
|
+
fail: (err) => {
|
|
322
|
+
if (this._isMiniProgramOpenCancel(err)) {
|
|
323
|
+
this._resetHalfScreenOpening()
|
|
324
|
+
this._notifyHalfScreenOpenResult(plugin, err)
|
|
325
|
+
return
|
|
326
|
+
}
|
|
327
|
+
this._openMiniProgramDirectInHost(openOptions, plugin, err)
|
|
328
|
+
}
|
|
329
|
+
})
|
|
330
|
+
},
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* 直接打开小程序 wx.navigateToMiniProgram(半屏未过审等场景兜底)
|
|
334
|
+
* @param {Object} openOptions 打开参数
|
|
335
|
+
* @param {Object} plugin uniad-plugin 实例
|
|
336
|
+
* @param {Object} fromErr 半屏打开失败时的错误
|
|
337
|
+
*/
|
|
338
|
+
_openMiniProgramDirectInHost (openOptions, plugin, fromErr) {
|
|
339
|
+
if (typeof wx.navigateToMiniProgram !== 'function') {
|
|
340
|
+
this._resetHalfScreenOpening()
|
|
341
|
+
this._notifyHalfScreenOpenResult(plugin, fromErr || {
|
|
342
|
+
errMsg: 'navigateToMiniProgram not supported'
|
|
343
|
+
})
|
|
344
|
+
return
|
|
345
|
+
}
|
|
346
|
+
if (!this._halfScreenOpening) {
|
|
347
|
+
this._beginMiniProgramOpening()
|
|
348
|
+
}
|
|
349
|
+
wx.navigateToMiniProgram({
|
|
350
|
+
appId: openOptions.appId,
|
|
351
|
+
path: openOptions.path,
|
|
352
|
+
extraData: openOptions.extraData || {},
|
|
353
|
+
success: (res) => {
|
|
354
|
+
this._resetHalfScreenOpening()
|
|
355
|
+
if (plugin && plugin.notifyHalfScreenOpenSuccess) {
|
|
356
|
+
plugin.notifyHalfScreenOpenSuccess(res, { isDirect: true })
|
|
357
|
+
}
|
|
358
|
+
},
|
|
359
|
+
fail: (err) => {
|
|
360
|
+
this._resetHalfScreenOpening()
|
|
361
|
+
this._notifyHalfScreenOpenResult(plugin, err)
|
|
362
|
+
}
|
|
363
|
+
})
|
|
364
|
+
},
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* 清除半屏打开锁定时器
|
|
368
|
+
*/
|
|
369
|
+
_clearHalfScreenOpeningTimer () {
|
|
370
|
+
if (this._halfScreenOpeningTimer) {
|
|
371
|
+
clearTimeout(this._halfScreenOpeningTimer)
|
|
372
|
+
this._halfScreenOpeningTimer = null
|
|
373
|
+
}
|
|
374
|
+
},
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* 重置半屏打开锁
|
|
378
|
+
*/
|
|
379
|
+
_resetHalfScreenOpening () {
|
|
380
|
+
this._halfScreenOpening = false
|
|
381
|
+
this._clearHalfScreenOpeningTimer()
|
|
382
|
+
},
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* 是否为打开/跳转小程序时用户点击取消(fail cancel)
|
|
386
|
+
* @param {Object} err 失败回调对象
|
|
387
|
+
*/
|
|
388
|
+
_isMiniProgramOpenCancel (err) {
|
|
389
|
+
const msg = (err && err.errMsg) || ''
|
|
390
|
+
return typeof msg === 'string' && msg.indexOf('fail cancel') !== -1
|
|
391
|
+
},
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* 通知插件半屏打开失败或用户取消
|
|
395
|
+
* @param {Object} plugin uniad-plugin 实例
|
|
396
|
+
* @param {Object} err 失败回调对象
|
|
397
|
+
*/
|
|
398
|
+
_notifyHalfScreenOpenResult (plugin, err) {
|
|
399
|
+
if (this._isMiniProgramOpenCancel(err)) {
|
|
400
|
+
if (plugin && plugin.notifyHalfScreenOpenCancel) {
|
|
401
|
+
plugin.notifyHalfScreenOpenCancel(err)
|
|
402
|
+
} else if (plugin && plugin.notifyHalfScreenOpenFail) {
|
|
403
|
+
plugin.notifyHalfScreenOpenFail(err)
|
|
404
|
+
} else {
|
|
405
|
+
this._dispatchEvent(EventType.Close, { type: 'userCancel', detail: err })
|
|
406
|
+
}
|
|
407
|
+
return
|
|
408
|
+
}
|
|
409
|
+
if (plugin && plugin.notifyHalfScreenOpenFail) {
|
|
410
|
+
plugin.notifyHalfScreenOpenFail(err)
|
|
411
|
+
} else {
|
|
412
|
+
this._dispatchEvent(EventType.Error, err)
|
|
413
|
+
}
|
|
414
|
+
},
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* 插件半屏占位就绪,同步宿主状态并隐藏 ad-custom
|
|
418
|
+
*/
|
|
419
|
+
_onHalfScreenReady () {
|
|
420
|
+
this._setHalfScreenMode()
|
|
421
|
+
},
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* 插件 all_show 双广告:ad 配置就绪后并行弹窗
|
|
425
|
+
* @param {Object} e 事件对象
|
|
426
|
+
*/
|
|
427
|
+
_onHalfScreenModal (e) {
|
|
428
|
+
const detail = e.detail || e
|
|
429
|
+
const openOptions = detail.openOptions
|
|
430
|
+
if (openOptions) {
|
|
431
|
+
this._tryShowHalfScreenModal(openOptions)
|
|
432
|
+
}
|
|
433
|
+
},
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* 尝试展示排队中的半屏弹窗
|
|
437
|
+
*/
|
|
438
|
+
_processPendingHalfScreenModal () {
|
|
439
|
+
const pending = takePendingHalfScreenModalOpenOptions()
|
|
440
|
+
if (pending) {
|
|
441
|
+
setTimeout(() => {
|
|
442
|
+
this._tryShowHalfScreenModal(pending)
|
|
443
|
+
}, 50)
|
|
444
|
+
}
|
|
445
|
+
},
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* 宿主层统一调用 uni.showModal 引导打开半屏
|
|
449
|
+
* @param {Object} openOptions 打开半屏/直达小程序参数
|
|
450
|
+
* @param {number} retryCount showModal 失败重试次数
|
|
451
|
+
*/
|
|
452
|
+
_tryShowHalfScreenModal (openOptions, retryCount = 0) {
|
|
453
|
+
if (!openOptions || !openOptions.appId) {
|
|
454
|
+
return
|
|
455
|
+
}
|
|
456
|
+
const appId = openOptions.appId
|
|
457
|
+
if (!canShowHalfScreenModal(appId)) {
|
|
458
|
+
return
|
|
459
|
+
}
|
|
460
|
+
if (isHalfScreenModalShowing()) {
|
|
461
|
+
queueHalfScreenModalOpenOptions(openOptions)
|
|
462
|
+
return
|
|
463
|
+
}
|
|
464
|
+
markHalfScreenModalShowing(appId)
|
|
465
|
+
uni.showModal({
|
|
466
|
+
title: '提示',
|
|
467
|
+
content: resolveHalfScreenModalContent(openOptions.msg),
|
|
468
|
+
confirmText: '继续',
|
|
469
|
+
cancelText: '取消',
|
|
470
|
+
success: (res) => {
|
|
471
|
+
if (res.confirm) {
|
|
472
|
+
markHalfScreenModalConfirmed()
|
|
473
|
+
this._openTargetMiniProgramInHost(openOptions)
|
|
474
|
+
} else {
|
|
475
|
+
markHalfScreenModalDismissed(appId)
|
|
476
|
+
}
|
|
477
|
+
},
|
|
478
|
+
fail: () => {
|
|
479
|
+
unlockHalfScreenModalShowing(appId)
|
|
480
|
+
if (retryCount < 1) {
|
|
481
|
+
setTimeout(() => {
|
|
482
|
+
this._tryShowHalfScreenModal(openOptions, retryCount + 1)
|
|
483
|
+
}, 300)
|
|
484
|
+
} else {
|
|
485
|
+
this._processPendingHalfScreenModal()
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
})
|
|
489
|
+
},
|
|
490
|
+
|
|
145
491
|
_onmpload (e) {
|
|
146
492
|
this.loading = false
|
|
493
|
+
const plugin = this.selectComponent('.uniad-plugin')
|
|
494
|
+
if (plugin && plugin.getHalfScreenConfig && plugin.getHalfScreenConfig()) {
|
|
495
|
+
this._setHalfScreenMode()
|
|
496
|
+
}
|
|
147
497
|
this._dispatchEvent(EventType.Load, {})
|
|
148
498
|
this._report(ActionType.AdRequest)
|
|
149
499
|
if (this._userInvokeShowFlag) {
|
|
150
500
|
this._userInvokeShowFlag = false
|
|
501
|
+
if (this.isHalfScreen) {
|
|
502
|
+
return
|
|
503
|
+
}
|
|
151
504
|
setTimeout(() => {
|
|
152
505
|
this.show()
|
|
153
506
|
}, 1)
|
|
@@ -185,15 +538,22 @@ export default {
|
|
|
185
538
|
},
|
|
186
539
|
|
|
187
540
|
_onmperror (e) {
|
|
188
|
-
|
|
189
|
-
this.
|
|
190
|
-
|
|
191
|
-
|
|
541
|
+
const detail = e.detail || e
|
|
542
|
+
if (this._handleUserWxAdError(detail, ActionType.AdRequest)) {
|
|
543
|
+
return
|
|
544
|
+
}
|
|
545
|
+
if (this._isMiniProgramOpenCancel(detail)) {
|
|
546
|
+
return
|
|
547
|
+
}
|
|
548
|
+
this._dispatchEvent(EventType.Error, detail)
|
|
192
549
|
},
|
|
193
550
|
|
|
194
551
|
_onnextchannel (e) {
|
|
552
|
+
const adData = this._findAdItemByProvider(e.detail, ProviderType.UserWeChat)
|
|
553
|
+
if (!adData) {
|
|
554
|
+
return
|
|
555
|
+
}
|
|
195
556
|
this.wxchannel = true
|
|
196
|
-
const adData = e.detail[0]
|
|
197
557
|
this.$nextTick(() => {
|
|
198
558
|
if (adData.provider === 10017) {
|
|
199
559
|
this._providerType = ProviderType.UserWeChat
|
|
@@ -311,8 +671,7 @@ export default {
|
|
|
311
671
|
this._wxRewardedAd.show().then(() => {
|
|
312
672
|
this._report(ActionType.Show)
|
|
313
673
|
}).catch((err) => {
|
|
314
|
-
this.
|
|
315
|
-
this._report(ActionType.Show, err)
|
|
674
|
+
this._handleUserWxAdError(err, ActionType.Show)
|
|
316
675
|
})
|
|
317
676
|
break
|
|
318
677
|
case AdType.Interstitial:
|
|
@@ -323,8 +682,7 @@ export default {
|
|
|
323
682
|
this._wxInterstitialAd.show().then(() => {
|
|
324
683
|
this._report(ActionType.Show)
|
|
325
684
|
}).catch((err) => {
|
|
326
|
-
this.
|
|
327
|
-
this._report(ActionType.Show, err)
|
|
685
|
+
this._handleUserWxAdError(err, ActionType.Show)
|
|
328
686
|
})
|
|
329
687
|
break
|
|
330
688
|
}
|
|
@@ -349,9 +707,7 @@ export default {
|
|
|
349
707
|
})
|
|
350
708
|
|
|
351
709
|
this._wxRewardedAd.onError(err => {
|
|
352
|
-
this.
|
|
353
|
-
this.errorMessage = JSON.stringify(err)
|
|
354
|
-
this._dispatchEvent(EventType.Error, err)
|
|
710
|
+
this._handleUserWxAdError(err, ActionType.AdRequest)
|
|
355
711
|
})
|
|
356
712
|
|
|
357
713
|
this._wxRewardedAd.onClose(res => {
|
|
@@ -389,10 +745,7 @@ export default {
|
|
|
389
745
|
})
|
|
390
746
|
|
|
391
747
|
this._wxInterstitialAd.onError(err => {
|
|
392
|
-
this.
|
|
393
|
-
this.errorMessage = JSON.stringify(err)
|
|
394
|
-
this._dispatchEvent(EventType.Error, err)
|
|
395
|
-
this._report(ActionType.AdRequest, err)
|
|
748
|
+
this._handleUserWxAdError(err, ActionType.AdRequest)
|
|
396
749
|
})
|
|
397
750
|
|
|
398
751
|
this._wxInterstitialAd.onClose(res => {
|
|
@@ -400,8 +753,7 @@ export default {
|
|
|
400
753
|
})
|
|
401
754
|
|
|
402
755
|
this._wxInterstitialAd.load().catch((err) => {
|
|
403
|
-
this.
|
|
404
|
-
this._report(ActionType.AdRequest, err)
|
|
756
|
+
this._handleUserWxAdError(err, ActionType.AdRequest)
|
|
405
757
|
})
|
|
406
758
|
|
|
407
759
|
this.loading = true
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/** 半屏弹窗默认文案(msg 缺失或为空时使用) */
|
|
2
|
+
export const HALF_SCREEN_MODAL_DEFAULT_MSG = '即将为您打开其他小程序,是否继续?'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 解析半屏弹窗展示文案
|
|
6
|
+
* @param {string} msg 服务端或插件下发的 msg
|
|
7
|
+
* @returns {string}
|
|
8
|
+
*/
|
|
9
|
+
export function resolveHalfScreenModalContent (msg) {
|
|
10
|
+
if (typeof msg === 'string' && msg.trim()) {
|
|
11
|
+
return msg.trim()
|
|
12
|
+
}
|
|
13
|
+
return HALF_SCREEN_MODAL_DEFAULT_MSG
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** 半屏弹窗页面级去重(组件重新挂载时重置,取消后当次不再弹) */
|
|
17
|
+
const _state = {
|
|
18
|
+
dismissedAppIds: new Set(),
|
|
19
|
+
showingAppId: null,
|
|
20
|
+
pendingOpenOptions: null
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 重置半屏弹窗会话(ad 组件新建 / 页面重新进入时调用)
|
|
25
|
+
*/
|
|
26
|
+
export function resetHalfScreenModalSession () {
|
|
27
|
+
_state.dismissedAppIds.clear()
|
|
28
|
+
_state.showingAppId = null
|
|
29
|
+
_state.pendingOpenOptions = null
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 是否允许展示半屏弹窗
|
|
34
|
+
* @param {string} appId 目标小程序 appId
|
|
35
|
+
* @returns {boolean}
|
|
36
|
+
*/
|
|
37
|
+
export function canShowHalfScreenModal (appId) {
|
|
38
|
+
if (!appId) {
|
|
39
|
+
return false
|
|
40
|
+
}
|
|
41
|
+
if (_state.dismissedAppIds.has(appId)) {
|
|
42
|
+
return false
|
|
43
|
+
}
|
|
44
|
+
return true
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* 是否有半屏弹窗正在展示
|
|
49
|
+
* @returns {boolean}
|
|
50
|
+
*/
|
|
51
|
+
export function isHalfScreenModalShowing () {
|
|
52
|
+
return !!_state.showingAppId
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* 标记半屏弹窗正在展示
|
|
57
|
+
* @param {string} appId 目标小程序 appId
|
|
58
|
+
*/
|
|
59
|
+
export function markHalfScreenModalShowing (appId) {
|
|
60
|
+
_state.showingAppId = appId
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 解除半屏弹窗展示锁
|
|
65
|
+
* @param {string} appId 目标小程序 appId
|
|
66
|
+
*/
|
|
67
|
+
export function unlockHalfScreenModalShowing (appId) {
|
|
68
|
+
if (_state.showingAppId === appId) {
|
|
69
|
+
_state.showingAppId = null
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 标记半屏弹窗用户已确认(不阻止下次进入页面再弹)
|
|
75
|
+
*/
|
|
76
|
+
export function markHalfScreenModalConfirmed () {
|
|
77
|
+
_state.showingAppId = null
|
|
78
|
+
_state.pendingOpenOptions = null
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 标记半屏弹窗用户取消(当前会话不再弹)
|
|
83
|
+
* @param {string} appId 目标小程序 appId
|
|
84
|
+
*/
|
|
85
|
+
export function markHalfScreenModalDismissed (appId) {
|
|
86
|
+
if (appId) {
|
|
87
|
+
_state.dismissedAppIds.add(appId)
|
|
88
|
+
}
|
|
89
|
+
_state.showingAppId = null
|
|
90
|
+
_state.pendingOpenOptions = null
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* 排队等待展示半屏弹窗(同 appId 多实例竞态时)
|
|
95
|
+
* @param {Object} openOptions 打开参数
|
|
96
|
+
*/
|
|
97
|
+
export function queueHalfScreenModalOpenOptions (openOptions) {
|
|
98
|
+
if (!openOptions || !openOptions.appId) {
|
|
99
|
+
return
|
|
100
|
+
}
|
|
101
|
+
if (_state.dismissedAppIds.has(openOptions.appId)) {
|
|
102
|
+
return
|
|
103
|
+
}
|
|
104
|
+
_state.pendingOpenOptions = openOptions
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* 取出并排清空排队中的半屏弹窗参数
|
|
109
|
+
* @returns {Object|null}
|
|
110
|
+
*/
|
|
111
|
+
export function takePendingHalfScreenModalOpenOptions () {
|
|
112
|
+
const pending = _state.pendingOpenOptions
|
|
113
|
+
_state.pendingOpenOptions = null
|
|
114
|
+
if (!pending || !pending.appId) {
|
|
115
|
+
return null
|
|
116
|
+
}
|
|
117
|
+
if (_state.dismissedAppIds.has(pending.appId)) {
|
|
118
|
+
return null
|
|
119
|
+
}
|
|
120
|
+
return pending
|
|
121
|
+
}
|
package/components/uniad.vue
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<view :class="[customFullscreen?'uni-ad-custom':'',customFullscreen]" :style="style" @click="
|
|
2
|
+
<view :class="[customFullscreen?'uni-ad-custom':'',customFullscreen]" :style="style" @click="_onclick">
|
|
3
3
|
<uniad-plugin
|
|
4
4
|
class="uniad-plugin"
|
|
5
5
|
:adpid="adpid"
|
|
@@ -10,9 +10,12 @@
|
|
|
10
10
|
@error="_onmperror"
|
|
11
11
|
@nextChannel="_onnextchannel"
|
|
12
12
|
@customFullscreen="_customFullscreen"
|
|
13
|
+
@halfScreenReady="_onHalfScreenReady"
|
|
14
|
+
@halfScreenTap="_onHalfScreenTap"
|
|
15
|
+
@halfScreenModal="_onHalfScreenModal"
|
|
13
16
|
/>
|
|
14
17
|
<!-- #ifdef MP-WEIXIN -->
|
|
15
|
-
<ad-custom v-if="userwx" :adIntervals="adIntervals" :unit-id="userUnitId" class="uni-ad-custom" data-com-type="wx" :class="[customFullscreen]" @load="_onmpload" @error="_onmperror"></ad-custom>
|
|
18
|
+
<ad-custom v-if="userwx && !isHalfScreen" :adIntervals="adIntervals" :unit-id="userUnitId" class="uni-ad-custom" data-com-type="wx" :class="[customFullscreen]" @load="_onmpload" @error="_onmperror"></ad-custom>
|
|
16
19
|
<!-- <uniad-plugin-wx v-if="wxchannel" class="uniad-plugin-wx" :class="[customFullscreen]" data-com-type="wx" @load="_onmpload" @error="_onwxchannelerror"></uniad-plugin-wx> -->
|
|
17
20
|
<!-- #endif -->
|
|
18
21
|
</view>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dcloudio/uni-cli-shared",
|
|
3
|
-
"version": "2.0.2-alpha-
|
|
3
|
+
"version": "2.0.2-alpha-5020120260710001",
|
|
4
4
|
"description": "uni-cli-shared",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -27,5 +27,5 @@
|
|
|
27
27
|
"postcss-urlrewrite": "^0.2.2",
|
|
28
28
|
"strip-json-comments": "^2.0.1"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "cf7b7801e8bc5a7e8b9cac638f4e3bece2599e42"
|
|
31
31
|
}
|