@dcloudio/uni-cli-shared 2.0.2-4080720251210002 → 2.0.2-5000420260318002

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.
@@ -2,11 +2,11 @@
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" data-com-type="wx" :adpid="adpid" :unit-id="unitId" @load="_onmpload" @close="_onmpclose" @error="_onmperror" @nextChannel="_onnextchannel"></uniad-plugin>
5
+ <uniad-plugin class="uniad-plugin" data-com-type="wx" :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" data-com-type="wx" @load="_onmpload" @close="_onmpclose" @error="_onwxchannelerror"></uniad-plugin-wx>
7
- <!-- #endif -->
8
- <!-- #ifdef MP-ALIPAY -->
9
- <uniad-plugin class="uniad-plugin" :adpid="adpid" @create="_handleAdRef" @load="_onmpload" @close="_onmpclose" @error="_onmperror"></uniad-plugin>
7
+ <!-- #endif -->
8
+ <!-- #ifdef MP-ALIPAY -->
9
+ <uniad-plugin class="uniad-plugin" :adpid="adpid" @create="_handleAdRef" @load="_onmpload" @close="_onmpclose" @error="_onmperror"></uniad-plugin>
10
10
  <!-- #endif -->
11
11
  <!-- #ifdef H5 -->
12
12
  <div ref="container" />
@@ -24,8 +24,8 @@
24
24
  // #ifdef MP-WEIXIN
25
25
  import adMixin from "./ad.mixin.mp-weixin.js"
26
26
  // #endif
27
- // #ifdef MP-ALIPAY
28
- import adMixin from "./ad.mixin.mp-alipay.js"
27
+ // #ifdef MP-ALIPAY
28
+ import adMixin from "./ad.mixin.mp-alipay.js"
29
29
  // #endif
30
30
 
31
31
  export default {
@@ -1,12 +1,12 @@
1
1
  <template>
2
2
  <view @click="_onclick">
3
- <slot :options="options" :loading="loading" :error="errorMessage" />
4
- <!-- #ifdef MP-WEIXIN -->
5
- <uniad-plugin class="uniad-plugin" data-com-type="wx" :adpid="adpid" :unit-id="unitId" @load="_onmpload" @close="_onmpclose" @error="_onmperror" @nextChannel="_onnextchannel"></uniad-plugin>
6
- <uniad-plugin-wx v-if="wxchannel" class="uniad-plugin-wx" data-com-type="wx" @load="_onmpload" @close="_onmpclose" @error="_onwxchannelerror"></uniad-plugin-wx>
7
- <!-- #endif -->
8
- <!-- #ifdef MP-ALIPAY -->
9
- <uniad-plugin class="uniad-plugin" :adpid="adpid" @create="_handleAdRef" @load="_onmpload" @close="_onmpclose" @error="_onmperror"></uniad-plugin>
3
+ <slot :options="options" :loading="loading" :error="errorMessage" />
4
+ <!-- #ifdef MP-WEIXIN -->
5
+ <uniad-plugin class="uniad-plugin" :isUni="true" data-com-type="wx" :adpid="adpid" :unit-id="unitId" @load="_onmpload" @close="_onmpclose" @error="_onmperror" @nextChannel="_onnextchannel"></uniad-plugin>
6
+ <uniad-plugin-wx v-if="wxchannel" class="uniad-plugin-wx" data-com-type="wx" @load="_onmpload" @close="_onmpclose" @error="_onwxchannelerror"></uniad-plugin-wx>
7
+ <!-- #endif -->
8
+ <!-- #ifdef MP-ALIPAY -->
9
+ <uniad-plugin class="uniad-plugin" :adpid="adpid" @create="_handleAdRef" @load="_onmpload" @close="_onmpclose" @error="_onmperror"></uniad-plugin>
10
10
  <!-- #endif -->
11
11
  </view>
12
12
  </template>
@@ -20,9 +20,9 @@
20
20
  // #endif
21
21
  // #ifdef MP-WEIXIN
22
22
  import adMixin from "./ad.mixin.mp-weixin.js"
23
- // #endif
24
- // #ifdef MP-ALIPAY
25
- import adMixin from "./ad.mixin.mp-alipay.js"
23
+ // #endif
24
+ // #ifdef MP-ALIPAY
25
+ import adMixin from "./ad.mixin.mp-alipay.js"
26
26
  // #endif
27
27
 
28
28
  export default {
@@ -1,4 +1,4 @@
1
- /* eslint-disable no-undef */
1
+ /* eslint-disable no-undef */
2
2
  const adPlugin = requirePlugin('uni-ad')
3
3
 
4
4
  const EventType = {
@@ -19,8 +19,22 @@ const ProviderType = {
19
19
  ShanHu: 10020
20
20
  }
21
21
 
22
+ const ActionType = {
23
+ ServerRequest: '-3',
24
+ AdRequest: '-1',
25
+ Show: '40',
26
+ Click: '41'
27
+ }
28
+
22
29
  export default {
30
+ options: {
31
+ virtualHost: true
32
+ },
23
33
  props: {
34
+ style: {
35
+ type: String,
36
+ default: ''
37
+ },
24
38
  options: {
25
39
  type: [Object, Array],
26
40
  default () {
@@ -43,6 +57,10 @@ export default {
43
57
  type: [Boolean, String],
44
58
  default: false
45
59
  },
60
+ adIntervals: {
61
+ type: [Number, String],
62
+ default: ''
63
+ },
46
64
  urlCallback: {
47
65
  type: Object,
48
66
  default () {
@@ -54,7 +72,7 @@ export default {
54
72
  return {
55
73
  loading: false,
56
74
  userwx: false,
57
- userUnitId: '',
75
+ userUnitId: '',
58
76
  customFullscreen: '',
59
77
  wxchannel: false,
60
78
  errorMessage: null
@@ -64,7 +82,7 @@ export default {
64
82
  this._ad = null
65
83
  this._loading = false
66
84
  this._wxRewardedAd = null
67
- this._wxInterstitialAd = null
85
+ this._wxInterstitialAd = null
68
86
  this._userInvokeShowFlag = false
69
87
  this._providerType = ProviderType.ShanHu
70
88
  if (this.preload && this._canCreateAd()) {
@@ -87,10 +105,10 @@ export default {
87
105
  },
88
106
 
89
107
  show (e) {
90
- this.errorMessage = null
91
- if (this.loading) {
92
- this._userInvokeShowFlag = true
93
- return
108
+ this.errorMessage = null
109
+ if (this.loading) {
110
+ this._userInvokeShowFlag = true
111
+ return
94
112
  }
95
113
  if (this._providerType === ProviderType.ShanHu) {
96
114
  this._showAdInPlugin(this.selectComponent('.uniad-plugin'))
@@ -126,16 +144,17 @@ export default {
126
144
 
127
145
  _onmpload (e) {
128
146
  this.loading = false
129
- this._dispatchEvent(EventType.Load, {})
130
- if (this._userInvokeShowFlag) {
131
- this._userInvokeShowFlag = false
132
- setTimeout(() => {
133
- this.show()
134
- }, 1)
147
+ this._dispatchEvent(EventType.Load, {})
148
+ this._report(ActionType.AdRequest)
149
+ if (this._userInvokeShowFlag) {
150
+ this._userInvokeShowFlag = false
151
+ setTimeout(() => {
152
+ this.show()
153
+ }, 1)
135
154
  }
136
155
  },
137
156
 
138
- _onmpclose (e) {
157
+ _onmpclose (e) {
139
158
  const detail = e.detail || e
140
159
  this._dispatchEvent(EventType.Close, detail)
141
160
  if (detail.adsdata) {
@@ -169,6 +188,7 @@ export default {
169
188
  this.loading = false
170
189
  this.errorMessage = JSON.stringify(e.detail)
171
190
  this._dispatchEvent(EventType.Error, e.detail)
191
+ this._report(ActionType.AdRequest, e.detail)
172
192
  },
173
193
 
174
194
  _onnextchannel (e) {
@@ -181,9 +201,9 @@ export default {
181
201
  case 4:
182
202
  this.wxAdType = AdType.Banner
183
203
  this.userwx = true
184
- this.userUnitId = adData.posid
185
- if (adData.tmpl_type === 24) {
186
- this.customFullscreen = 'uni-ad-custom-fullscreen'
204
+ this.userUnitId = adData.posid
205
+ if (adData.tmpl_type === 24) {
206
+ this.customFullscreen = 'uni-ad-custom-fullscreen'
187
207
  }
188
208
  break
189
209
  case 9:
@@ -196,20 +216,22 @@ export default {
196
216
  break
197
217
  }
198
218
  } else if (adData.provider === 10018) {
199
- this._providerType = ProviderType.WeChat
200
- if (adData.tmpl_type === 24) {
201
- this.customFullscreen = 'uni-ad-custom-fullscreen'
202
- }
203
- this.loading = true
204
- if (!adData.dcloudAdpid) {
205
- adData.dcloudAdpid = this.adpid
219
+ this._providerType = ProviderType.WeChat
220
+ if (adData.tmpl_type === 24) {
221
+ this.customFullscreen = 'uni-ad-custom-fullscreen'
222
+ }
223
+ this.loading = true
224
+ if (!adData.dcloudAdpid) {
225
+ adData.dcloudAdpid = this.adpid
206
226
  }
207
227
  this.selectComponent('.uniad-plugin-wx').setConfig(adData)
208
228
  }
209
229
  })
210
230
  },
211
-
212
- _onwxchannelerror (e) {
231
+ _customFullscreen () {
232
+ this.customFullscreen = 'uni-ad-custom-fullscreen'
233
+ },
234
+ _onwxchannelerror (e) {
213
235
  this._dispatchEvent(EventType.Error, e.detail || e)
214
236
  },
215
237
 
@@ -228,9 +250,9 @@ export default {
228
250
  iv,
229
251
  version,
230
252
  expireTime
231
- }) => {
232
- const uniOptions = {
233
- adpid: this.adpid
253
+ }) => {
254
+ const uniOptions = {
255
+ adpid: this.adpid
234
256
  }
235
257
  adComponent.show({
236
258
  userId: this.urlCallback.userId || '',
@@ -238,7 +260,7 @@ export default {
238
260
  encryptKey,
239
261
  iv,
240
262
  version,
241
- expireTime,
263
+ expireTime,
242
264
  uniOptions
243
265
  })
244
266
  },
@@ -284,19 +306,25 @@ export default {
284
306
  case AdType.RewardedVideo:
285
307
  if (!this._wxRewardedAd) {
286
308
  return
287
- }
309
+ }
288
310
  // eslint-disable-next-line handle-callback-err
289
- this._wxRewardedAd.show().catch((err) => {
311
+ this._wxRewardedAd.show().then(() => {
312
+ this._report(ActionType.Show)
313
+ }).catch((err) => {
290
314
  this._dispatchEvent(EventType.Error, err)
315
+ this._report(ActionType.Show, err)
291
316
  })
292
317
  break
293
318
  case AdType.Interstitial:
294
319
  if (!this._wxInterstitialAd) {
295
320
  return
296
- }
321
+ }
297
322
  // eslint-disable-next-line handle-callback-err
298
- this._wxInterstitialAd.show().catch((err) => {
323
+ this._wxInterstitialAd.show().then(() => {
324
+ this._report(ActionType.Show)
325
+ }).catch((err) => {
299
326
  this._dispatchEvent(EventType.Error, err)
327
+ this._report(ActionType.Show, err)
300
328
  })
301
329
  break
302
330
  }
@@ -313,6 +341,7 @@ export default {
313
341
  this._wxRewardedAd.onLoad(() => {
314
342
  this.loading = false
315
343
  this._dispatchEvent(EventType.Load, {})
344
+ this._report(ActionType.AdRequest)
316
345
  if (this._userInvokeShowFlag) {
317
346
  this._userInvokeShowFlag = false
318
347
  this._wxRewardedAd.show()
@@ -320,21 +349,21 @@ export default {
320
349
  })
321
350
 
322
351
  this._wxRewardedAd.onError(err => {
323
- this.loading = false
352
+ this.loading = false
324
353
  this.errorMessage = JSON.stringify(err)
325
354
  this._dispatchEvent(EventType.Error, err)
326
355
  })
327
356
 
328
- this._wxRewardedAd.onClose(res => {
357
+ this._wxRewardedAd.onClose(res => {
329
358
  this._dispatchEvent(EventType.Close, res)
330
359
  if (res.isEnded && this._hasCallback()) {
331
360
  this._callServer()
332
361
  }
333
- })
334
-
335
- this._wxRewardedAd.load().then(() => {
336
- }).catch((_) => {
337
- })
362
+ })
363
+
364
+ this._wxRewardedAd.load().then(() => {
365
+ }).catch((_) => {
366
+ })
338
367
 
339
368
  this.loading = true
340
369
  },
@@ -350,6 +379,7 @@ export default {
350
379
  this._wxInterstitialAd.onLoad(() => {
351
380
  this.loading = false
352
381
  this._dispatchEvent(EventType.Load, {})
382
+ this._report(ActionType.AdRequest)
353
383
  if (this._userInvokeShowFlag) {
354
384
  this._userInvokeShowFlag = false
355
385
  this._wxInterstitialAd.show().catch((err) => {
@@ -359,17 +389,19 @@ export default {
359
389
  })
360
390
 
361
391
  this._wxInterstitialAd.onError(err => {
362
- this.loading = false
392
+ this.loading = false
363
393
  this.errorMessage = JSON.stringify(err)
364
394
  this._dispatchEvent(EventType.Error, err)
395
+ this._report(ActionType.AdRequest, err)
365
396
  })
366
397
 
367
398
  this._wxInterstitialAd.onClose(res => {
368
399
  this._dispatchEvent(EventType.Close, res)
369
- })
370
-
400
+ })
401
+
371
402
  this._wxInterstitialAd.load().catch((err) => {
372
403
  this._dispatchEvent(EventType.Error, err)
404
+ this._report(ActionType.AdRequest, err)
373
405
  })
374
406
 
375
407
  this.loading = true
@@ -400,6 +432,18 @@ export default {
400
432
 
401
433
  toJSON () {
402
434
  return ''
435
+ },
436
+
437
+ _report (type, detail) {
438
+ const adComponent = this.selectComponent('.uniad-plugin')
439
+ if (adComponent && adComponent._unireport) {
440
+ adComponent._unireport({
441
+ isUni: true,
442
+ adpid: this.adpid,
443
+ type,
444
+ detail: detail || ''
445
+ })
446
+ }
403
447
  }
404
448
  }
405
449
  }
@@ -1,40 +1,52 @@
1
- <template>
2
- <view @click="onclick">
3
- <uniad-plugin
4
- class="uniad-plugin"
5
- :adpid="adpid"
6
- @load="_onmpload"
7
- @close="_onmpclose"
1
+ <template>
2
+ <view :class="[customFullscreen?'uni-ad-custom':'',customFullscreen]" :style="style" @click="onclick">
3
+ <uniad-plugin
4
+ class="uniad-plugin"
5
+ :adpid="adpid"
6
+ :isUni="true"
7
+ :adIntervals="adIntervals"
8
+ @load="_onmpload"
9
+ @close="_onmpclose"
8
10
  @error="_onmperror"
9
- @nextChannel="_onnextchannel"
11
+ @nextChannel="_onnextchannel"
12
+ @customFullscreen="_customFullscreen"
10
13
  />
11
14
  <!-- #ifdef MP-WEIXIN -->
12
- <ad-custom v-if="userwx" :unit-id="userUnitId" class="uni-ad-custom" data-com-type="wx" :class="[customFullscreen]" @load="_onmpload" @error="_onmperror"></ad-custom>
13
- <uniad-plugin-wx v-if="wxchannel" class="uniad-plugin-wx" :class="[customFullscreen]" data-com-type="wx" @load="_onmpload" @error="_onwxchannelerror"></uniad-plugin-wx>
14
- <!-- #endif -->
15
- </view>
16
- </template>
17
-
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>
16
+ <!-- <uniad-plugin-wx v-if="wxchannel" class="uniad-plugin-wx" :class="[customFullscreen]" data-com-type="wx" @load="_onmpload" @error="_onwxchannelerror"></uniad-plugin-wx> -->
17
+ <!-- #endif -->
18
+ </view>
19
+ </template>
20
+
18
21
  <script>
19
- // #ifdef MP-WEIXIN
20
- import adMixin from "./ad.mixin.mp-weixin.js"
22
+ // #ifdef MP-WEIXIN
23
+ import adMixin from "./ad.mixin.mp-weixin.js"
21
24
  // #endif
22
25
  // #ifdef MP-ALIPAY
23
26
  import adMixin from "./ad.mixin.mp-alipay.js"
24
- // #endif
25
- export default {
26
- name: 'Uniad',
27
- mixins: [adMixin],
28
- props: {
29
- },
30
- methods: {
31
- }
32
- }
33
- </script>
27
+ // #endif
28
+ export default {
29
+ name: 'Uniad',
30
+ mixins: [adMixin],
31
+ props: {
32
+ },
33
+ methods: {
34
+ }
35
+ }
36
+ </script>
34
37
 
35
38
  <style>
36
39
  .uni-ad-custom-fullscreen {
37
- display: flex;
38
- height: 100vh;
40
+ display: flex;
41
+ height: 100vh;
42
+ }
43
+ .uni-ad-custom {
44
+ display: flex;
45
+ flex: 1;
46
+ width: 100%;
47
+ }
48
+ .uniad-plugin {
49
+ display: flex;
50
+ flex: 1;
39
51
  }
40
52
  </style>
package/lib/cache.js CHANGED
@@ -200,6 +200,18 @@ function updateUsingComponents (name, usingComponents, type, content = '') {
200
200
  }
201
201
  if (oldJsonStr) { // update
202
202
  jsonObj.usingComponents = usingComponents
203
+ // 嵌套组件获取 props 为 null,使用占组件修正父子组件生命周期执行顺序 https://developer.open-douyin.com/docs/resource/zh-CN/mini-app/develop/tutorial/custom-component/placeholder
204
+ if (process.env.UNI_PLATFORM === 'mp-toutiao') {
205
+ if (type === 'Component') {
206
+ const usingComponentnames = Object.keys(jsonObj.usingComponents)
207
+ if (usingComponentnames.length) {
208
+ jsonObj.componentPlaceholder = {}
209
+ usingComponentnames.forEach(componentName => {
210
+ jsonObj.componentPlaceholder[componentName] = 'view'
211
+ })
212
+ }
213
+ }
214
+ }
203
215
  const newJsonStr = JSON.stringify(jsonObj, null, 2)
204
216
  if (newJsonStr !== oldJsonStr) {
205
217
  updateJsonFile(name, newJsonStr)
package/lib/index.js CHANGED
@@ -74,6 +74,14 @@ const {
74
74
  initTheme
75
75
  } = require('./theme')
76
76
 
77
+ const {
78
+ createRpx2Unit,
79
+ defaultRpx2Unit,
80
+ unitRE,
81
+ setRpx2Unit,
82
+ getRpx2Unit
83
+ } = require('./style')
84
+
77
85
  module.exports = {
78
86
  uts,
79
87
  md5,
@@ -130,5 +138,10 @@ module.exports = {
130
138
  getPlatformUniCloud,
131
139
  parseTheme,
132
140
  initTheme,
133
- getDevUniConsoleCode
141
+ getDevUniConsoleCode,
142
+ createRpx2Unit,
143
+ defaultRpx2Unit,
144
+ unitRE,
145
+ setRpx2Unit,
146
+ getRpx2Unit
134
147
  }
package/lib/pages.js CHANGED
@@ -329,6 +329,14 @@ function generateGlobalUsingComponentsCode (usingComponents) {
329
329
  return `${importCode.join(';')};${componentsCode.join(';')};`
330
330
  }
331
331
 
332
+ function getSubpackageRoots () {
333
+ const pagesJson = getPagesJson()
334
+ if (Array.isArray(pagesJson.subPackages) && pagesJson.subPackages.length) {
335
+ return pagesJson.subPackages.map(({ root }) => root).filter(Boolean)
336
+ }
337
+ return []
338
+ }
339
+
332
340
  function getGlobalUsingComponentsCode () {
333
341
  const pagesJson = getPagesJson()
334
342
  const usingComponents = pagesJson.globalStyle && pagesJson.globalStyle.usingComponents
@@ -575,6 +583,7 @@ module.exports = {
575
583
  parsePages,
576
584
  parseEntry,
577
585
  getPagesJson,
586
+ getSubpackageRoots,
578
587
  parsePagesJson,
579
588
  pagesJsonJsFileName,
580
589
  getAutoComponents,
package/lib/style.js ADDED
@@ -0,0 +1,60 @@
1
+ const unitRE = new RegExp('"[^"]+"|\'[^\']+\'|url\\([^)]+\\)|(\\d*\\.?\\d+)[r|u]px', 'g')
2
+
3
+ function toFixed (number, precision) {
4
+ const multiplier = Math.pow(10, precision + 1)
5
+ const wholeNumber = Math.floor(number * multiplier)
6
+ return (Math.round(wholeNumber / 10) * 10) / multiplier
7
+ }
8
+
9
+ const defaultRpx2Unit = {
10
+ unit: 'rem',
11
+ unitRatio: 10 / 320,
12
+ unitPrecision: 5
13
+ }
14
+
15
+ const Rpx2Unit = Object.assign({}, defaultRpx2Unit)
16
+
17
+ function setRpx2Unit (config) {
18
+ return Object.assign(config, defaultRpx2Unit)
19
+ }
20
+
21
+ function getRpx2Unit () {
22
+ return Rpx2Unit
23
+ }
24
+
25
+ function _rpx2Unit (rpx, unit, unitRatio, unitPrecision) {
26
+ if (unitRatio === 1) {
27
+ return `${rpx}${unit}`
28
+ }
29
+ const value = toFixed(rpx * unitRatio, unitPrecision)
30
+ return value === 0 ? '0' : `${value}${unit}`
31
+ }
32
+
33
+ function createRpx2Unit (unit, unitRatio, unitPrecision) {
34
+ // ignore: rpxCalcIncludeWidth
35
+ /**
36
+ * @param {string | number} val
37
+ * @returns {string}
38
+ */
39
+ return (val) => {
40
+ if (unitRE.test(val)) {
41
+ return val.replace(unitRE, (m, $1) => {
42
+ if (!$1) {
43
+ return m
44
+ }
45
+
46
+ return _rpx2Unit(parseFloat($1), unit, unitRatio, unitPrecision)
47
+ })
48
+ } else {
49
+ return _rpx2Unit(parseFloat(val), unit, unitRatio, unitPrecision)
50
+ }
51
+ }
52
+ }
53
+
54
+ module.exports = {
55
+ unitRE,
56
+ defaultRpx2Unit,
57
+ setRpx2Unit,
58
+ getRpx2Unit,
59
+ createRpx2Unit
60
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcloudio/uni-cli-shared",
3
- "version": "2.0.2-4080720251210002",
3
+ "version": "2.0.2-5000420260318002",
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": "18c75eccfcdabb303c0675cafdc44bc3cf58d7be"
30
+ "gitHead": "5ee212292b880f06dde5d198e5ceb09f9d3769e1"
31
31
  }