@dcloudio/uni-components 3.0.0-4080720251210001 → 3.0.0-5000320260312001

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.
@@ -7,9 +7,9 @@ const EventType = {
7
7
  }
8
8
 
9
9
  const AdType = {
10
- Banner: "banner",
11
- RewardedVideo: "rewardedVideo",
12
- Interstitial: "interstitial"
10
+ Banner: 'banner',
11
+ RewardedVideo: 'rewardedVideo',
12
+ Interstitial: 'interstitial'
13
13
  }
14
14
 
15
15
  const ProviderType = {
@@ -18,8 +18,22 @@ const ProviderType = {
18
18
  ShanHu: 10020
19
19
  }
20
20
 
21
+ const ActionType = {
22
+ ServerRequest: '-3',
23
+ AdRequest: '-1',
24
+ Show: '40',
25
+ Click: '41'
26
+ }
27
+
21
28
  export default {
29
+ options: {
30
+ virtualHost: true
31
+ },
22
32
  props: {
33
+ style: {
34
+ type: String,
35
+ default: ''
36
+ },
23
37
  options: {
24
38
  type: [Object, Array],
25
39
  default () {
@@ -42,6 +56,10 @@ export default {
42
56
  type: [Boolean, String],
43
57
  default: false
44
58
  },
59
+ adIntervals: {
60
+ type: [Number, String],
61
+ default: ''
62
+ },
45
63
  urlCallback: {
46
64
  type: Object,
47
65
  default () {
@@ -53,7 +71,7 @@ export default {
53
71
  return {
54
72
  loading: false,
55
73
  userwx: false,
56
- userUnitId: "",
74
+ userUnitId: '',
57
75
  customFullscreen: '',
58
76
  wxchannel: false,
59
77
  errorMessage: null
@@ -69,6 +87,7 @@ export default {
69
87
  if (this.preload && this._canCreateAd()) {
70
88
  this.load()
71
89
  }
90
+ this._dispatchEvent('adcreated', { instance: this })
72
91
  },
73
92
  methods: {
74
93
  load () {
@@ -76,10 +95,10 @@ export default {
76
95
  return
77
96
  }
78
97
  this._startLoading()
79
- if (this._providerType == ProviderType.ShanHu) {
80
- } else if (this._providerType == ProviderType.WeChat) {
98
+ if (this._providerType === ProviderType.ShanHu) {
99
+ } else if (this._providerType === ProviderType.WeChat) {
81
100
  this.selectComponent('.uniad-plugin-wx').load()
82
- } else if (this._providerType == ProviderType.UserWeChat) {
101
+ } else if (this._providerType === ProviderType.UserWeChat) {
83
102
  this._loadWxAd()
84
103
  }
85
104
  },
@@ -90,11 +109,11 @@ export default {
90
109
  this._userInvokeShowFlag = true
91
110
  return
92
111
  }
93
- if (this._providerType == ProviderType.ShanHu) {
112
+ if (this._providerType === ProviderType.ShanHu) {
94
113
  this._showAdInPlugin(this.selectComponent('.uniad-plugin'))
95
- } else if (this._providerType == ProviderType.WeChat) {
114
+ } else if (this._providerType === ProviderType.WeChat) {
96
115
  this._showAdInPlugin(this.selectComponent('.uniad-plugin-wx'))
97
- } else if (this._providerType == ProviderType.UserWeChat) {
116
+ } else if (this._providerType === ProviderType.UserWeChat) {
98
117
  this._showWxAd(e)
99
118
  }
100
119
  },
@@ -125,16 +144,17 @@ export default {
125
144
  _onmpload (e) {
126
145
  this.loading = false
127
146
  this._dispatchEvent(EventType.Load, {})
147
+ this._report(ActionType.AdRequest)
128
148
  if (this._userInvokeShowFlag) {
129
149
  this._userInvokeShowFlag = false
130
150
  setTimeout(() => {
131
- this.show();
151
+ this.show()
132
152
  }, 1)
133
153
  }
134
154
  },
135
155
 
136
156
  _onmpclose (e) {
137
- const detail = e.detail || e;
157
+ const detail = e.detail || e
138
158
  this._dispatchEvent(EventType.Close, detail)
139
159
  if (detail.adsdata) {
140
160
  const adv = detail.adv
@@ -167,15 +187,16 @@ export default {
167
187
  this.loading = false
168
188
  this.errorMessage = JSON.stringify(e.detail)
169
189
  this._dispatchEvent(EventType.Error, e.detail)
190
+ this._report(ActionType.AdRequest, e.detail)
170
191
  },
171
192
 
172
193
  _onnextchannel (e) {
173
194
  this.wxchannel = true
174
- const adData = e.detail[0];
195
+ const adData = e.detail[0]
175
196
  this.$nextTick(() => {
176
- if (adData.provider == 10017) {
197
+ if (adData.provider === 10017) {
177
198
  this._providerType = ProviderType.UserWeChat
178
- switch(adData._nt_) {
199
+ switch (adData._nt_) {
179
200
  case 4:
180
201
  this.wxAdType = AdType.Banner
181
202
  this.userwx = true
@@ -183,17 +204,17 @@ export default {
183
204
  if (adData.tmpl_type === 24) {
184
205
  this.customFullscreen = 'uni-ad-custom-fullscreen'
185
206
  }
186
- break;
207
+ break
187
208
  case 9:
188
209
  this.wxAdType = AdType.RewardedVideo
189
210
  this._createRewardedAd(adData.posid)
190
- break;
211
+ break
191
212
  case 15:
192
213
  this.wxAdType = AdType.Interstitial
193
214
  this._createInterstitialAd(adData.posid)
194
- break;
215
+ break
195
216
  }
196
- } else if (adData.provider == 10018) {
217
+ } else if (adData.provider === 10018) {
197
218
  this._providerType = ProviderType.WeChat
198
219
  if (adData.tmpl_type === 24) {
199
220
  this.customFullscreen = 'uni-ad-custom-fullscreen'
@@ -206,8 +227,10 @@ export default {
206
227
  }
207
228
  })
208
229
  },
209
-
210
- _onwxchannelerror(e) {
230
+ _customFullscreen () {
231
+ this.customFullscreen = 'uni-ad-custom-fullscreen'
232
+ },
233
+ _onwxchannelerror (e) {
211
234
  this._dispatchEvent(EventType.Error, e.detail || e)
212
235
  },
213
236
 
@@ -217,7 +240,7 @@ export default {
217
240
  })
218
241
  },
219
242
 
220
- _showAdInPlugin(adComponent) {
243
+ _showAdInPlugin (adComponent) {
221
244
  if (this._hasCallback()) {
222
245
  const userCryptoManager = wx.getUserCryptoManager()
223
246
  userCryptoManager.getLatestUserKey({
@@ -229,7 +252,7 @@ export default {
229
252
  }) => {
230
253
  const uniOptions = {
231
254
  adpid: this.adpid
232
- };
255
+ }
233
256
  adComponent.show({
234
257
  userId: this.urlCallback.userId || '',
235
258
  extra: this.urlCallback.extra || '',
@@ -256,122 +279,134 @@ export default {
256
279
  switch (this.wxAdType) {
257
280
  case AdType.RewardedVideo:
258
281
  if (this._wxRewardedAd) {
259
- this._wxRewardedAd.load();
282
+ this._wxRewardedAd.load().catch((err) => {
283
+ this._dispatchEvent(EventType.Error, err)
284
+ })
260
285
  }
261
- break;
286
+ break
262
287
  case AdType.Interstitial:
263
288
  if (this._wxInterstitialAd) {
264
- this._wxInterstitialAd.load();
289
+ this._wxInterstitialAd.load().catch((err) => {
290
+ this._dispatchEvent(EventType.Error, err)
291
+ })
265
292
  }
266
- break;
293
+ break
267
294
  }
268
295
  },
269
296
 
270
297
  // 加载/显示广告
271
298
  _showWxAd (options) {
272
- this._urlCallback = options || this.urlCallback;
273
- if (this.loading == true) {
299
+ this._urlCallback = options || this.urlCallback
300
+ if (this.loading === true) {
274
301
  this._userInvokeShowFlag = true
275
302
  return
276
303
  }
277
304
  switch (this.wxAdType) {
278
305
  case AdType.RewardedVideo:
279
306
  if (!this._wxRewardedAd) {
280
- return;
307
+ return
281
308
  }
282
- this._wxRewardedAd.show().catch((err) => {
283
- this._wxRewardedAd.load().then(() => {
284
- this._wxRewardedAd.show();
285
- }).catch((err) => {
286
- this._dispatchEvent(EventType.Error, err);
287
- });
288
- });
289
- break;
309
+ // eslint-disable-next-line handle-callback-err
310
+ this._wxRewardedAd.show().then(() => {
311
+ this._report(ActionType.Show)
312
+ }).catch((err) => {
313
+ this._dispatchEvent(EventType.Error, err)
314
+ this._report(ActionType.Show, err)
315
+ })
316
+ break
290
317
  case AdType.Interstitial:
291
318
  if (!this._wxInterstitialAd) {
292
- return;
319
+ return
293
320
  }
294
- this._wxInterstitialAd.show().catch((err) => {
295
- this._wxInterstitialAd.load().then(() => {
296
- this._wxInterstitialAd.show();
297
- }).catch((err) => {
298
- this._dispatchEvent(EventType.Error, err);
299
- });
300
- });
301
- break;
321
+ // eslint-disable-next-line handle-callback-err
322
+ this._wxInterstitialAd.show().then(() => {
323
+ this._report(ActionType.Show)
324
+ }).catch((err) => {
325
+ this._dispatchEvent(EventType.Error, err)
326
+ this._report(ActionType.Show, err)
327
+ })
328
+ break
302
329
  }
303
330
  },
304
331
 
305
332
  // 微信激励视频
306
- _createRewardedAd(adUnitId) {
333
+ _createRewardedAd (adUnitId) {
307
334
  if (this._wxRewardedAd) {
308
- return;
335
+ return
309
336
  }
310
337
 
311
- this._wxRewardedAd = wx.createRewardedVideoAd({ adUnitId: adUnitId, multiton: true });
338
+ this._wxRewardedAd = wx.createRewardedVideoAd({ adUnitId: adUnitId, multiton: true })
312
339
 
313
340
  this._wxRewardedAd.onLoad(() => {
314
341
  this.loading = false
315
342
  this._dispatchEvent(EventType.Load, {})
343
+ this._report(ActionType.AdRequest)
316
344
  if (this._userInvokeShowFlag) {
317
- this._userInvokeShowFlag = false;
318
- this._wxRewardedAd.show();
345
+ this._userInvokeShowFlag = false
346
+ this._wxRewardedAd.show()
319
347
  }
320
- });
348
+ })
321
349
 
322
350
  this._wxRewardedAd.onError(err => {
323
351
  this.loading = false
324
352
  this.errorMessage = JSON.stringify(err)
325
- this._dispatchEvent(EventType.Error, err);
326
- });
353
+ this._dispatchEvent(EventType.Error, err)
354
+ })
327
355
 
328
356
  this._wxRewardedAd.onClose(res => {
329
- this._dispatchEvent(EventType.Close, res);
357
+ this._dispatchEvent(EventType.Close, res)
330
358
  if (res.isEnded && this._hasCallback()) {
331
359
  this._callServer()
332
360
  }
333
- });
361
+ })
334
362
 
335
363
  this._wxRewardedAd.load().then(() => {
336
364
  }).catch((_) => {
337
- });
365
+ })
338
366
 
339
367
  this.loading = true
340
368
  },
341
369
 
342
370
  // 微信插屏
343
- _createInterstitialAd(adUnitId) {
371
+ _createInterstitialAd (adUnitId) {
344
372
  if (this._wxInterstitialAd) {
345
- return;
373
+ return
346
374
  }
347
375
 
348
- this._wxInterstitialAd = wx.createInterstitialAd({ adUnitId: adUnitId });
376
+ this._wxInterstitialAd = wx.createInterstitialAd({ adUnitId: adUnitId })
349
377
 
350
378
  this._wxInterstitialAd.onLoad(() => {
351
379
  this.loading = false
352
380
  this._dispatchEvent(EventType.Load, {})
381
+ this._report(ActionType.AdRequest)
353
382
  if (this._userInvokeShowFlag) {
354
- this._userInvokeShowFlag = false;
355
- this._wxInterstitialAd.show();
383
+ this._userInvokeShowFlag = false
384
+ this._wxInterstitialAd.show().catch((err) => {
385
+ this._dispatchEvent(EventType.Error, err)
386
+ })
356
387
  }
357
- });
388
+ })
358
389
 
359
390
  this._wxInterstitialAd.onError(err => {
360
391
  this.loading = false
361
392
  this.errorMessage = JSON.stringify(err)
362
- this._dispatchEvent(EventType.Error, err);
363
- });
393
+ this._dispatchEvent(EventType.Error, err)
394
+ this._report(ActionType.AdRequest, err)
395
+ })
364
396
 
365
397
  this._wxInterstitialAd.onClose(res => {
366
- this._dispatchEvent(EventType.Close, res);
367
- });
398
+ this._dispatchEvent(EventType.Close, res)
399
+ })
368
400
 
369
- this._wxInterstitialAd.load().then(() => { }).catch((err) => { });
401
+ this._wxInterstitialAd.load().catch((err) => {
402
+ this._dispatchEvent(EventType.Error, err)
403
+ this._report(ActionType.AdRequest, err)
404
+ })
370
405
 
371
406
  this.loading = true
372
407
  },
373
408
 
374
- _callServer() {
409
+ _callServer () {
375
410
  const userCryptoManager = wx.getUserCryptoManager()
376
411
  userCryptoManager.getLatestUserKey({
377
412
  success: (encryptConfig) => {
@@ -381,17 +416,33 @@ export default {
381
416
  data: callbackData,
382
417
  secretType: 'both',
383
418
  success: (res) => {
384
- this._dispatchEvent(EventType.Close, res);
419
+ this._dispatchEvent(EventType.Close, res)
385
420
  },
386
421
  fail: (err) => {
387
- this._dispatchEvent(EventType.Error, err);
422
+ this._dispatchEvent(EventType.Error, err)
388
423
  }
389
424
  })
390
425
  },
391
426
  fail: (err) => {
392
- this._dispatchEvent(EventType.Error, err);
427
+ this._dispatchEvent(EventType.Error, err)
393
428
  }
394
429
  })
430
+ },
431
+
432
+ toJSON () {
433
+ return ''
434
+ },
435
+
436
+ _report (type, detail) {
437
+ const adComponent = this.selectComponent('.uniad-plugin')
438
+ if (adComponent && adComponent._unireport) {
439
+ adComponent._unireport({
440
+ isUni: true,
441
+ adpid: this.adpid,
442
+ type,
443
+ detail: detail || ''
444
+ })
445
+ }
395
446
  }
396
447
  }
397
448
  }
@@ -2,7 +2,7 @@
2
2
  <view @click="_onclick">
3
3
  <slot :options="options" :loading="loading" :error="errorMessage" />
4
4
  <!-- #ifdef MP-WEIXIN -->
5
- <uniad-plugin class="uniad-plugin" :adpid="adpid" :unit-id="unitId" @load="_onmpload" @close="_onmpclose" @error="_onmperror"></uniad-plugin>
5
+ <uniad-plugin class="uniad-plugin" :isUni="true" :adpid="adpid" :unit-id="unitId" @load="_onmpload" @close="_onmpclose" @error="_onmperror"></uniad-plugin>
6
6
  <uniad-plugin-wx v-if="wxchannel" class="uniad-plugin-wx" @load="_onmpload" @close="_onmpclose" @error="_onwxchannelerror"></uniad-plugin-wx>
7
7
  <!-- #endif -->
8
8
  <!-- #ifdef MP-ALIPAY -->
@@ -2,7 +2,7 @@
2
2
  <view @click="_onclick">
3
3
  <slot :options="options" :loading="loading" :error="errorMessage" />
4
4
  <!-- #ifdef MP-WEIXIN -->
5
- <uniad-plugin class="uniad-plugin" :adpid="adpid" :unit-id="unitId" @load="_onmpload" @close="_onmpclose" @error="_onmperror" @nextChannel="_onnextchannel"></uniad-plugin>
5
+ <uniad-plugin class="uniad-plugin" :isUni="true" :adpid="adpid" :unit-id="unitId" @load="_onmpload" @close="_onmpclose" @error="_onmperror" @nextChannel="_onnextchannel"></uniad-plugin>
6
6
  <uniad-plugin-wx v-if="wxchannel" class="uniad-plugin-wx" @load="_onmpload" @close="_onmpclose" @error="_onwxchannelerror"></uniad-plugin-wx>
7
7
  <!-- #endif -->
8
8
  <!-- #ifdef MP-ALIPAY -->
@@ -2,7 +2,7 @@
2
2
  <view @click="_onclick">
3
3
  <slot :options="options" :loading="loading" :error="errorMessage" />
4
4
  <!-- #ifdef MP-WEIXIN -->
5
- <uniad-plugin class="uniad-plugin" :adpid="adpid" :unit-id="unitId" @load="_onmpload" @close="_onmpclose" @error="_onmperror" @nextChannel="_onnextchannel"></uniad-plugin>
5
+ <uniad-plugin class="uniad-plugin" :isUni="true" :adpid="adpid" :unit-id="unitId" @load="_onmpload" @close="_onmpclose" @error="_onmperror" @nextChannel="_onnextchannel"></uniad-plugin>
6
6
  <uniad-plugin-wx v-if="wxchannel" class="uniad-plugin-wx" @load="_onmpload" @close="_onmpclose" @error="_onwxchannelerror"></uniad-plugin-wx>
7
7
  <!-- #endif -->
8
8
  <!-- #ifdef MP-ALIPAY -->
@@ -1,17 +1,20 @@
1
1
  <template>
2
- <view @click="onclick">
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"
6
+ :isUni="true"
6
7
  :unit-id="unitId"
8
+ :adIntervals="adIntervals"
7
9
  @load="_onmpload"
8
10
  @close="_onmpclose"
9
11
  @error="_onmperror"
10
12
  @nextChannel="_onnextchannel"
13
+ @customFullscreen="_customFullscreen"
11
14
  />
12
15
  <!-- #ifdef MP-WEIXIN -->
13
- <ad-custom v-if="userwx" :unit-id="userUnitId" class="uni-ad-custom" :class="[customFullscreen]" @load="_onmpload" @error="_onmperror"></ad-custom>
14
- <uniad-plugin-wx v-if="wxchannel" class="uniad-plugin-wx" :class="[customFullscreen]" @load="_onmpload" @error="_onwxchannelerror"></uniad-plugin-wx>
16
+ <ad-custom v-if="userwx" :unit-id="userUnitId" :adIntervals="adIntervals" class="uni-ad-custom" :class="[customFullscreen]" @load="_onmpload" @error="_onmperror"></ad-custom>
17
+ <!-- <uniad-plugin-wx v-if="wxchannel" class="uniad-plugin-wx" :class="[customFullscreen]" @load="_onmpload" @error="_onwxchannelerror"></uniad-plugin-wx> -->
15
18
  <!-- #endif -->
16
19
  </view>
17
20
  </template>
@@ -35,4 +38,13 @@ export default {
35
38
  display: flex;
36
39
  height: 100vh;
37
40
  }
41
+ .uni-ad-custom {
42
+ display: flex;
43
+ flex: 1;
44
+ width: 100%;
45
+ }
46
+ .uniad-plugin {
47
+ display: flex;
48
+ flex: 1;
49
+ }
38
50
  </style>