除了支持 通用属性以外,还支持如下属性。
可通过valuetype和open-type指定文案类型。
名称 | 类型 | 默认值 | 是否必填 | 描述 |
|---|---|---|---|---|
adid | string | - | 是 | 广告信息标识,调用nativeAd.onLoad,在回调中获取。 |
adunitid | string | - | 是 | 原生广告位标识,即调用ad.createNativeAd创建原生广告时传入的广告位标识。 说明: 一个adunitid只能绑定在一个ad-button组件上。 |
valuetype | number | 0 | 否 | 按钮安装文案预置类型,仅在中国大陆支持。 valuetype设置值对应文案如下:
|
open-type(1106+) | number | 0 | 否 | 按钮打开文案预置类型,仅在中国大陆支持。 open-type设置值对应文案如下:
|
install-text-value(1103+) | string | - | 否 | 按钮安装文案。 1106版本该属性已废弃,设置无效。 |
open-text-value(1103+) | string | - | 否 | 按钮打开文案。 1106版本该属性已废弃,设置无效。 |
样式限制:
名称 | 类型 | 默认值 | 是否必填 | 描述 |
|---|---|---|---|---|
font-size | number | 37.5px | 否 | 按钮文本字体大小。取值范围:20px~112.5px |
width | length | 128px | 否 | 组件宽度。取值范围:不小于110px |
height | length | 60px | 否 | 组件高度。取值范围:30px~180px |
opacity(1103+) | float | 1.0 | 否 | 组件透明度。从1106版本开始,此样式设置无效,指定为不透明。 |
border-radius(1103+) | length | 42px | 否 | 组件圆角。 |
color(1103+) | color | #FFFFFF | 否 | 按钮初始文案颜色。background-color和color值过于相似时,这两个字段设置的值无效。 说明: 当设置成rgba或者hsla类型颜色值时,从1106版本开始透明度设置无效,指定为不透明。 |
background-color(1103+) | color | #0A59F7 | 否 | 按钮初始背景颜色。当background-color和color值过于相似时,这两个字段设置的值无效。 说明: 当设置成rgba或者hsla类型颜色值时,从1106版本开始透明度设置无效,指定为不透明。 |
progressbar-color(1103+) | color | - | 否 | 下载过程中按钮的进度条颜色。 说明: 当设置成rgba或者hsla类型颜色值时,从1106版本开始透明度设置无效,指定为不透明。 |
progressbar-background-color(1103+) | color | - | 否 | 下载过程中按钮的背景颜色。 说明: 当设置成rgba或者hsla类型颜色值时,从1106版本开始透明度设置无效,指定为不透明。 |
progressbar-text-color(1103+) | color | #000000 | 否 | 下载过程中按钮的文案颜色。从1106版本开始透明度指定为不透明。 |
transform:scale/scaleX/scaleY(1114+) | float | - | 否 | 动画缩放样式,支持范围为0.8~1.2 |
除了支持 通用事件 以外,还支持如下事件。
名称 | 参数 | 描述 |
|---|---|---|
click | {resultCode: number} | 响应结果,number类型,数值含义如下:
|
<template>
<!-- Only one root node is allowed in template. -->
<div class="container">
<div class="item-container">
<input class="input-text" placeholder="请输入slotid" onchange="setProductIdValue"></input>
<input type="button" class="btn" value="加载并展示原生广告" onclick="showNativeAd()" />
<ad-button class = "adbutton" adunitid="{{native.adUnitId}}" adid="{{native.adData.adId}}"
open-type ="1" valuetype="1" onclick="onAdButtonClick()"></ad-button>
<div if="native.isShow" class="container">
<stack>
<video id="video" if="native.isShowVideo" src="{{native.adVideoSrc}}" autoplay="true" onclick="reportNativeClick()" class="ad-video"></video>
<image if="native.isShowImg" src="{{native.adImgSrc}}" onclick="reportNativeClick()"></image>
</stack>
<text if="native.isShowData">{{native.adData}}</text>
<text if="native.errStr">{{native.errStr}}</text>
<text if="native.isShowDesc">{{native.desc}}</text>
</div>
</div>
</div>
</template>
<style>
.container {
flex: 1;
flex-direction: column;
}
.input-text {
height: 80px;
line-height: 80px;
padding-left: 30px;
padding-right: 30px;
margin-left: 30px;
margin-right: 30px;
border-top-width: 1px;
border-bottom-width: 1px;
border-color: #999999;
font-size: 30px;
background-color: #ffffff;
}
.adbutton {
height: 100px;
width: 600px;
text-align: center;
margin-right: 60px;
margin-left: 60px;
margin-bottom: 50px;
font-size: 30px;
background-color: rgba(176, 14, 136, 0.6);
color: rgba(52, 92, 65, 0.945);
border-radius: 88;
opacity: 0.9;
progressbar-color: rgba(51, 10, 89, 0.931415926);
progressbar-text-color: #8b0000;
progressbar-background-color: hsl(001, 65%, 075%);
}
.btn {
height: 80px;
text-align: center;
border-radius: 5px;
margin-right: 60px;
margin-left: 60px;
margin-bottom: 50px;
color: #ffffff;
font-size: 30px;
background-color: #0faeff;
}
.item-container {
margin-top: 50px;
margin-right: 60px;
margin-left: 60px;
flex-direction: column;
align-items: center;
}
image {
width: 100%;
}
.ad-video {
object-fit: contain;
width: 100%;
height: 415px;
}
</style>
<script>
import ad from '@service.ad'
let nativeAd
export default {
componentName: 'ad',
provider: '',
data: {
native: {
adUnitId: 'testb65czjivt9',
isShow: 'false',
adData: {},
isShowImg: false,
isShowVideo: false,
isShowData: false,
isShowDesc: false,
errStr: '',
adImgSrc: '',
adImgSrc1: '',
adImgSrc2: '',
adVideoSrc: ''
}
},
hideAll() {
this.native.isShow = false
this.native.isShowImg = false
this.native.isShowVideo = false
this.native.isShowDesc = false
},
showNativeAd() {
nativeAd = ad.createNativeAd({ adUnitId: this.native.adUnitId })
nativeAd.onLoad((data) => {
console.info('ad data loaded: ' + JSON.stringify(data))
this.native.adData = data.adList[0]
if (this.native.adData) {
if (this.native.adData.imgUrlList) {
this.native.adImgSrc = this.native.adData.imgUrlList[0]
this.native.isShowImg = true
} else {
this.native.isShowImg = false
this.native.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()
},
reportNativeClick() {
nativeAd.reportAdClick({
'adId': this.native.adData.adId
})
},
setProductIdValue: function (e) {
this.native.adUnitId = e.value
},
onAdButtonClick(event) {
console.error('result code is : ', event.resultCode)
}
}
</script> 版本 | 发布日期 | 描述 |
|---|---|---|
1106 | 2023-06-19 |
|
1103 | 2022-12-26 |
|
1101 | 2022-09-10 |
|
1100 | 2022-08-01 | 第一次正式发布。 |