From cb4c0b877b4c164a9d76d7a8ab26ed3be3571bbc Mon Sep 17 00:00:00 2001 From: handongxun Date: Mon, 13 Jan 2020 18:01:51 +0800 Subject: [PATCH] =?UTF-8?q?update:=20=E4=BC=98=E5=8C=96=20=20=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E9=87=8D=E5=A4=8D=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app-plus/view/components/ad/index.vue | 46 +++++++++++++------ 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/src/platforms/app-plus/view/components/ad/index.vue b/src/platforms/app-plus/view/components/ad/index.vue index 02ae7b54..b8ed9fee 100644 --- a/src/platforms/app-plus/view/components/ad/index.vue +++ b/src/platforms/app-plus/view/components/ad/index.vue @@ -13,6 +13,35 @@ import { } from 'uni-mixins' import native from '../../mixins/native' +const _adDataCache = {} +function getAdData (adpid, adWidth, onsuccess, onerror) { + const key = adpid + '-' + adWidth + const adDataList = _adDataCache[key] + if (adDataList && adDataList.length > 0) { + onsuccess(adDataList.splice(0, 1)[0]) + return + } + + plus.ad.getAds( + { + adpid: adpid, + count: 10, + width: adWidth + }, + (res) => { + const list = res.ads + onsuccess(list.splice(0, 1)[0]) + _adDataCache[key] = adDataList ? adDataList.concat(list) : list + }, + (err) => { + onerror({ + errCode: err.code, + errMsg: err.message + }) + } + ) +} + const methods = [ 'draw' ] @@ -135,19 +164,10 @@ export default { } }, _loadData (adpid) { - plus.ad.getAds({ - adpid: adpid || this.adpid, - count: 1, - width: this.position.width - }, - (res) => { - this._fillData(res.ads[0]) - }, - (err) => { - this.$trigger('error', {}, { - errCode: err.code, - errMsg: err.message - }) + getAdData(adpid || this.adpid, this.position.width, (data) => { + this._fillData(data) + }, (err) => { + this.$trigger('error', err) }) }, _fillData (data) { -- GitLab