@dcloudio/uni-cli-shared 2.0.2-alpha-5000320260310001 → 2.0.2-alpha-5000720260327001

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,6 +41,9 @@ 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: {
@@ -51,15 +54,21 @@ export default {
51
54
  show () {
52
55
  this.errorMessage = null
53
56
 
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
- })
57
+ const res = this._interstitialData
58
+ // 插屏广告返回格式:{ ret: 0, data: [...] }
59
+ if (this._adShow) {
60
+ if (res && res.ret === 0) {
61
+ const id = this._createView()
62
+ // 直接调用 renderAd 渲染插屏广告
63
+ window.TencentGDT.NATIVE.renderAd(res.data[0], id)
64
+ this._dispatchEvent(EventType.Load, {})
65
+ } else {
66
+ this.errorMessage = res ? `Error code: ${res.ret}` : 'No advertisement'
67
+ this._dispatchEvent(EventType.Error, res || { errMsg: 'No advertisement' })
68
+ }
69
+ } else {
70
+ this._dispatchEvent(EventType.Error, this.errorMessage)
71
+ }
63
72
  },
64
73
 
65
74
  _onclick () {
@@ -73,6 +82,25 @@ export default {
73
82
  this._pc = a
74
83
  this._pl = b
75
84
  this.loading = false
85
+
86
+ const data = this._pl[0]
87
+ const providerConfig = this._pc[data.a1]
88
+
89
+ if (data.a1 === '2') {
90
+ if (!window.TencentGDT) {
91
+ window.TencentGDT = window.TencentGDT || []
92
+ }
93
+ // 优量汇(广点通)
94
+ AdScript.instance.load(data.a1, providerConfig.script, () => {
95
+ this._adShow = true
96
+ // 脚本加载成功后初始化
97
+ this._renderGdt(data)
98
+ }, (err) => {
99
+ this._adShow = false
100
+ this.errorMessage = err.message
101
+ this._dispatchEvent(EventType.Error, err)
102
+ })
103
+ }
76
104
  }, (err) => {
77
105
  this.loading = false
78
106
  this.errorMessage = err
@@ -80,24 +108,17 @@ export default {
80
108
  })
81
109
  },
82
110
 
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)
111
+ _renderGdt (data) {
112
+ window.TencentGDT.push({
113
+ placement_id: data.a3, // 广告位ID
114
+ app_id: data.a2, // APP ID
115
+ type: 'native',
116
+ display_type: 'interstitial', // 插屏广告
117
+ count: 1,
118
+ onComplete: (res) => {
119
+ // 缓存数据
120
+ this._interstitialData = res
98
121
  }
99
- }).catch((err) => {
100
- this._dispatchEvent(EventType.Error, err)
101
122
  })
102
123
  },
103
124
 
@@ -303,8 +324,18 @@ class AdScript {
303
324
 
304
325
  loadScript (provider, script) {
305
326
  this._cache[provider] = 0
327
+ const domid = 'uniad_provider' + provider
328
+ // 判断是否已经加载平台sdk
329
+ const adScriptDom = document.getElementById(domid)
330
+ const src = adScriptDom && adScriptDom.getAttribute('src')
331
+ if (src) {
332
+ this._cache[provider] = 1
333
+ return
334
+ }
335
+
306
336
  var ads = document.createElement('script')
307
- ads.setAttribute('id', 'uniad_provider' + provider)
337
+ ads.setAttribute('id', domid)
338
+
308
339
  for (const var1 in script) {
309
340
  ads.setAttribute(var1, script[var1])
310
341
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcloudio/uni-cli-shared",
3
- "version": "2.0.2-alpha-5000320260310001",
3
+ "version": "2.0.2-alpha-5000720260327001",
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": "412e1d109dbf93b8540b1884f22a2f254536e94f"
30
+ "gitHead": "14489ff43cbf4e79691c9b87f057a3d7f3419f3c"
31
31
  }