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

ad: 增加getProvider方法

上级 93203dfd
......@@ -2,7 +2,7 @@
<view @click="_onclick">
<slot :options="options" :loading="loading" :error="errorMessage" />
<!-- #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 -->
</view>
</template>
......
......@@ -2,7 +2,7 @@
<view @click="_onclick">
<slot :options="options" :loading="loading" :error="errorMessage" />
<!-- #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 -->
</view>
</template>
......
......@@ -2,7 +2,7 @@
<view @click="_onclick">
<slot :options="options" :loading="loading" :error="errorMessage" />
<!-- #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 -->
</view>
</template>
......
......@@ -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()
......
......@@ -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, {})
......
<template>
<view @click="onclick">
<uni-ad-plugin
class="uni-ad-plugin"
<uniad-plugin
class="uniad-plugin"
:adpid="adpid"
:unit-id="unitId"
@load="_onmpload"
......@@ -14,7 +14,7 @@
<script>
import adMixin from './ad.mixin.mp.js'
export default {
name: 'UniAd',
name: 'Uniad',
mixins: [adMixin],
props: {
},
......
......@@ -120,7 +120,10 @@ module.exports = {
options.mp.filterModules = Object.keys(options.filterModules || {})
// (可用的原生微信小程序组件,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 = {
ast: {},
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册