@dcloudio/uni-cli-shared 2.0.1-alpha-34620220415002 → 2.0.1-alpha-34820220426002

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