提交 fc675d7e 编写于 作者: d-u-a's avatar d-u-a

ad: 增加getProvider方法

上级 93203dfd
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<view @click="_onclick"> <view @click="_onclick">
<slot :options="options" :loading="loading" :error="errorMessage" /> <slot :options="options" :loading="loading" :error="errorMessage" />
<!-- #ifdef MP-WEIXIN --> <!-- #ifdef MP-WEIXIN -->
<uniad-plugin class="uni-ad-plugin" :adpid="adpid" :unit-id="unitId" @load="_onmpload" @close="_onmpclose" @error="_onmperror"></uniad-plugin> <uniad-plugin class="uniad-plugin" :adpid="adpid" :unit-id="unitId" @load="_onmpload" @close="_onmpclose" @error="_onmperror"></uniad-plugin>
<!-- #endif --> <!-- #endif -->
</view> </view>
</template> </template>
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<view @click="_onclick"> <view @click="_onclick">
<slot :options="options" :loading="loading" :error="errorMessage" /> <slot :options="options" :loading="loading" :error="errorMessage" />
<!-- #ifdef MP-WEIXIN --> <!-- #ifdef MP-WEIXIN -->
<uniad-plugin class="uni-ad-plugin" :adpid="adpid" :unit-id="unitId" @load="_onmpload" @close="_onmpclose" @error="_onmperror"></uniad-plugin> <uniad-plugin class="uniad-plugin" :adpid="adpid" :unit-id="unitId" @load="_onmpload" @close="_onmpclose" @error="_onmperror"></uniad-plugin>
<!-- #endif --> <!-- #endif -->
</view> </view>
</template> </template>
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<view @click="_onclick"> <view @click="_onclick">
<slot :options="options" :loading="loading" :error="errorMessage" /> <slot :options="options" :loading="loading" :error="errorMessage" />
<!-- #ifdef MP-WEIXIN --> <!-- #ifdef MP-WEIXIN -->
<uniad-plugin class="uni-ad-plugin" :adpid="adpid" :unit-id="unitId" @load="_onmpload" @close="_onmpclose" @error="_onmperror"></uniad-plugin> <uniad-plugin class="uniad-plugin" :adpid="adpid" :unit-id="unitId" @load="_onmpload" @close="_onmpclose" @error="_onmperror"></uniad-plugin>
<!-- #endif --> <!-- #endif -->
</view> </view>
</template> </template>
......
...@@ -19,14 +19,13 @@ const ProviderType = { ...@@ -19,14 +19,13 @@ const ProviderType = {
const RETRY_COUNT = 1 const RETRY_COUNT = 1
class AdBase { class AdBase {
constructor (adInstance, options = {}, interstitial) { constructor (adInstance, options = {}) {
this._isLoad = false this._isLoad = false
this._isLoading = false this._isLoading = false
this._isPlaying = false this._isPlaying = false
this._lastLoadTime = 0 this._lastLoadTime = 0
this._lastError = null this._lastError = null
this._retryCount = 0 this._retryCount = 0
this._isInterstitial = interstitial || false
if (options.retry !== undefined) { if (options.retry !== undefined) {
this._retry = options.retry this._retry = options.retry
} else { } else {
...@@ -140,19 +139,10 @@ class AdBase { ...@@ -140,19 +139,10 @@ class AdBase {
return return
} }
// TODO
if (this._isInterstitial && provider === ProviderType.GDT) {
setTimeout(() => {
this._isPlaying = true
this._ad.show()
onshow && onshow()
}, 1000)
} else {
this._isPlaying = true this._isPlaying = true
this._ad.show() this._ad.show()
onshow && onshow() onshow && onshow()
} }
}
onLoad (e) { onLoad (e) {
if (this._loadCallback != null) { if (this._loadCallback != null) {
...@@ -199,8 +189,8 @@ class FullScreenVideo extends AdBase { ...@@ -199,8 +189,8 @@ class FullScreenVideo extends AdBase {
} }
class Interstitial extends AdBase { class Interstitial extends AdBase {
constructor (options = {}, interstitial) { constructor (options = {}) {
super(plus.ad.createInterstitialAd(options), options, interstitial) super(plus.ad.createInterstitialAd(options), options)
} }
} }
...@@ -208,6 +198,7 @@ class AdHelper { ...@@ -208,6 +198,7 @@ class AdHelper {
constructor (adType) { constructor (adType) {
this._ads = {} this._ads = {}
this._adType = adType this._adType = adType
this._lastWaterfallIndex = -1
} }
load (options, onload, onerror) { load (options, onload, onerror) {
...@@ -251,6 +242,10 @@ class AdHelper { ...@@ -251,6 +242,10 @@ class AdHelper {
return return
} }
if (index === 0) {
this._lastWaterfallIndex = -1
}
const options2 = { const options2 = {
adpid: adpid[index], adpid: adpid[index],
urlCallback, urlCallback,
...@@ -258,6 +253,7 @@ class AdHelper { ...@@ -258,6 +253,7 @@ class AdHelper {
} }
this.load(options2, (res) => { this.load(options2, (res) => {
this._lastWaterfallIndex = index
onload(options2) onload(options2)
}, (err) => { }, (err) => {
index++ index++
...@@ -280,8 +276,13 @@ class AdHelper { ...@@ -280,8 +276,13 @@ class AdHelper {
return return
} }
let idx = index
if (this._lastWaterfallIndex > -1) {
idx = this._lastWaterfallIndex
}
const options2 = { const options2 = {
adpid: adpid[index], adpid: adpid[idx],
urlCallback, urlCallback,
retry: false retry: false
} }
...@@ -352,6 +353,13 @@ class AdHelper { ...@@ -352,6 +353,13 @@ class AdHelper {
return this._ads[adpid] return this._ads[adpid]
} }
getProvider (adpid) {
if (this._ads[adpid]) {
return this._ads[adpid].getProvider()
}
return null
}
remove (adpid) { remove (adpid) {
if (this._ads[adpid]) { if (this._ads[adpid]) {
this._ads[adpid].destroy() this._ads[adpid].destroy()
...@@ -464,6 +472,13 @@ export default { ...@@ -464,6 +472,13 @@ export default {
}) })
}, },
getProvider () {
if (Array.isArray(this.adpid)) {
return null
}
return this._adHelper.getProvider(this.adpid)
},
_loadAd () { _loadAd () {
if (this._canCreateAd()) { if (this._canCreateAd()) {
this.load() this.load()
......
...@@ -57,7 +57,7 @@ export default { ...@@ -57,7 +57,7 @@ export default {
show () { show () {
this.errorMessage = null this.errorMessage = null
this._ad = this.selectComponent('.uni-ad') this._ad = this.selectComponent('.uniad-plugin')
this._ad.show() this._ad.show()
}, },
...@@ -70,6 +70,16 @@ export default { ...@@ -70,6 +70,16 @@ export default {
this.errorMessage = null 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) { _onmpload (e) {
this.loading = false this.loading = false
this._dispatchEvent(EventType.Load, {}) this._dispatchEvent(EventType.Load, {})
......
<template> <template>
<view @click="onclick"> <view @click="onclick">
<uni-ad-plugin <uniad-plugin
class="uni-ad-plugin" class="uniad-plugin"
:adpid="adpid" :adpid="adpid"
:unit-id="unitId" :unit-id="unitId"
@load="_onmpload" @load="_onmpload"
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
<script> <script>
import adMixin from './ad.mixin.mp.js' import adMixin from './ad.mixin.mp.js'
export default { export default {
name: 'UniAd', name: 'Uniad',
mixins: [adMixin], mixins: [adMixin],
props: { props: {
}, },
......
...@@ -121,6 +121,9 @@ module.exports = { ...@@ -121,6 +121,9 @@ module.exports = {
// (可用的原生微信小程序组件,global+scoped) // (可用的原生微信小程序组件,global+scoped)
options.mp.wxComponents = options.wxComponents || Object.create(null) options.mp.wxComponents = options.wxComponents || Object.create(null)
Object.assign(options.mp.wxComponents, {
'uniad-plugin': 'plugin://uni-ad/ad'
})
const state = { const state = {
ast: {}, ast: {},
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册