可通过valuetype和open-type指定文案类型。
名称 | 类型 | 默认值 | 是否必填 | 描述 |
|---|---|---|---|---|
adid | string | - | 是 | 广告信息标识,调用nativeAd.onLoad,在回调中获取。 |
adunitid | string | - | 是 | 原生广告位标识,即调用qa.createNativeAd创建原生广告时传入的广告位标识。 说明: 一个adunitid只能绑定在一个ad-button组件上。 |
valuetype | number | 0 | 否 | 按钮安装文案预置类型,仅在中国大陆支持。 valuetype设置值对应文案如下:
|
open-type(1106+) | number | 0 | 否 | 按钮打开文案预置类型,仅在中国大陆支持。 open-type设置值对应文案如下:
|
bindtap | eventhandle | - | 否 | 点击时触发,event.detail = {resultCode} 。 resultCode是number类型,数值含义如下:
|
install-text-value(1103+) | string | - | 否 | 按钮安装文案。 1106版本该属性已废弃,设置无效。 |
open-text-value(1103+) | string | - | 否 | 按钮打开文案。 1106版本该属性已废弃,设置无效。 |
progressbar-color(1103+) | color | - | 否 | 下载过程中按钮的进度条颜色。 说明: 当设置成rgba或者hsla类型颜色值时,从1106版本开始透明度设置无效,指定为不透明。 |
progressbar-background-color(1103+) | color | - | 否 | 下载过程中按钮的背景颜色。 说明: 当设置成rgba或者hsla类型颜色值时,从1106版本开始透明度设置无效,指定为不透明。 |
progressbar-text-color(1103+) | color | #000000 | 否 | 下载过程中按钮的文案颜色。 说明: 当设置成rgba或者hsla类型颜色值时,从1106版本开始透明度设置无效,指定为不透明。 |
样式限制:
名称 | 类型 | 默认值 | 是否必填 | 描述 |
|---|---|---|---|---|
font-size | number | 18px | 否 | 文本尺寸。按钮文本字体大小。取值范围:12px~54px |
width | length | 65px | 否 | 组件宽度。取值范围:不小于55px,最大不能超过屏幕宽度。 |
height | length | 32px | 否 | 组件高度。取值范围:15px~90px |
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版本开始透明度设置无效,指定为不透明。 |
<!-- page.qxml -->
<view class="container">
<view>
<button class="btn" type="default" bindtap="changeValueType">点我修改valueType</button>
<button class="btn" type="default" bindtap="showNativeAd">加载并展示原生广告</button>
<ad-button id='adbuttonid' bindtap="startButton" class='adbutton' valuetype="1"
open-type = "1" progressbar-color="hsla(5, 93%, 5%, 1.00)"
progressbar-background-color='RED' progressbar-text-color="#663377 "
adunitid="{{adUnitId}}" adid="{{addata.adId}}"></ad-button>
<view qa:if="{{native.isShow}}">
<view class="container">
<image qa:if="{{native.isShowImg}}" src="{{native.adImgSrc}}" bindtap="reportNativeClick"></image>
<video id="video" qa:if="{{native.isShowVideo}}" src="{{native.adVideoSrc}}" autoplay="true" bindtap="reportNativeClick" class="ad-video"></video>
</view>
<view qa:if="{{native.isShowData}}">{{native.adData}}</view>
<view qa:if="{{native.errStr}}">{{native.errStr}}</view>
</view>
</view>
</view> // page.js
let nativeAd
Page({
data: {
logs: [],
native: {
adUnitId: 'testy63txaom86',
isShow: false,
adData: {},
isShowImg: false,
isShowVideo: false,
isShowData: false,
errStr: '',
adImgSrc: 'http://cs02-pps-drcn.dbankcdn.com/cc/creative/upload/20191226/b750592e-04be-4132-9971-52494b1e5b43.jpg',
adVideoSrc: ''
},
valuetype: 0
},
onLoad: function () {},
showNativeAd () {
nativeAd = qa.createNativeAd({ adUnitId: this.data.native.adUnitId })
nativeAd.onLoad((data) => {
console.info('ad data loaded: ' + JSON.stringify(data))
this.setData({
['native.adData']: data.adList[0]
})
if (this.data.native.adData) {
if (this.data.native.adData.imgUrlList) {
this.setData({
['native.adImgSrc']: this.data.native.adData.imgUrlList[0],
['native.isShowImg']: true
})
} else {
this.setData({
['native.isShowImg']: false,
['native.adImgSrc']: ''
})
}
let showVideoFlag = false
if (this.data.native.adData.videoUrlList && this.data.native.adData.videoUrlList[0]) {
showVideoFlag = true
this.setData({
['native.adVideoSrc']: this.data.native.adData.videoUrlList[0]
})
} else {
this.setData({
['native.isShowVideo']: false,
['native.adVideoSrc']: ''
})
}
if (this.data.native.isShowImg && showVideoFlag) {
setTimeout(() => {
console.log('show video')
this.setData({
['native.isShowVideo']: true,
['native.isShowImg']: false
})
}, 1000)
}
}
this.setData({
['native.isShow']: true,
['native.errStr']: ''
})
})
const errEvent = (e) => {
console.error('load ad error:' + JSON.stringify(e))
this.setData({
['native.isShowImg']: false,
['native.isShowVideo']: false,
['native.errStr']: JSON.stringify(e),
})
}
nativeAd.onError(errEvent)
nativeAd.load()
},
startButton (e) {
console.log('startButton e.resultCode = '+ e.resultCode)
},
reportNativeClick () {
console.log('reportNativeClick')
},
changeValueType: function (e) {
this.setData({
valuetype: 1
})
}
}) // nativeAdCss
@import "../../../common/lib/weui.css";
.txtclass {
word-break: break-all;
}
.item-container {
margin-bottom: 50px;
margin-right: 60px;
margin-left: 60px;
flex-direction: column;
}
.item-content {
flex-direction: column;
background-color: #ffffff;
padding: 30px;
margin-bottom: 50px;
align-items: flex-start;
}
.adbutton {
height: 70px;
width: 100%;
text-align: center;
margin-bottom: 50px;
background-color:rgba(141 , 175 , 199, 0.5);
color: red;
font-size: 30px;
border-radius: 120px;
}