目录

ad-button(1100+)

概述

原生广告组件,用于下载原生广告中的广告主App。

使用限制

限制条件

说明

适用终端

手机、平板、智慧屏、车机

适用区域

全球

子组件

不支持。

属性

除了支持 通用属性以外,还支持如下属性。

可通过valuetype和open-type指定文案类型。

名称

类型

默认值

是否必填

描述

adid

string

-

是

广告信息标识,调用nativeAd.onLoad,在回调中获取。

adunitid

string

-

是

原生广告位标识,即调用ad.createNativeAd创建原生广告时传入的广告位标识。

说明:

一个adunitid只能绑定在一个ad-button组件上。

valuetype

number

0

否

按钮安装文案预置类型,仅在中国大陆支持。

valuetype设置值对应文案如下:

  • 0:安装
  • 1:下载并领取
  • 2:安装并领取
  • 3:安装并收下
  • 4:安装并兑换
  • 5:立即下载领取
  • 6:下载并解锁
  • 7:立即下载查看
  • 8:下载立即阅读
  • 9:下载解锁精彩章节
  • 10:安装并领取
  • 11:快速安装
  • 12:安装并提现

open-type(1106+)

number

0

否

按钮打开文案预置类型,仅在中国大陆支持。

open-type设置值对应文案如下:

  • 0:打开
  • 1:打开并领取
  • 2:打开查看
  • 3:打开并解锁
  • 4:立即打开
  • 5:打开应用
  • 6:打开APP

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

  1. 该组件必须完整对用户可见,不可被任何元素覆盖或遮挡(含透明元素),否则无法触发下载。
  2. 该组件必须完全在屏幕范围内,否则无法触发下载

事件

除了支持 通用事件 以外,还支持如下事件。

名称

参数

描述

click

{resultCode: number}

响应结果,number类型,数值含义如下:

  • 0:调用应用开始下载或重启下载方法成功的标识。
  • -1:由于参数错误导致调用应用开始下载或重启下载失败的标识,如:素材为非应用下载类广告。
  • -2:由于无下载权限导致调用应用开始下载或重启下载失败的标识。
  • -3:无网络。

示例代码

<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

  • 优化valuetype属性的描述。
  • 新增open-type属性。

1103

2022-12-26

  • 优化了一些描述和示例代码。
  • 新增install-text-value和open-text-value属性。
  • 新增opacity、border-radius、color、background-color、progressbar-color、progressbar-background-color、progressbar-text-color样式。

1101

2022-09-10

  • 优化了一些描述和示例代码。
  • 1101版本开始,不支持设置color样式。
  • 样式新增取值范围。
  • height样式的默认值修改为“60px”。
  • click事件的响应结果新增-3:无网络。

1100

2022-08-01

第一次正式发布。