From fc675d7ee7fbfac2f409b0a86384eb8cedd8a46a Mon Sep 17 00:00:00 2001 From: handongxun Date: Wed, 27 Apr 2022 14:32:52 +0800 Subject: [PATCH] =?UTF-8?q?ad:=20=E5=A2=9E=E5=8A=A0getProvider=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/ad-fullscreen-video.vue | 2 +- .../components/ad-interstitial.vue | 2 +- .../components/ad-rewarded-video.vue | 2 +- .../uni-cli-shared/components/ad.mixin.js | 49 ++++++++++++------- .../uni-cli-shared/components/ad.mixin.mp.js | 12 ++++- packages/uni-cli-shared/components/uniad.vue | 6 +-- packages/uni-template-compiler/lib/index.js | 5 +- 7 files changed, 53 insertions(+), 25 deletions(-) diff --git a/packages/uni-cli-shared/components/ad-fullscreen-video.vue b/packages/uni-cli-shared/components/ad-fullscreen-video.vue index 4c81942f4..e809894a0 100644 --- a/packages/uni-cli-shared/components/ad-fullscreen-video.vue +++ b/packages/uni-cli-shared/components/ad-fullscreen-video.vue @@ -2,7 +2,7 @@ - + diff --git a/packages/uni-cli-shared/components/ad-interstitial.vue b/packages/uni-cli-shared/components/ad-interstitial.vue index c561793b5..af258270a 100644 --- a/packages/uni-cli-shared/components/ad-interstitial.vue +++ b/packages/uni-cli-shared/components/ad-interstitial.vue @@ -2,7 +2,7 @@ - + diff --git a/packages/uni-cli-shared/components/ad-rewarded-video.vue b/packages/uni-cli-shared/components/ad-rewarded-video.vue index 3d81f81fc..64644467b 100644 --- a/packages/uni-cli-shared/components/ad-rewarded-video.vue +++ b/packages/uni-cli-shared/components/ad-rewarded-video.vue @@ -2,7 +2,7 @@ - + diff --git a/packages/uni-cli-shared/components/ad.mixin.js b/packages/uni-cli-shared/components/ad.mixin.js index d541ed7d6..62121c38a 100644 --- a/packages/uni-cli-shared/components/ad.mixin.js +++ b/packages/uni-cli-shared/components/ad.mixin.js @@ -19,14 +19,13 @@ const ProviderType = { const RETRY_COUNT = 1 class AdBase { - constructor (adInstance, options = {}, interstitial) { + constructor (adInstance, options = {}) { this._isLoad = false this._isLoading = false this._isPlaying = false this._lastLoadTime = 0 this._lastError = null this._retryCount = 0 - this._isInterstitial = interstitial || false if (options.retry !== undefined) { this._retry = options.retry } else { @@ -140,18 +139,9 @@ class AdBase { return } - // TODO - if (this._isInterstitial && provider === ProviderType.GDT) { - setTimeout(() => { - this._isPlaying = true - this._ad.show() - onshow && onshow() - }, 1000) - } else { - this._isPlaying = true - this._ad.show() - onshow && onshow() - } + this._isPlaying = true + this._ad.show() + onshow && onshow() } onLoad (e) { @@ -199,8 +189,8 @@ class FullScreenVideo extends AdBase { } class Interstitial extends AdBase { - constructor (options = {}, interstitial) { - super(plus.ad.createInterstitialAd(options), options, interstitial) + constructor (options = {}) { + super(plus.ad.createInterstitialAd(options), options) } } @@ -208,6 +198,7 @@ class AdHelper { constructor (adType) { this._ads = {} this._adType = adType + this._lastWaterfallIndex = -1 } load (options, onload, onerror) { @@ -251,6 +242,10 @@ class AdHelper { return } + if (index === 0) { + this._lastWaterfallIndex = -1 + } + const options2 = { adpid: adpid[index], urlCallback, @@ -258,6 +253,7 @@ class AdHelper { } this.load(options2, (res) => { + this._lastWaterfallIndex = index onload(options2) }, (err) => { index++ @@ -280,8 +276,13 @@ class AdHelper { return } + let idx = index + if (this._lastWaterfallIndex > -1) { + idx = this._lastWaterfallIndex + } + const options2 = { - adpid: adpid[index], + adpid: adpid[idx], urlCallback, retry: false } @@ -352,6 +353,13 @@ class AdHelper { return this._ads[adpid] } + getProvider (adpid) { + if (this._ads[adpid]) { + return this._ads[adpid].getProvider() + } + return null + } + remove (adpid) { if (this._ads[adpid]) { this._ads[adpid].destroy() @@ -464,6 +472,13 @@ export default { }) }, + getProvider () { + if (Array.isArray(this.adpid)) { + return null + } + return this._adHelper.getProvider(this.adpid) + }, + _loadAd () { if (this._canCreateAd()) { this.load() diff --git a/packages/uni-cli-shared/components/ad.mixin.mp.js b/packages/uni-cli-shared/components/ad.mixin.mp.js index 808794052..ea507591d 100644 --- a/packages/uni-cli-shared/components/ad.mixin.mp.js +++ b/packages/uni-cli-shared/components/ad.mixin.mp.js @@ -57,7 +57,7 @@ export default { show () { this.errorMessage = null - this._ad = this.selectComponent('.uni-ad') + this._ad = this.selectComponent('.uniad-plugin') this._ad.show() }, @@ -70,6 +70,16 @@ export default { this.errorMessage = null }, + _canCreateAd () { + let result = false + if (typeof this.adpid === 'string' && this.adpid.length > 0) { + result = true + } else if (typeof this.adpid === 'number') { + result = true + } + return result + }, + _onmpload (e) { this.loading = false this._dispatchEvent(EventType.Load, {}) diff --git a/packages/uni-cli-shared/components/uniad.vue b/packages/uni-cli-shared/components/uniad.vue index 4d9f02feb..7387d6201 100644 --- a/packages/uni-cli-shared/components/uniad.vue +++ b/packages/uni-cli-shared/components/uniad.vue @@ -1,7 +1,7 @@