@dcloudio/uni-cli-shared 2.0.2-alpha-4030520241124001 → 2.0.2-alpha-4040120241205001

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,7 +2,8 @@
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" :adpid="adpid" :unit-id="unitId" @load="_onmpload" @close="_onmpclose" @error="_onmperror"></uniad-plugin>
5
+ <uniad-plugin class="uniad-plugin" :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" @error="_onwxchannelerror"></uniad-plugin-wx>
6
7
  <!-- #endif -->
7
8
  <!-- #ifdef MP-ALIPAY -->
8
9
  <uniad-plugin class="uniad-plugin" :adpid="adpid" @create="_handleAdRef" @load="_onmpload" @close="_onmpclose" @error="_onmperror"></uniad-plugin>
@@ -2,7 +2,8 @@
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" :adpid="adpid" :unit-id="unitId" @load="_onmpload" @close="_onmpclose" @error="_onmperror"></uniad-plugin>
5
+ <uniad-plugin class="uniad-plugin" :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" @error="_onwxchannelerror"></uniad-plugin-wx>
6
7
  <!-- #endif -->
7
8
  <!-- #ifdef MP-ALIPAY -->
8
9
  <uniad-plugin class="uniad-plugin" :adpid="adpid" @create="_handleAdRef" @load="_onmpload" @close="_onmpclose" @error="_onmperror"></uniad-plugin>
@@ -1,8 +1,9 @@
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" :adpid="adpid" :unit-id="unitId" @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" :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" @error="_onwxchannelerror"></uniad-plugin-wx>
6
7
  <!-- #endif -->
7
8
  <!-- #ifdef MP-ALIPAY -->
8
9
  <uniad-plugin class="uniad-plugin" :adpid="adpid" @create="_handleAdRef" @load="_onmpload" @close="_onmpclose" @error="_onmperror"></uniad-plugin>
@@ -1,9 +1,24 @@
1
+ /* eslint-disable no-undef */
2
+ const adPlugin = requirePlugin('uni-ad')
3
+
1
4
  const EventType = {
2
5
  Load: 'load',
3
6
  Close: 'close',
4
7
  Error: 'error'
5
8
  }
6
9
 
10
+ const AdType = {
11
+ Banner: 'banner',
12
+ RewardedVideo: 'rewardedVideo',
13
+ Interstitial: 'interstitial'
14
+ }
15
+
16
+ const ProviderType = {
17
+ WeChat: 10018,
18
+ UserWeChat: 10017,
19
+ ShanHu: 10020
20
+ }
21
+
7
22
  export default {
8
23
  props: {
9
24
  options: {
@@ -38,13 +53,20 @@ export default {
38
53
  data () {
39
54
  return {
40
55
  loading: false,
56
+ userwx: false,
57
+ userUnitId: '',
58
+ wxchannel: false,
41
59
  errorMessage: null
42
60
  }
43
61
  },
44
62
  created () {
45
63
  this._ad = null
46
- if (this.preload && this._canCreateAd()) {
47
- this.load()
64
+ this._loading = false
65
+ this._wxRewardedAd = null
66
+ this._wxInterstitialAd = null
67
+ this._providerType = ProviderType.ShanHu
68
+ if (this.preload && this._canCreateAd()) {
69
+ this.load()
48
70
  }
49
71
  },
50
72
  methods: {
@@ -53,35 +75,22 @@ export default {
53
75
  return
54
76
  }
55
77
  this._startLoading()
78
+ if (this._providerType === ProviderType.ShanHu) {
79
+ } else if (this._providerType === ProviderType.WeChat) {
80
+ this.selectComponent('.uniad-plugin-wx').load()
81
+ } else if (this._providerType === ProviderType.UserWeChat) {
82
+ this._loadWxAd()
83
+ }
56
84
  },
57
85
 
58
- show () {
86
+ show (e) {
59
87
  this.errorMessage = null
60
- this._ad = this.selectComponent('.uniad-plugin')
61
- if (this._hasCallback()) {
62
- const userCryptoManager = wx.getUserCryptoManager()
63
- userCryptoManager.getLatestUserKey({
64
- success: ({
65
- encryptKey,
66
- iv,
67
- version,
68
- expireTime
69
- }) => {
70
- this._ad.show({
71
- userId: this.urlCallback.userId || '',
72
- extra: this.urlCallback.extra || '',
73
- encryptKey,
74
- iv,
75
- version,
76
- expireTime
77
- })
78
- },
79
- fail: (err) => {
80
- this._dispatchEvent(EventType.Error, err)
81
- }
82
- })
83
- } else {
84
- this._ad.show()
88
+ if (this._providerType === ProviderType.ShanHu) {
89
+ this._showAdInPlugin(this.selectComponent('.uniad-plugin'))
90
+ } else if (this._providerType === ProviderType.WeChat) {
91
+ this._showAdInPlugin(this.selectComponent('.uniad-plugin-wx'))
92
+ } else if (this._providerType === ProviderType.UserWeChat) {
93
+ this._showWxAd(e)
85
94
  }
86
95
  },
87
96
 
@@ -148,10 +157,214 @@ export default {
148
157
  this._dispatchEvent(EventType.Error, e.detail)
149
158
  },
150
159
 
160
+ _onnextchannel (e) {
161
+ this.wxchannel = true
162
+ const adData = e.detail[0]
163
+ this.$nextTick(() => {
164
+ if (adData.provider === 10017) {
165
+ this._providerType = ProviderType.UserWeChat
166
+ switch (adData._nt_) {
167
+ case 4:
168
+ this.wxAdType = AdType.Banner
169
+ this.userwx = true
170
+ this.userUnitId = adData.posid
171
+ break
172
+ case 9:
173
+ this.wxAdType = AdType.RewardedVideo
174
+ this._createRewardedAd(adData.posid)
175
+ break
176
+ case 15:
177
+ this.wxAdType = AdType.Interstitial
178
+ this._createInterstitialAd(adData.posid)
179
+ break
180
+ }
181
+ } else if (adData.provider === 10018) {
182
+ this._providerType = ProviderType.WeChat
183
+ this.selectComponent('.uniad-plugin-wx').setConfig(adData)
184
+ }
185
+ })
186
+ },
187
+
188
+ _onwxchannelerror (e) {
189
+ this.wxchannel = false
190
+ this.$nextTick(() => {
191
+ this._providerType = ProviderType.ShanHu
192
+ this.selectComponent('.uniad-plugin').shanhuChannel()
193
+ })
194
+ },
195
+
151
196
  _dispatchEvent (type, data) {
152
197
  this.$emit(type, {
153
198
  detail: data
154
199
  })
200
+ },
201
+
202
+ _showAdInPlugin (adComponent) {
203
+ if (this._hasCallback()) {
204
+ const userCryptoManager = wx.getUserCryptoManager()
205
+ userCryptoManager.getLatestUserKey({
206
+ success: ({
207
+ encryptKey,
208
+ iv,
209
+ version,
210
+ expireTime
211
+ }) => {
212
+ adComponent.show({
213
+ userId: this.urlCallback.userId || '',
214
+ extra: this.urlCallback.extra || '',
215
+ encryptKey,
216
+ iv,
217
+ version,
218
+ expireTime
219
+ })
220
+ },
221
+ fail: (err) => {
222
+ this._dispatchEvent(EventType.Error, err)
223
+ }
224
+ })
225
+ } else {
226
+ adComponent.show({
227
+ userId: this.urlCallback.userId || '',
228
+ extra: this.urlCallback.extra || ''
229
+ })
230
+ }
231
+ },
232
+
233
+ _loadWxAd () {
234
+ switch (this.wxAdType) {
235
+ case AdType.RewardedVideo:
236
+ if (this._wxRewardedAd) {
237
+ this._wxRewardedAd.load()
238
+ }
239
+ break
240
+ case AdType.Interstitial:
241
+ if (this._wxInterstitialAd) {
242
+ this._wxInterstitialAd.load()
243
+ }
244
+ break
245
+ }
246
+ },
247
+
248
+ // 加载/显示广告
249
+ _showWxAd (options) {
250
+ this._urlCallback = options || this.urlCallback
251
+ if (this.loading === true) {
252
+ this._userInvokeShowFlag = true
253
+ return
254
+ }
255
+ switch (this.wxAdType) {
256
+ case AdType.RewardedVideo:
257
+ if (!this._wxRewardedAd) {
258
+ return
259
+ }
260
+ // eslint-disable-next-line handle-callback-err
261
+ this._wxRewardedAd.show().catch((err) => {
262
+ this._wxRewardedAd.load().then(() => {
263
+ this._wxRewardedAd.show()
264
+ }).catch((err) => {
265
+ this._dispatchEvent(EventType.Error, err)
266
+ })
267
+ })
268
+ break
269
+ case AdType.Interstitial:
270
+ if (!this._wxInterstitialAd) {
271
+ return
272
+ }
273
+ // eslint-disable-next-line handle-callback-err
274
+ this._wxInterstitialAd.show().catch((err) => {
275
+ this._wxInterstitialAd.load().then(() => {
276
+ this._wxInterstitialAd.show()
277
+ }).catch((err) => {
278
+ this._dispatchEvent(EventType.Error, err)
279
+ })
280
+ })
281
+ break
282
+ }
283
+ },
284
+
285
+ // 微信激励视频
286
+ _createRewardedAd (adUnitId) {
287
+ if (this._wxRewardedAd) {
288
+ return
289
+ }
290
+
291
+ this._wxRewardedAd = wx.createRewardedVideoAd({ adUnitId: adUnitId, multiton: true })
292
+
293
+ this._wxRewardedAd.onLoad(() => {
294
+ this.loading = false
295
+ this._dispatchEvent(EventType.Load, {})
296
+ if (this._userInvokeShowFlag) {
297
+ this._userInvokeShowFlag = false
298
+ this._wxRewardedAd.show()
299
+ }
300
+ })
301
+
302
+ this._wxRewardedAd.onError(err => {
303
+ this.loading = false
304
+ this._dispatchEvent(EventType.Error, err)
305
+ })
306
+
307
+ this._wxRewardedAd.onClose(res => {
308
+ if (res.isEnded) {
309
+ this._callServer()
310
+ } else {
311
+ this._dispatchEvent(EventType.Close, res)
312
+ }
313
+ })
314
+
315
+ this.loading = true
316
+ },
317
+
318
+ // 微信插屏
319
+ _createInterstitialAd (adUnitId) {
320
+ if (this._wxInterstitialAd) {
321
+ return
322
+ }
323
+
324
+ this._wxInterstitialAd = wx.createInterstitialAd({ adUnitId: adUnitId })
325
+
326
+ this._wxInterstitialAd.onLoad(() => {
327
+ this.loading = false
328
+ this._dispatchEvent(EventType.Load, {})
329
+ if (this._userInvokeShowFlag) {
330
+ this._userInvokeShowFlag = false
331
+ this._wxInterstitialAd.show()
332
+ }
333
+ })
334
+
335
+ this._wxInterstitialAd.onError(err => {
336
+ this.loading = false
337
+ this._dispatchEvent(EventType.Error, err)
338
+ })
339
+
340
+ this._wxInterstitialAd.onClose(res => {
341
+ this._dispatchEvent(EventType.Close, res)
342
+ })
343
+
344
+ this.loading = true
345
+ },
346
+
347
+ _callServer () {
348
+ const userCryptoManager = wx.getUserCryptoManager()
349
+ userCryptoManager.getLatestUserKey({
350
+ success: (encryptConfig) => {
351
+ const callbackData = adPlugin.buildCallbackData(this.adpid, this.urlCallback, {}, encryptConfig)
352
+ uniCloud.callFunction({
353
+ name: 'uniAdCallback',
354
+ data: callbackData,
355
+ secretType: 'both',
356
+ success: (res) => {
357
+ this._dispatchEvent(EventType.Close, res)
358
+ },
359
+ fail: (err) => {
360
+ this._dispatchEvent(EventType.Error, err)
361
+ }
362
+ })
363
+ },
364
+ fail: (err) => {
365
+ this._dispatchEvent(EventType.Error, err)
366
+ }
367
+ })
155
368
  }
156
369
  }
157
370
  }
@@ -5,8 +5,13 @@
5
5
  :adpid="adpid"
6
6
  @load="_onmpload"
7
7
  @close="_onmpclose"
8
- @error="_onmperror"
9
- />
8
+ @error="_onmperror"
9
+ @nextChannel="_onnextchannel"
10
+ />
11
+ <!-- #ifdef MP-WEIXIN -->
12
+ <ad-custom v-if="userwx" :unit-id="userUnitId"></ad-custom>
13
+ <uniad-plugin-wx v-if="wxchannel" class="uniad-plugin-wx" @error="_onwxchannelerror"></uniad-plugin-wx>
14
+ <!-- #endif -->
10
15
  </view>
11
16
  </template>
12
17
 
@@ -393,7 +393,7 @@
393
393
  needLoading: true,
394
394
  loadingTitle: ''
395
395
  }, options);
396
- if (!options.needConfirm) {
396
+ if (options.needConfirm) {
397
397
  uni.showModal({
398
398
  title: options.confirmTitle || t('uniCloud.component.update.showModal.title'),
399
399
  content: options.confirmContent || t('uniCloud.component.update.showModal.content'),
package/lib/preprocess.js CHANGED
@@ -52,14 +52,14 @@ module.exports = function initPreprocess (name, platforms, userDefines = {}) {
52
52
  nvueContext.APP_NVUE = true
53
53
  nvueContext.APP_PLUS_NVUE = true
54
54
 
55
- if (process.env.UNI_APP_PLATFORM === 'android') {
56
- defaultContext.APP_ANDROID = true
57
- } else if (process.env.UNI_APP_PLATFORM === 'ios') {
58
- defaultContext.APP_IOS = true
59
- } else {
60
- defaultContext.APP_ANDROID = true
61
- defaultContext.APP_IOS = true
62
- }
55
+ // if (process.env.UNI_APP_PLATFORM === 'android') {
56
+ // defaultContext.APP_ANDROID = true
57
+ // } else if (process.env.UNI_APP_PLATFORM === 'ios') {
58
+ // defaultContext.APP_IOS = true
59
+ // } else {
60
+ // defaultContext.APP_ANDROID = true
61
+ // defaultContext.APP_IOS = true
62
+ // }
63
63
  }
64
64
  if (name === 'h5') {
65
65
  defaultContext.WEB = true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcloudio/uni-cli-shared",
3
- "version": "2.0.2-alpha-4030520241124001",
3
+ "version": "2.0.2-alpha-4040120241205001",
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": "6e052548a72c646da813a042de984522e9fda9ae"
30
+ "gitHead": "9cfb80aae2eca520db7e52e87a1b31f02597c143"
31
31
  }