智能客服
你问我答,随时在线为你解决问题
用来展示广告内容的组件
支持
除了支持 通用属性以外,还支持如下属性。
名称 | 类型 | 默认值 | 是否必填 | 描述 |
|---|---|---|---|---|
adid | string | - | 是 | 广告信息标识,由onload回调返回。 |
adunitid | string | - | 是 | 原生广告位标识。一个adunitid只能绑定在一个ad-button组件上。 |
有限制地支持 通用样式 (不支持background和background-image,不支持padding,padding-left,padding-right,padding-top,padding-bottom,不支持opacity样式),受限制的通用样式如下:
名称 | 类型 | 默认值 | 是否必填 | 描述 |
|---|---|---|---|---|
background-color | <color> | 无 | 否 | 组件背景颜色,当设置成rgba或者hsla类型颜色值时,透明度通道设置无效,指定为不透明。当背景颜色不设置时,会默认为白色或黑色(跟随系统深色模式设置) |
注意:该组件必须完全在屏幕范围内。
支持 通用事件
<template>
<!-- Only one root node is allowed in template. -->
<div class="container">
<div class="item-container">
<input type="button" class="btn" value="加载并展示原生广告" onclick="showNativeAd()" />
</div>
<div class="parent">
<ad-native-view class="clickable" adunitid="{{native.adUnitId}}" adid="{{native.adData.adId}}">
<image adindex="0" class="ad-view-image1"></image>
<ad-button if="native.isShow" class="adbutton" adunitid="{{native.adUnitId}}" adid="{{native.adData.adId}}"></ad-button>
</ad-native-view>
</div>
</div>
</template>
<style>
.container {
flex: 1;
flex-direction: column;
}
.adbutton {
height: 80px;
width: 600px;
text-align: center;
margin-top: 300px;
margin-right: 60px;
margin-left: 60px;
margin-bottom: 50px;
color: #dd6522;
font-size: 30px;
border-radius: 50;
}
.btn {
height: 80px;
width: 600px;
text-align: center;
margin-top: 20px;
margin-right: 60px;
margin-left: 60px;
margin-bottom: 50px;
color: #dd6522;
font-size: 30px;
background-color: #0faeff;
border-radius: 50;
}
.item-container {
margin-top: 50px;
flex-direction: column;
}
.ad-view-image1 {
height: 200px;
width: 450px;
opacity: 0.5;
margin-left: 150px;
margin-top: 70px;
}
.clickable {
height: 600px;
width: 750px;
padding-left: 200px;
}
</style>
<script>
import ad from '@service.ad'
import device from '@system.device'
import router from '@system.router'
let nativeAd
export default {
componentName: 'ad',
provider: '',
data: {
hcztransparent: "transparent",
native: {
adUnitId: 'testy63txaom86',
channel: 'this is channel',
isShow: false,
adData: {},
isShowImg: false,
isShowVideo: false,
isShowData: false,
isShowDesc: false,
errStr: '',
adImgSrc: '',
adImgSrc1: '',
adImgSrc2: '',
adVideoSrc: '',
adIcon: '',
},
},
onInit: function () {
this.$page.setStatusBar({ immersive: true, textStyle: 'dark', backgroundColor: '#FFFFFF', backgroundOpacity: 0, visible: true });
var queryString = JSON.stringify(this.$page.query)
console.log("query result: " + queryString);
},
hideAll() {
this.native.isShow = false
this.native.isShowImg = false
this.native.isShowVideo = false
this.native.isShowDesc = false
},
showNativeAd() {
let that = this;
device.host({
success: function (ret) {
console.log("handling success: " + JSON.stringify(ret));
},
fail: function (erromsg, errocode) {
console.log("handling success: " + errocode + ': ' + erromsg)
},
});
this.native.isShowImg = false
nativeAd = ad.createNativeAd({
adUnitId: this.native.adUnitId,
channel: this.native.channel
})
nativeAd.onLoad((data) => {
console.info('ad data loaded: ' + JSON.stringify(data))
this.native.adData = data.adList[0]
if (this.adidList === '') {
this.adidList = this.native.adData.adId
}
if (this.native.adData) {
if (this.native.adData.imgUrlList) {
this.native.adImgSrc = this.native.adData.imgUrlList[0]
this.native.isShowImg = true
} else if (this.native.adData.adIcon) {
this.native.isShowImg = true
this.native.adImgSrc = this.native.adData.adIcon[0]
} else {
this.native.isShowImg = false
this.showNativeAd.adImgSrc = ''
}
if (this.native.adData.desc) {
this.native.desc = this.native.adData.desc
this.native.isShowDesc = true
}
let showVideoFlag = false
if (this.native.adData.videoUrlList && this.native.adData.videoUrlList[0]) {
this.native.adVideoSrc = this.native.adData.videoUrlList[0]
showVideoFlag = true
} else {
this.native.isShowVideo = false
this.native.adVideoSrc = ''
}
if (this.native.isShowImg && showVideoFlag) {
setTimeout(() => {
this.native.isShowVideo = true
this.native.isShowImg = false
}, 1000)
}
}
this.native.isShow = true
this.native.errStr = ''
})
nativeAd.onError((e) => {
console.error('load ad error:' + JSON.stringify(e))
this.native.isShowImg = false
this.native.isShowVideo = false
})
nativeAd.load()
}
}
</script> 版本 | 发布日期 | 描述 |
|---|---|---|
1111 | 2024-03-06 | 第一次正式发布。 |