@dcloudio/uni-cli-shared 2.0.2-5000720260410001 → 2.0.2-5010520260709001

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.
@@ -41,31 +41,44 @@ export default {
41
41
  created () {
42
42
  this._pc = {}
43
43
  this._pl = []
44
+ this._interstitialData = {}
45
+ this._adShow = false
46
+ this._id = ''
44
47
  this._loadData()
45
48
  },
46
49
  methods: {
50
+ /** 对外 load:仅派发 load 事件(与历史行为一致) */
47
51
  load () {
48
52
  this._dispatchEvent(EventType.Load, {})
49
53
  },
50
54
 
55
+ /** 展示插屏:在 SDK 与素材就绪后调用 GDT NATIVE.renderAd */
51
56
  show () {
52
57
  this.errorMessage = null
53
58
 
54
- const data = this._pl[0]
55
- const providerConfig = this._pc[data.a1][data.t]
56
-
57
- AdScript.instance.load(data.t, providerConfig.script, () => {
58
- this._renderData(data)
59
- }, (err) => {
60
- this.errorMessage = err.message
61
- this._dispatchEvent(EventType.Error, err)
62
- })
59
+ const res = this._interstitialData
60
+ // 插屏广告返回格式:{ ret: 0, data: [...] }
61
+ if (this._adShow) {
62
+ if (res && res.ret === 0) {
63
+ const id = this._createView()
64
+ // 直接调用 renderAd 渲染插屏广告
65
+ window.TencentGDT.NATIVE.renderAd(res.data[0], id)
66
+ this._dispatchEvent(EventType.Load, {})
67
+ } else {
68
+ this.errorMessage = res ? `Error code: ${res.ret}` : 'No advertisement'
69
+ this._dispatchEvent(EventType.Error, res || { errMsg: 'No advertisement' })
70
+ }
71
+ } else {
72
+ this._dispatchEvent(EventType.Error, this.errorMessage)
73
+ }
63
74
  },
64
75
 
76
+ /** 点击插屏区域时尝试展示广告 */
65
77
  _onclick () {
66
78
  this.show()
67
79
  },
68
80
 
81
+ /** 按 adpid 拉取 H5 广告配置并加载优量汇脚本、预请求素材 */
69
82
  _loadData (adpid) {
70
83
  this.loading = true
71
84
  const id = adpid || this.adpid
@@ -73,6 +86,25 @@ export default {
73
86
  this._pc = a
74
87
  this._pl = b
75
88
  this.loading = false
89
+
90
+ const data = this._pl[0]
91
+ const providerConfig = this._pc[data.a1]
92
+
93
+ if (data.a1 === '2') {
94
+ if (!window.TencentGDT) {
95
+ window.TencentGDT = window.TencentGDT || []
96
+ }
97
+ // 优量汇(广点通)
98
+ AdScript.instance.load(data.a1, providerConfig.script, () => {
99
+ this._adShow = true
100
+ // 脚本加载成功后初始化
101
+ this._renderGdt(data)
102
+ }, (err) => {
103
+ this._adShow = false
104
+ this.errorMessage = err.message
105
+ this._dispatchEvent(EventType.Error, err)
106
+ })
107
+ }
76
108
  }, (err) => {
77
109
  this.loading = false
78
110
  this.errorMessage = err
@@ -80,33 +112,29 @@ export default {
80
112
  })
81
113
  },
82
114
 
83
- _renderData (data) {
84
- const id = this._createView()
85
-
86
- const coral = new window.CoralAdv({
87
- app_id: data.a2,
88
- placement_id: data.a3,
89
- type: data.a4,
90
- display_type: data.a5,
91
- container_id: id,
92
- count: 1
93
- })
94
- coral.ready().then(async (res) => {
95
- if (res.ret === 0) {
96
- } else {
97
- this._dispatchEvent(EventType.Error, res)
115
+ /** TencentGDT 队列提交插屏 native 请求,onComplete 写入 _interstitialData */
116
+ _renderGdt (data) {
117
+ window.TencentGDT.push({
118
+ placement_id: data.a3, // 广告位ID
119
+ app_id: data.a2, // APP ID
120
+ type: 'native',
121
+ display_type: 'interstitial', // 插屏广告
122
+ count: 1,
123
+ onComplete: (res) => {
124
+ // 缓存数据
125
+ this._interstitialData = res
98
126
  }
99
- }).catch((err) => {
100
- this._dispatchEvent(EventType.Error, err)
101
127
  })
102
128
  },
103
129
 
130
+ /** 以小程序风格 detail 包装后向父组件派发事件 */
104
131
  _dispatchEvent (type, data) {
105
132
  this.$emit(type, {
106
133
  detail: data
107
134
  })
108
135
  },
109
136
 
137
+ /** 在容器内创建带随机 id 的 DOM 节点,供 renderAd 挂载 */
110
138
  _createView () {
111
139
  const id = this._randomId()
112
140
  const adView = document.createElement('div')
@@ -116,6 +144,7 @@ export default {
116
144
  return id
117
145
  },
118
146
 
147
+ /** 生成 renderAd 容器 DOM id */
119
148
  _randomId () {
120
149
  let result = ''
121
150
  for (let i = 0; i < 4; i++) {
@@ -130,6 +159,7 @@ export default {
130
159
  // let IS = 0
131
160
 
132
161
  class AdConfig {
162
+ /** @returns {AdConfig} 全局单例 */
133
163
  static get instance () {
134
164
  if (this._instance == null) {
135
165
  this._instance = new AdConfig()
@@ -146,10 +176,12 @@ class AdConfig {
146
176
  this._callbacks = []
147
177
  }
148
178
 
179
+ /** @returns 当前内存中的配置体(服务端返回的 data) */
149
180
  get adConfig () {
150
181
  return this._adConfig
151
182
  }
152
183
 
184
+ /** @returns {boolean} 本地缓存是否超过 CACHE_TIME */
153
185
  get isExpired () {
154
186
  if (this._adConfig == null) {
155
187
  return true
@@ -157,6 +189,7 @@ class AdConfig {
157
189
  return (Math.abs(Date.now() - this._adConfig.last) > this.CACHE_TIME)
158
190
  }
159
191
 
192
+ /** 从 localStorage 恢复未过期的配置到内存 */
160
193
  _init () {
161
194
  var config = this._getConfig()
162
195
  if (config === null || !config.last) {
@@ -168,6 +201,12 @@ class AdConfig {
168
201
  }
169
202
  }
170
203
 
204
+ /**
205
+ * 按 adpid 获取配置:优先内存/缓存命中,否则请求 ah5v2 并排队回调
206
+ * @param {string|number} adpid
207
+ * @param {(a: object, b: object[]) => void} success
208
+ * @param {(err: object) => void} fail
209
+ */
171
210
  get (adpid, success, fail) {
172
211
  // IC++
173
212
  if (this._adConfig != null) {
@@ -187,6 +226,7 @@ class AdConfig {
187
226
  this._loadAdConfig(adpid)
188
227
  }
189
228
 
229
+ /** 用当前 _adConfig 解析 adpid 并调用 success 或 fail */
190
230
  _doCallback (adpid, success, fail) {
191
231
  // IS++
192
232
  var { a, b } = this._adConfig
@@ -197,6 +237,7 @@ class AdConfig {
197
237
  }
198
238
  }
199
239
 
240
+ /** 请求远端 H5 广告配置并刷新内存与等待队列 */
200
241
  _loadAdConfig (adpid) {
201
242
  if (this._isLoading === true) {
202
243
  return
@@ -242,6 +283,7 @@ class AdConfig {
242
283
  })
243
284
  }
244
285
 
286
+ /** @returns {{ last: number, data: object }|null} localStorage 中的包装结构 */
245
287
  _getConfig () {
246
288
  if (!navigator.cookieEnabled || !window.localStorage) {
247
289
  return null
@@ -250,6 +292,7 @@ class AdConfig {
250
292
  return data ? JSON.parse(data) : null
251
293
  }
252
294
 
295
+ /** 将服务端 data 与当前时间写入 localStorage */
253
296
  _setConfig (data) {
254
297
  if (!navigator.cookieEnabled || !window.localStorage) {
255
298
  return null
@@ -261,7 +304,8 @@ class AdConfig {
261
304
  }
262
305
  }
263
306
  Object.assign(AdConfig.prototype, {
264
- URL: 'https://hac1.dcloud.net.cn/ah5',
307
+ // 旧版 https://hac1.dcloud.net.cn/ah5 已废弃,配置迁移至 v2(与 Vue3 H5 插屏一致)
308
+ URL: 'https://hac1.dcloud.net.cn/ah5v2',
265
309
  KEY: 'uni_app_ad_config',
266
310
  CACHE_TIME: 1000 * 60 * 10,
267
311
  ERROR_INVALID_ADPID: {
@@ -270,6 +314,7 @@ Object.assign(AdConfig.prototype, {
270
314
  })
271
315
 
272
316
  class AdScript {
317
+ /** @returns {AdScript} 脚本加载器单例 */
273
318
  static get instance () {
274
319
  if (this._instance == null) {
275
320
  this._instance = new AdScript()
@@ -283,6 +328,10 @@ class AdScript {
283
328
  this._cache = {}
284
329
  }
285
330
 
331
+ /**
332
+ * 按渠道加载广告 SDK script,已缓存则同步 success
333
+ * @param {string} provider 渠道标识(如优量汇为 '2')
334
+ */
286
335
  load (provider, script, success, fail) {
287
336
  if (this._cache[provider] === undefined) {
288
337
  this.loadScript(provider, script)
@@ -301,10 +350,21 @@ class AdScript {
301
350
  }
302
351
  }
303
352
 
353
+ /** 向 document 插入 script 节点并处理 onload/onerror 队列 */
304
354
  loadScript (provider, script) {
305
355
  this._cache[provider] = 0
356
+ const domid = 'uniad_provider' + provider
357
+ // 判断是否已经加载平台sdk
358
+ const adScriptDom = document.getElementById(domid)
359
+ const src = adScriptDom && adScriptDom.getAttribute('src')
360
+ if (src) {
361
+ this._cache[provider] = 1
362
+ return
363
+ }
364
+
306
365
  var ads = document.createElement('script')
307
- ads.setAttribute('id', 'uniad_provider' + provider)
366
+ ads.setAttribute('id', domid)
367
+
308
368
  for (const var1 in script) {
309
369
  ads.setAttribute(var1, script[var1])
310
370
  }
package/lib/platform.js CHANGED
@@ -81,7 +81,10 @@ function isEnableConsole () {
81
81
  process.env.NODE_ENV === 'development' &&
82
82
  process.env.UNI_SOCKET_HOSTS &&
83
83
  process.env.UNI_SOCKET_PORT &&
84
- process.env.UNI_SOCKET_ID
84
+ process.env.UNI_SOCKET_ID &&
85
+ // 环境变量传入有bug,临时屏蔽安卓平台开启 uni-console
86
+ process.env.UNI_APP_PLATFORM !== 'android' &&
87
+ process.env.UNI_APP_PLATFORM !== 'ios'
85
88
  )
86
89
  }
87
90
 
@@ -94,6 +97,7 @@ const {
94
97
  vueContext: preprocessContext,
95
98
  nvueContext: nvuePreprocessContext
96
99
  } = global.uniPlugin.preprocess
100
+
97
101
  // TODO 暂时保留原有导出,减少影响,后续再整理一下
98
102
  module.exports = {
99
103
  normalizeNodeModules,
@@ -209,8 +213,9 @@ module.exports = {
209
213
  if (!process.env.UNI_USING_STAT) {
210
214
  return ''
211
215
  }
212
- return process.env.UNI_USING_STAT === '2' ? 'import \'@dcloudio/uni-stat/dist/uni-cloud-stat.es.js\';'
213
- : 'import \'@dcloudio/uni-stat/dist/uni-stat.es.js\';'
216
+ return process.env.UNI_USING_STAT === 'private'
217
+ ? 'import \'@dcloudio/uni-stat/dist/uni-cloud-stat.es.js\';'
218
+ : 'import \'@dcloudio/uni-stat/dist/uni-stat-public.es.js\';'
214
219
  },
215
220
  getPlatformPush () {
216
221
  if (process.env.UNI_PUSH_V1) {
package/lib/stat.js ADDED
@@ -0,0 +1,21 @@
1
+ const { hasOwn } = require('./util')
2
+
3
+ /**
4
+ * 解析统计 enable 开关。
5
+ * 1. 子平台 uniStatistics.enable 显式存在 → 以子为准
6
+ * 2. 否则根 uniStatistics.enable 显式存在 → 继承根
7
+ * 3. 否则默认开启
8
+ */
9
+ function resolveStatEnable (rootStat, platformStat) {
10
+ if (platformStat && hasOwn(platformStat, 'enable')) {
11
+ return platformStat.enable === true
12
+ }
13
+ if (rootStat && hasOwn(rootStat, 'enable')) {
14
+ return rootStat.enable === true
15
+ }
16
+ return true
17
+ }
18
+
19
+ module.exports = {
20
+ resolveStatEnable
21
+ }
package/lib/style.js CHANGED
@@ -36,9 +36,9 @@ function createRpx2Unit (unit, unitRatio, unitPrecision) {
36
36
  * @param {string | number} val
37
37
  * @returns {string}
38
38
  */
39
- return (val) => {
39
+ return function (val) {
40
40
  if (unitRE.test(val)) {
41
- return val.replace(unitRE, (m, $1) => {
41
+ return val.replace(unitRE, function (m, $1) {
42
42
  if (!$1) {
43
43
  return m
44
44
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcloudio/uni-cli-shared",
3
- "version": "2.0.2-5000720260410001",
3
+ "version": "2.0.2-5010520260709001",
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": "82deb22abba40f01d10a6a4deb83b418e0adc266"
30
+ "gitHead": "f17eaf4bf390726fa12db98e6efbe0557841bed0"
31
31
  }