@dcloudio/uni-cli-shared 2.0.2-3081220230817001 → 2.0.2-3090520231028001
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.
|
@@ -4,13 +4,19 @@
|
|
|
4
4
|
<!-- #ifdef MP-WEIXIN -->
|
|
5
5
|
<uniad-plugin class="uniad-plugin" :adpid="adpid" :unit-id="unitId" @load="_onmpload" @close="_onmpclose" @error="_onmperror"></uniad-plugin>
|
|
6
6
|
<!-- #endif -->
|
|
7
|
+
<!-- #ifdef H5 -->
|
|
8
|
+
<div ref="container" />
|
|
9
|
+
<!-- #endif -->
|
|
7
10
|
</view>
|
|
8
11
|
</template>
|
|
9
12
|
|
|
10
13
|
<script>
|
|
11
|
-
// #
|
|
14
|
+
// #ifdef APP
|
|
12
15
|
import adMixin from "./ad.mixin.js"
|
|
13
16
|
// #endif
|
|
17
|
+
// #ifdef H5
|
|
18
|
+
import adMixin from "./ad-interstitial.web.js"
|
|
19
|
+
// #endif
|
|
14
20
|
// #ifdef MP-WEIXIN
|
|
15
21
|
import adMixin from "./ad.mixin.mp.js"
|
|
16
22
|
// #endif
|
|
@@ -0,0 +1,327 @@
|
|
|
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
|
+
preload: {
|
|
20
|
+
type: [Boolean, String],
|
|
21
|
+
default: true
|
|
22
|
+
},
|
|
23
|
+
loadnext: {
|
|
24
|
+
type: [Boolean, String],
|
|
25
|
+
default: false
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
watch: {
|
|
29
|
+
adpid (val) {
|
|
30
|
+
if (val) {
|
|
31
|
+
this._loadData(val)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
data () {
|
|
36
|
+
return {
|
|
37
|
+
loading: false,
|
|
38
|
+
errorMessage: null
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
created () {
|
|
42
|
+
this._pc = {}
|
|
43
|
+
this._pl = []
|
|
44
|
+
this._loadData()
|
|
45
|
+
},
|
|
46
|
+
methods: {
|
|
47
|
+
load () {
|
|
48
|
+
this._dispatchEvent(EventType.Load, {})
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
show () {
|
|
52
|
+
this.errorMessage = null
|
|
53
|
+
|
|
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
|
+
})
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
_onclick () {
|
|
66
|
+
this.show()
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
_loadData (adpid) {
|
|
70
|
+
this.loading = true
|
|
71
|
+
const id = adpid || this.adpid
|
|
72
|
+
AdConfig.instance.get(id, (a, b) => {
|
|
73
|
+
this._pc = a
|
|
74
|
+
this._pl = b
|
|
75
|
+
this.loading = false
|
|
76
|
+
}, (err) => {
|
|
77
|
+
this.loading = false
|
|
78
|
+
this.errorMessage = err
|
|
79
|
+
this._dispatchEvent(EventType.Error, err)
|
|
80
|
+
})
|
|
81
|
+
},
|
|
82
|
+
|
|
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)
|
|
98
|
+
}
|
|
99
|
+
}).catch((err) => {
|
|
100
|
+
this._dispatchEvent(EventType.Error, err)
|
|
101
|
+
})
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
_dispatchEvent (type, data) {
|
|
105
|
+
this.$emit(type, {
|
|
106
|
+
detail: data
|
|
107
|
+
})
|
|
108
|
+
},
|
|
109
|
+
|
|
110
|
+
_createView () {
|
|
111
|
+
const id = this._randomId()
|
|
112
|
+
const adView = document.createElement('div')
|
|
113
|
+
adView.setAttribute('id', id)
|
|
114
|
+
this.$refs.container.innerHTML = ''
|
|
115
|
+
this.$refs.container.append(adView)
|
|
116
|
+
return id
|
|
117
|
+
},
|
|
118
|
+
|
|
119
|
+
_randomId () {
|
|
120
|
+
let result = ''
|
|
121
|
+
for (let i = 0; i < 4; i++) {
|
|
122
|
+
result += (65536 * (1 + Math.random()) | 0).toString(16).substring(1)
|
|
123
|
+
}
|
|
124
|
+
return '_u' + result
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// let IC = 0
|
|
130
|
+
// let IS = 0
|
|
131
|
+
|
|
132
|
+
class AdConfig {
|
|
133
|
+
static get instance () {
|
|
134
|
+
if (this._instance == null) {
|
|
135
|
+
this._instance = new AdConfig()
|
|
136
|
+
this._instance._init()
|
|
137
|
+
}
|
|
138
|
+
return this._instance
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
constructor () {
|
|
142
|
+
this._instance = null
|
|
143
|
+
this._adConfig = null
|
|
144
|
+
this._isLoading = false
|
|
145
|
+
this._lastError = null
|
|
146
|
+
this._callbacks = []
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
get adConfig () {
|
|
150
|
+
return this._adConfig
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
get isExpired () {
|
|
154
|
+
if (this._adConfig == null) {
|
|
155
|
+
return true
|
|
156
|
+
}
|
|
157
|
+
return (Math.abs(Date.now() - this._adConfig.last) > this.CACHE_TIME)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
_init () {
|
|
161
|
+
var config = this._getConfig()
|
|
162
|
+
if (config === null || !config.last) {
|
|
163
|
+
return
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (!this.isExpired) {
|
|
167
|
+
this._adConfig = config.data
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
get (adpid, success, fail) {
|
|
172
|
+
// IC++
|
|
173
|
+
if (this._adConfig != null) {
|
|
174
|
+
this._doCallback(adpid, success, fail)
|
|
175
|
+
if (this.isExpired) {
|
|
176
|
+
this._loadAdConfig(adpid)
|
|
177
|
+
}
|
|
178
|
+
return
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
this._callbacks.push({
|
|
182
|
+
adpid: adpid,
|
|
183
|
+
success: success,
|
|
184
|
+
fail: fail
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
this._loadAdConfig(adpid)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
_doCallback (adpid, success, fail) {
|
|
191
|
+
// IS++
|
|
192
|
+
var { a, b } = this._adConfig
|
|
193
|
+
if (a[adpid]) {
|
|
194
|
+
success(b, a[adpid])
|
|
195
|
+
} else {
|
|
196
|
+
fail(this.ERROR_INVALID_ADPID)
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
_loadAdConfig (adpid) {
|
|
201
|
+
if (this._isLoading === true) {
|
|
202
|
+
return
|
|
203
|
+
}
|
|
204
|
+
this._isLoading = true
|
|
205
|
+
|
|
206
|
+
uni.request({
|
|
207
|
+
url: this.URL,
|
|
208
|
+
method: 'GET',
|
|
209
|
+
timeout: 8000,
|
|
210
|
+
data: {
|
|
211
|
+
d: location.hostname,
|
|
212
|
+
a: adpid
|
|
213
|
+
},
|
|
214
|
+
dataType: 'json',
|
|
215
|
+
success: (res) => {
|
|
216
|
+
const rd = res.data
|
|
217
|
+
if (rd.ret === 0) {
|
|
218
|
+
const data = rd.data
|
|
219
|
+
|
|
220
|
+
this._adConfig = data
|
|
221
|
+
this._setConfig(data)
|
|
222
|
+
|
|
223
|
+
this._callbacks.forEach(({ adpid, success, fail }) => {
|
|
224
|
+
this._doCallback(adpid, success, fail)
|
|
225
|
+
})
|
|
226
|
+
} else {
|
|
227
|
+
this._callbacks.forEach((i) => {
|
|
228
|
+
i.fail({ errCode: rd.ret, errMsg: rd.msg })
|
|
229
|
+
})
|
|
230
|
+
}
|
|
231
|
+
this._callbacks = []
|
|
232
|
+
},
|
|
233
|
+
fail: (err) => {
|
|
234
|
+
this._callbacks.forEach((i) => {
|
|
235
|
+
i.fail(err)
|
|
236
|
+
})
|
|
237
|
+
this._callbacks = []
|
|
238
|
+
},
|
|
239
|
+
complete: (c) => {
|
|
240
|
+
this._isLoading = false
|
|
241
|
+
}
|
|
242
|
+
})
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
_getConfig () {
|
|
246
|
+
if (!navigator.cookieEnabled || !window.localStorage) {
|
|
247
|
+
return null
|
|
248
|
+
}
|
|
249
|
+
var data = localStorage.getItem(this.KEY)
|
|
250
|
+
return data ? JSON.parse(data) : null
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
_setConfig (data) {
|
|
254
|
+
if (!navigator.cookieEnabled || !window.localStorage) {
|
|
255
|
+
return null
|
|
256
|
+
}
|
|
257
|
+
localStorage.setItem(this.KEY, JSON.stringify({
|
|
258
|
+
last: Date.now(),
|
|
259
|
+
data: data
|
|
260
|
+
}))
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
Object.assign(AdConfig.prototype, {
|
|
264
|
+
URL: 'https://hac1.dcloud.net.cn/ah5',
|
|
265
|
+
KEY: 'uni_app_ad_config',
|
|
266
|
+
CACHE_TIME: 1000 * 60 * 10,
|
|
267
|
+
ERROR_INVALID_ADPID: {
|
|
268
|
+
'-5002': 'invalid adpid'
|
|
269
|
+
}
|
|
270
|
+
})
|
|
271
|
+
|
|
272
|
+
class AdScript {
|
|
273
|
+
static get instance () {
|
|
274
|
+
if (this._instance == null) {
|
|
275
|
+
this._instance = new AdScript()
|
|
276
|
+
}
|
|
277
|
+
return this._instance
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
constructor () {
|
|
281
|
+
this._instance = null
|
|
282
|
+
this._callback = {}
|
|
283
|
+
this._cache = {}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
load (provider, script, success, fail) {
|
|
287
|
+
if (this._cache[provider] === undefined) {
|
|
288
|
+
this.loadScript(provider, script)
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
if (this._cache[provider] === 1) {
|
|
292
|
+
success()
|
|
293
|
+
} else {
|
|
294
|
+
if (!this._callback[provider]) {
|
|
295
|
+
this._callback[provider] = []
|
|
296
|
+
}
|
|
297
|
+
this._callback[provider].push({
|
|
298
|
+
success,
|
|
299
|
+
fail
|
|
300
|
+
})
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
loadScript (provider, script) {
|
|
305
|
+
this._cache[provider] = 0
|
|
306
|
+
var ads = document.createElement('script')
|
|
307
|
+
ads.setAttribute('id', 'uniad_provider' + provider)
|
|
308
|
+
for (const var1 in script) {
|
|
309
|
+
ads.setAttribute(var1, script[var1])
|
|
310
|
+
}
|
|
311
|
+
ads.onload = () => {
|
|
312
|
+
this._cache[provider] = 1
|
|
313
|
+
this._callback[provider].forEach(({ success }) => {
|
|
314
|
+
success()
|
|
315
|
+
})
|
|
316
|
+
this._callback[provider].length = 0
|
|
317
|
+
}
|
|
318
|
+
ads.onerror = (err) => {
|
|
319
|
+
this._cache[provider] = undefined
|
|
320
|
+
this._callback[provider].forEach(({ fail }) => {
|
|
321
|
+
fail(err)
|
|
322
|
+
})
|
|
323
|
+
this._callback[provider].length = 0
|
|
324
|
+
}
|
|
325
|
+
document.body.append(ads)
|
|
326
|
+
}
|
|
327
|
+
}
|
package/lib/preprocess.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const DEFAULT_KEYS = [
|
|
2
|
+
'UNI-APP-X',
|
|
2
3
|
'VUE2',
|
|
3
4
|
'VUE3',
|
|
4
5
|
'MP',
|
|
@@ -21,6 +22,8 @@ module.exports = function initPreprocess (name, platforms, userDefines = {}) {
|
|
|
21
22
|
|
|
22
23
|
const defaultContext = {}
|
|
23
24
|
|
|
25
|
+
defaultContext.uniVersion = parseFloat(process.env.UNI_COMPILER_VERSION) || 0
|
|
26
|
+
|
|
24
27
|
const userDefineKeys = Object.keys(userDefines)
|
|
25
28
|
|
|
26
29
|
platforms
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dcloudio/uni-cli-shared",
|
|
3
|
-
"version": "2.0.2-
|
|
3
|
+
"version": "2.0.2-3090520231028001",
|
|
4
4
|
"description": "uni-cli-shared",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -26,5 +26,5 @@
|
|
|
26
26
|
"postcss-urlrewrite": "^0.2.2",
|
|
27
27
|
"strip-json-comments": "^2.0.1"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "bcea69220d435b282e82aa6118f402c996333c55"
|
|
30
30
|
}
|