@dcloudio/uni-cli-shared 2.0.1-34720220422002 → 2.0.1-34920220607003
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-fullscreen-video.vue +30 -0
- package/components/ad-interactive.vue +141 -0
- package/components/ad-interstitial.vue +30 -0
- package/components/ad-rewarded-video.vue +29 -0
- package/components/ad.mixin.js +556 -0
- package/components/ad.mixin.mp.js +104 -0
- package/components/uniad.vue +24 -0
- package/lib/cache.js +9 -2
- package/lib/index.js +4 -2
- package/lib/json.js +3 -8
- package/lib/manifest.js +32 -3
- package/lib/pages.js +15 -2
- package/lib/platform.js +194 -185
- package/package.json +2 -2
- package/template/common/__uniappscan.js +1 -1
|
@@ -0,0 +1,556 @@
|
|
|
1
|
+
const ADType = {
|
|
2
|
+
RewardedVideo: 'RewardedVideo',
|
|
3
|
+
FullScreenVideo: 'FullScreenVideo',
|
|
4
|
+
Interstitial: 'Interstitial'
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const EventType = {
|
|
8
|
+
Load: 'load',
|
|
9
|
+
Close: 'close',
|
|
10
|
+
Error: 'error'
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const EXPIRED_TIME = 1000 * 60 * 30
|
|
14
|
+
const ProviderType = {
|
|
15
|
+
CSJ: 'csj',
|
|
16
|
+
GDT: 'gdt'
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const RETRY_COUNT = 1
|
|
20
|
+
|
|
21
|
+
class AdBase {
|
|
22
|
+
constructor (adInstance, options = {}) {
|
|
23
|
+
this._isLoad = false
|
|
24
|
+
this._isLoading = false
|
|
25
|
+
this._isPlaying = false
|
|
26
|
+
this._lastLoadTime = 0
|
|
27
|
+
this._lastError = null
|
|
28
|
+
this._retryCount = 0
|
|
29
|
+
if (options.retry !== undefined) {
|
|
30
|
+
this._retry = options.retry
|
|
31
|
+
} else {
|
|
32
|
+
this._retry = true
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
this._loadCallback = null
|
|
36
|
+
this._closeCallback = null
|
|
37
|
+
this._errorCallback = null
|
|
38
|
+
|
|
39
|
+
const ad = this._ad = adInstance
|
|
40
|
+
ad.onLoad((e) => {
|
|
41
|
+
this._isLoading = false
|
|
42
|
+
this._isLoad = true
|
|
43
|
+
this._lastLoadTime = Date.now()
|
|
44
|
+
|
|
45
|
+
this.onLoad()
|
|
46
|
+
})
|
|
47
|
+
ad.onClose((e) => {
|
|
48
|
+
this._isLoad = false
|
|
49
|
+
this._isPlaying = false
|
|
50
|
+
this.onClose(e)
|
|
51
|
+
})
|
|
52
|
+
ad.onVerify && ad.onVerify((e) => {
|
|
53
|
+
// e.isValid
|
|
54
|
+
})
|
|
55
|
+
ad.onError(({
|
|
56
|
+
code,
|
|
57
|
+
message
|
|
58
|
+
}) => {
|
|
59
|
+
this._isLoading = false
|
|
60
|
+
const data = {
|
|
61
|
+
code: code,
|
|
62
|
+
errMsg: message
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (this._retry && code === -5008) {
|
|
66
|
+
this._loadAd()
|
|
67
|
+
return
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (this._retry && this._retryCount < RETRY_COUNT) {
|
|
71
|
+
this._retryCount += 1
|
|
72
|
+
this._loadAd()
|
|
73
|
+
return
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
this._lastError = data
|
|
77
|
+
this.onError(data)
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
get isExpired () {
|
|
82
|
+
return (this._lastLoadTime !== 0 && (Math.abs(Date.now() - this._lastLoadTime) > EXPIRED_TIME))
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
get isLoad () {
|
|
86
|
+
return this._isLoad
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
get isLoading () {
|
|
90
|
+
return this._isLoading
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
getProvider () {
|
|
94
|
+
return this._ad.getProvider()
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
load (onload, onerror) {
|
|
98
|
+
this._loadCallback = onload
|
|
99
|
+
this._errorCallback = onerror
|
|
100
|
+
|
|
101
|
+
if (this._isPlaying) {
|
|
102
|
+
onerror && onerror()
|
|
103
|
+
return
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (this._isLoading) {
|
|
107
|
+
return
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (this._isLoad) {
|
|
111
|
+
this.onLoad()
|
|
112
|
+
return
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
this._retryCount = 0
|
|
116
|
+
|
|
117
|
+
this._loadAd()
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
show (onclose, onshow) {
|
|
121
|
+
this._closeCallback = onclose
|
|
122
|
+
|
|
123
|
+
if (this._isLoading || this._isPlaying || !this._isLoad) {
|
|
124
|
+
return
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (this._lastError !== null) {
|
|
128
|
+
this.onError(this._lastError)
|
|
129
|
+
return
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const provider = this.getProvider()
|
|
133
|
+
if (provider === ProviderType.CSJ && this.isExpired) {
|
|
134
|
+
if (this._retry) {
|
|
135
|
+
this._loadAd()
|
|
136
|
+
} else {
|
|
137
|
+
this.onError(this._lastError)
|
|
138
|
+
}
|
|
139
|
+
return
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
this._isPlaying = true
|
|
143
|
+
this._ad.show()
|
|
144
|
+
onshow && onshow()
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
onLoad (e) {
|
|
148
|
+
if (this._loadCallback != null) {
|
|
149
|
+
this._loadCallback()
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
onClose (e) {
|
|
154
|
+
if (this._closeCallback != null) {
|
|
155
|
+
this._closeCallback({
|
|
156
|
+
isEnded: e.isEnded
|
|
157
|
+
})
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
onError (e) {
|
|
162
|
+
if (this._errorCallback != null) {
|
|
163
|
+
this._errorCallback(e)
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
destroy () {
|
|
168
|
+
this._ad.destroy()
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
_loadAd () {
|
|
172
|
+
this._isLoad = false
|
|
173
|
+
this._isLoading = true
|
|
174
|
+
this._lastError = null
|
|
175
|
+
this._ad.load()
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
class RewardedVideo extends AdBase {
|
|
180
|
+
constructor (options = {}) {
|
|
181
|
+
super(plus.ad.createRewardedVideoAd(options), options)
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
class FullScreenVideo extends AdBase {
|
|
186
|
+
constructor (options = {}) {
|
|
187
|
+
super(plus.ad.createFullScreenVideoAd(options), options)
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
class Interstitial extends AdBase {
|
|
192
|
+
constructor (options = {}) {
|
|
193
|
+
super(plus.ad.createInterstitialAd(options), options)
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
class AdHelper {
|
|
198
|
+
constructor (adType) {
|
|
199
|
+
this._ads = {}
|
|
200
|
+
this._adType = adType
|
|
201
|
+
this._lastWaterfallIndex = -1
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
load (options, onload, onerror) {
|
|
205
|
+
if (!options.adpid || this.isBusy(options.adpid)) {
|
|
206
|
+
return
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
this.get(options).load(onload, onerror)
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
show (options, onload, onerror, onclose, onshow) {
|
|
213
|
+
const ad = this.get(options)
|
|
214
|
+
|
|
215
|
+
if (ad.isLoad) {
|
|
216
|
+
this._lastWaterfallIndex = -1
|
|
217
|
+
ad.show((e) => {
|
|
218
|
+
onclose && onclose(e)
|
|
219
|
+
}, () => {
|
|
220
|
+
onshow && onshow()
|
|
221
|
+
})
|
|
222
|
+
} else {
|
|
223
|
+
ad.load(() => {
|
|
224
|
+
this._lastWaterfallIndex = -1
|
|
225
|
+
onload && onload()
|
|
226
|
+
ad.show((e) => {
|
|
227
|
+
onclose && onclose(e)
|
|
228
|
+
}, () => {
|
|
229
|
+
onshow && onshow()
|
|
230
|
+
})
|
|
231
|
+
}, (err) => {
|
|
232
|
+
onerror && onerror(err)
|
|
233
|
+
})
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// 底价预载逻辑
|
|
238
|
+
loadWaterfall (options, onload, onfail, index = 0) {
|
|
239
|
+
const {
|
|
240
|
+
adpid,
|
|
241
|
+
urlCallback
|
|
242
|
+
} = options
|
|
243
|
+
if (!Array.isArray(adpid)) {
|
|
244
|
+
return
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const options2 = {
|
|
248
|
+
adpid: adpid[index],
|
|
249
|
+
urlCallback,
|
|
250
|
+
retry: false
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
console.log('ad.loadWaterfall::index=' + index)
|
|
254
|
+
|
|
255
|
+
this.load(options2, (res) => {
|
|
256
|
+
this._lastWaterfallIndex = index
|
|
257
|
+
onload(options2)
|
|
258
|
+
}, (err) => {
|
|
259
|
+
index++
|
|
260
|
+
if (index >= adpid.length) {
|
|
261
|
+
onfail(err)
|
|
262
|
+
} else {
|
|
263
|
+
this.loadWaterfall(options, onload, onfail, index)
|
|
264
|
+
}
|
|
265
|
+
})
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// 底价逻辑,失败后下一个,无重试机制
|
|
269
|
+
showWaterfall (options, onload, onfail, onclose, onshow, index = 0) {
|
|
270
|
+
const {
|
|
271
|
+
adpid,
|
|
272
|
+
urlCallback
|
|
273
|
+
} = options
|
|
274
|
+
if (!Array.isArray(adpid)) {
|
|
275
|
+
return
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if (this._lastWaterfallIndex > -1) {
|
|
279
|
+
index = this._lastWaterfallIndex
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const options2 = {
|
|
283
|
+
adpid: adpid[index],
|
|
284
|
+
urlCallback,
|
|
285
|
+
retry: false
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
console.log('ad.showWaterfall::index=' + index)
|
|
289
|
+
|
|
290
|
+
this.show(options2, () => {
|
|
291
|
+
onload()
|
|
292
|
+
}, (err) => {
|
|
293
|
+
index++
|
|
294
|
+
if (index >= adpid.length) {
|
|
295
|
+
onfail(err)
|
|
296
|
+
} else {
|
|
297
|
+
this.showWaterfall(options, onload, onfail, onclose, onshow, index)
|
|
298
|
+
}
|
|
299
|
+
}, (res) => {
|
|
300
|
+
onclose(res)
|
|
301
|
+
}, () => {
|
|
302
|
+
onshow()
|
|
303
|
+
})
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// 预载底价瀑布流
|
|
307
|
+
preloadWaterfall (options, index = 0, step = 1) {
|
|
308
|
+
if (step === 1) {
|
|
309
|
+
this.loadWaterfall(options, (res) => {
|
|
310
|
+
console.log('preloadWaterfall.success::', res)
|
|
311
|
+
}, (err) => {
|
|
312
|
+
console.log('loadWaterfall.fail', err)
|
|
313
|
+
})
|
|
314
|
+
return
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
const {
|
|
318
|
+
adpid,
|
|
319
|
+
urlCallback
|
|
320
|
+
} = options
|
|
321
|
+
for (let i = 0; i < step; i++) {
|
|
322
|
+
if (index < adpid.length) {
|
|
323
|
+
const options2 = {
|
|
324
|
+
adpid: adpid[index],
|
|
325
|
+
urlCallback
|
|
326
|
+
}
|
|
327
|
+
this.loadWaterfall(options2, (res) => {
|
|
328
|
+
console.log('preloadWaterfall.success::', res)
|
|
329
|
+
}, (err) => {
|
|
330
|
+
console.log('loadWaterfall.fail', err)
|
|
331
|
+
this.preloadWaterfall(options, index, step)
|
|
332
|
+
})
|
|
333
|
+
index++
|
|
334
|
+
} else {
|
|
335
|
+
break
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
isBusy (adpid) {
|
|
341
|
+
return (this._ads[adpid] && this._ads[adpid].isLoading)
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
get (options) {
|
|
345
|
+
const {
|
|
346
|
+
adpid
|
|
347
|
+
} = options
|
|
348
|
+
|
|
349
|
+
if (!this._ads[adpid]) {
|
|
350
|
+
this._ads[adpid] = this._createInstance(options)
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
return this._ads[adpid]
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
getProvider (adpid) {
|
|
357
|
+
if (this._ads[adpid]) {
|
|
358
|
+
return this._ads[adpid].getProvider()
|
|
359
|
+
}
|
|
360
|
+
return null
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
remove (adpid) {
|
|
364
|
+
if (this._ads[adpid]) {
|
|
365
|
+
this._ads[adpid].destroy()
|
|
366
|
+
delete this._ads[adpid]
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
_createInstance (options) {
|
|
371
|
+
const adType = options.adType || this._adType
|
|
372
|
+
delete options.adType
|
|
373
|
+
|
|
374
|
+
let ad = null
|
|
375
|
+
if (adType === ADType.RewardedVideo) {
|
|
376
|
+
ad = new RewardedVideo(options)
|
|
377
|
+
} else if (adType === ADType.FullScreenVideo) {
|
|
378
|
+
ad = new FullScreenVideo(options)
|
|
379
|
+
} else if (adType === ADType.Interstitial) {
|
|
380
|
+
ad = new Interstitial(options, true)
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
return ad
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
export default {
|
|
388
|
+
props: {
|
|
389
|
+
options: {
|
|
390
|
+
type: [Object, Array],
|
|
391
|
+
default () {
|
|
392
|
+
return {}
|
|
393
|
+
}
|
|
394
|
+
},
|
|
395
|
+
disabled: {
|
|
396
|
+
type: [Boolean, String],
|
|
397
|
+
default: false
|
|
398
|
+
},
|
|
399
|
+
adpid: {
|
|
400
|
+
type: [Number, String, Array],
|
|
401
|
+
default: ''
|
|
402
|
+
},
|
|
403
|
+
preload: {
|
|
404
|
+
type: [Boolean, String],
|
|
405
|
+
default: true
|
|
406
|
+
},
|
|
407
|
+
loadnext: {
|
|
408
|
+
type: [Boolean, String],
|
|
409
|
+
default: false
|
|
410
|
+
},
|
|
411
|
+
urlCallback: {
|
|
412
|
+
type: Object,
|
|
413
|
+
default () {
|
|
414
|
+
return {}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
},
|
|
418
|
+
data () {
|
|
419
|
+
return {
|
|
420
|
+
loading: false,
|
|
421
|
+
errorMessage: null
|
|
422
|
+
}
|
|
423
|
+
},
|
|
424
|
+
watch: {
|
|
425
|
+
adpid (newValue, oldValue) {
|
|
426
|
+
this._removeInstance(oldValue)
|
|
427
|
+
if (this.preload) {
|
|
428
|
+
this._loadAd()
|
|
429
|
+
}
|
|
430
|
+
},
|
|
431
|
+
// 服务器回调透传参数,仅在创建广告实例时可传递参数,如果发生变化需要重新创建广告实例
|
|
432
|
+
urlCallback () {
|
|
433
|
+
this._removeInstance()
|
|
434
|
+
}
|
|
435
|
+
},
|
|
436
|
+
created () {
|
|
437
|
+
this._adHelper = new AdHelper(this.adType)
|
|
438
|
+
|
|
439
|
+
setTimeout(() => {
|
|
440
|
+
if (this.preload) {
|
|
441
|
+
this._loadAd()
|
|
442
|
+
}
|
|
443
|
+
}, 100)
|
|
444
|
+
},
|
|
445
|
+
methods: {
|
|
446
|
+
load () {
|
|
447
|
+
if (this.isLoading) {
|
|
448
|
+
return
|
|
449
|
+
}
|
|
450
|
+
this._startLoading()
|
|
451
|
+
const invoke = this._isWaterfall() ? 'loadWaterfall' : 'load'
|
|
452
|
+
this._adHelper[invoke](this._getAdOptions(), () => {
|
|
453
|
+
this._onLoad()
|
|
454
|
+
}, (err) => {
|
|
455
|
+
this._onLoadFail(err)
|
|
456
|
+
})
|
|
457
|
+
},
|
|
458
|
+
|
|
459
|
+
show () {
|
|
460
|
+
if (this.isLoading) {
|
|
461
|
+
return
|
|
462
|
+
}
|
|
463
|
+
this._startLoading()
|
|
464
|
+
const invoke = this._isWaterfall() ? 'showWaterfall' : 'show'
|
|
465
|
+
this._adHelper[invoke](this._getAdOptions(), () => {
|
|
466
|
+
this._onLoad()
|
|
467
|
+
}, (err) => {
|
|
468
|
+
this._onLoadFail(err)
|
|
469
|
+
}, (res) => {
|
|
470
|
+
this._dispatchEvent(EventType.Close, res)
|
|
471
|
+
|
|
472
|
+
if (this.loadnext) {
|
|
473
|
+
this.load()
|
|
474
|
+
}
|
|
475
|
+
}, () => {
|
|
476
|
+
// show
|
|
477
|
+
this.loading = false
|
|
478
|
+
})
|
|
479
|
+
},
|
|
480
|
+
|
|
481
|
+
getProvider () {
|
|
482
|
+
if (Array.isArray(this.adpid)) {
|
|
483
|
+
return null
|
|
484
|
+
}
|
|
485
|
+
return this._adHelper.getProvider(this.adpid)
|
|
486
|
+
},
|
|
487
|
+
|
|
488
|
+
_loadAd () {
|
|
489
|
+
if (this._canCreateAd()) {
|
|
490
|
+
this.load()
|
|
491
|
+
}
|
|
492
|
+
},
|
|
493
|
+
|
|
494
|
+
_onclick () {
|
|
495
|
+
if (!this.disabled) {
|
|
496
|
+
this.show()
|
|
497
|
+
}
|
|
498
|
+
},
|
|
499
|
+
|
|
500
|
+
_getAdOptions () {
|
|
501
|
+
return {
|
|
502
|
+
adpid: this.adpid,
|
|
503
|
+
urlCallback: this.urlCallback
|
|
504
|
+
}
|
|
505
|
+
},
|
|
506
|
+
|
|
507
|
+
_isWaterfall () {
|
|
508
|
+
return (Array.isArray(this.adpid) && this.adpid.length > 0)
|
|
509
|
+
},
|
|
510
|
+
|
|
511
|
+
_canCreateAd () {
|
|
512
|
+
let result = false
|
|
513
|
+
if (Array.isArray(this.adpid) && this.adpid.length > 0) {
|
|
514
|
+
result = true
|
|
515
|
+
} else if (typeof this.adpid === 'string' && this.adpid.length > 0) {
|
|
516
|
+
result = true
|
|
517
|
+
} else if (typeof this.adpid === 'number') {
|
|
518
|
+
result = true
|
|
519
|
+
}
|
|
520
|
+
return result
|
|
521
|
+
},
|
|
522
|
+
|
|
523
|
+
_removeInstance (adpid) {
|
|
524
|
+
const id = adpid || this.adpid
|
|
525
|
+
if (Array.isArray(id)) {
|
|
526
|
+
id.forEach((item) => {
|
|
527
|
+
this._adHelper.remove(item)
|
|
528
|
+
})
|
|
529
|
+
} else if (id) {
|
|
530
|
+
this._adHelper.remove(id)
|
|
531
|
+
}
|
|
532
|
+
},
|
|
533
|
+
|
|
534
|
+
_startLoading () {
|
|
535
|
+
this.loading = true
|
|
536
|
+
this.errorMessage = null
|
|
537
|
+
},
|
|
538
|
+
|
|
539
|
+
_onLoad () {
|
|
540
|
+
this.loading = false
|
|
541
|
+
this._dispatchEvent(EventType.Load, {})
|
|
542
|
+
},
|
|
543
|
+
|
|
544
|
+
_onLoadFail (err) {
|
|
545
|
+
this.loading = false
|
|
546
|
+
this.errorMessage = JSON.stringify(err)
|
|
547
|
+
this._dispatchEvent(EventType.Error, err)
|
|
548
|
+
},
|
|
549
|
+
|
|
550
|
+
_dispatchEvent (type, data) {
|
|
551
|
+
this.$emit(type, {
|
|
552
|
+
detail: data
|
|
553
|
+
})
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
const EventType = {
|
|
2
|
+
Load: 'load',
|
|
3
|
+
Close: 'close',
|
|
4
|
+
Error: 'error'
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
props: {
|
|
9
|
+
options: {
|
|
10
|
+
type: [Object, Array],
|
|
11
|
+
default () {
|
|
12
|
+
return {}
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
adpid: {
|
|
16
|
+
type: [Number, String],
|
|
17
|
+
default: ''
|
|
18
|
+
},
|
|
19
|
+
unitId: {
|
|
20
|
+
type: [Number, String],
|
|
21
|
+
default: ''
|
|
22
|
+
},
|
|
23
|
+
preload: {
|
|
24
|
+
type: [Boolean, String],
|
|
25
|
+
default: true
|
|
26
|
+
},
|
|
27
|
+
loadnext: {
|
|
28
|
+
type: [Boolean, String],
|
|
29
|
+
default: false
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
data () {
|
|
33
|
+
return {
|
|
34
|
+
loading: false,
|
|
35
|
+
errorMessage: null
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
created () {
|
|
39
|
+
this._ad = null
|
|
40
|
+
setTimeout(() => {
|
|
41
|
+
if (this.preload && this._canCreateAd()) {
|
|
42
|
+
this.load()
|
|
43
|
+
}
|
|
44
|
+
}, 100)
|
|
45
|
+
},
|
|
46
|
+
methods: {
|
|
47
|
+
load () {
|
|
48
|
+
if (this.loading) {
|
|
49
|
+
return
|
|
50
|
+
}
|
|
51
|
+
this._startLoading()
|
|
52
|
+
|
|
53
|
+
setTimeout(() => {
|
|
54
|
+
this._onmpload()
|
|
55
|
+
}, 3000)
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
show () {
|
|
59
|
+
this.errorMessage = null
|
|
60
|
+
this._ad = this.selectComponent('.uniad-plugin')
|
|
61
|
+
this._ad.show()
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
_onclick () {
|
|
65
|
+
this.show()
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
_startLoading () {
|
|
69
|
+
this.loading = true
|
|
70
|
+
this.errorMessage = null
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
_canCreateAd () {
|
|
74
|
+
let result = false
|
|
75
|
+
if (typeof this.adpid === 'string' && this.adpid.length > 0) {
|
|
76
|
+
result = true
|
|
77
|
+
} else if (typeof this.adpid === 'number') {
|
|
78
|
+
result = true
|
|
79
|
+
}
|
|
80
|
+
return result
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
_onmpload (e) {
|
|
84
|
+
this.loading = false
|
|
85
|
+
this._dispatchEvent(EventType.Load, {})
|
|
86
|
+
},
|
|
87
|
+
|
|
88
|
+
_onmpclose (e) {
|
|
89
|
+
this._dispatchEvent(EventType.Close, e.detail)
|
|
90
|
+
},
|
|
91
|
+
|
|
92
|
+
_onmperror (e) {
|
|
93
|
+
this.loading = false
|
|
94
|
+
this.errorMessage = JSON.stringify(e.detail)
|
|
95
|
+
this._dispatchEvent(EventType.Error, e.detail)
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
_dispatchEvent (type, data) {
|
|
99
|
+
this.$emit(type, {
|
|
100
|
+
detail: data
|
|
101
|
+
})
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view @click="onclick">
|
|
3
|
+
<uniad-plugin
|
|
4
|
+
class="uniad-plugin"
|
|
5
|
+
:adpid="adpid"
|
|
6
|
+
:unit-id="unitId"
|
|
7
|
+
@load="_onmpload"
|
|
8
|
+
@close="_onmpclose"
|
|
9
|
+
@error="_onmperror"
|
|
10
|
+
/>
|
|
11
|
+
</view>
|
|
12
|
+
</template>
|
|
13
|
+
|
|
14
|
+
<script>
|
|
15
|
+
import adMixin from './ad.mixin.mp.js'
|
|
16
|
+
export default {
|
|
17
|
+
name: 'Uniad',
|
|
18
|
+
mixins: [adMixin],
|
|
19
|
+
props: {
|
|
20
|
+
},
|
|
21
|
+
methods: {
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
</script>
|
package/lib/cache.js
CHANGED
|
@@ -104,9 +104,14 @@ function updateComponentJson (name, jsonObj, usingComponents = true, type = 'Com
|
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
function updateUsingGlobalComponents (name, usingGlobalComponents) {
|
|
107
|
-
|
|
107
|
+
const manifestConfig = process.UNI_MANIFEST
|
|
108
|
+
const weixinConfig = manifestConfig['mp-weixin']
|
|
109
|
+
const independentSwitch = !!weixinConfig.independent
|
|
110
|
+
|
|
111
|
+
if (!independentSwitch && supportGlobalUsingComponents) {
|
|
108
112
|
return
|
|
109
113
|
}
|
|
114
|
+
|
|
110
115
|
const oldJsonStr = getJsonFile(name)
|
|
111
116
|
if (oldJsonStr) { // update
|
|
112
117
|
const jsonObj = JSON.parse(oldJsonStr)
|
|
@@ -342,6 +347,7 @@ module.exports = {
|
|
|
342
347
|
getWXComponents,
|
|
343
348
|
getGlobalUsingComponents,
|
|
344
349
|
updateAppJson,
|
|
350
|
+
updateJsonFile,
|
|
345
351
|
updatePageJson,
|
|
346
352
|
updateProjectJson,
|
|
347
353
|
updateComponentJson,
|
|
@@ -353,5 +359,6 @@ module.exports = {
|
|
|
353
359
|
updateComponentGenerics,
|
|
354
360
|
updateGenericComponents,
|
|
355
361
|
getChangedJsonFileMap,
|
|
356
|
-
getSpecialMethods
|
|
362
|
+
getSpecialMethods,
|
|
363
|
+
supportGlobalUsingComponents
|
|
357
364
|
}
|
package/lib/index.js
CHANGED
|
@@ -58,7 +58,8 @@ const {
|
|
|
58
58
|
nvueCssPreprocessOptions,
|
|
59
59
|
nvueHtmlPreprocessOptions,
|
|
60
60
|
getPlatformGlobal,
|
|
61
|
-
getPlatformStat
|
|
61
|
+
getPlatformStat,
|
|
62
|
+
getPlatformPush
|
|
62
63
|
} = require('./platform')
|
|
63
64
|
|
|
64
65
|
module.exports = {
|
|
@@ -108,5 +109,6 @@ module.exports = {
|
|
|
108
109
|
nvueCssPreprocessOptions,
|
|
109
110
|
nvueHtmlPreprocessOptions,
|
|
110
111
|
getPlatformGlobal,
|
|
111
|
-
getPlatformStat
|
|
112
|
+
getPlatformStat,
|
|
113
|
+
getPlatformPush
|
|
112
114
|
}
|