文档管理中心

functionalButtonComponentManager(场景化融合Button组件管理)

本模块提供Button组件的逻辑管理,辅助HarmonyOS应用和元服务通过Button组件完成相应功能。

模型约束: 此接口仅可在Stage模型下使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 4.1.0(11)

导入模块

PhonePC/2in1TabletTV
收起
自动换行
深色代码主题
复制
  1. import { functionalButtonComponentManager } from '@kit.ScenarioFusionKit';

OpenType

PhonePC/2in1TabletTV

该枚举定义了FunctionalButton组件的功能类型,通过设置该参数来指定FunctionalButton的功能。

模型约束: 此接口仅可在Stage模型下使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 4.1.0(11)

展开
名称 说明
GET_PHONE_NUMBER 0

快速验证手机号。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

GET_REALTIME_PHONENUMBER 1

实时验证手机号。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

说明:

从版本5.0.0(12)开始,GET_REALTIME_PHONENUMBER暂不对外开放使用。

LAUNCH_APP 2

打开APP。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

OPEN_SETTING 3

打开授权设置页。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

说明:

从版本5.0.2(14)开始,OPEN_SETTING不再演进,建议使用PERMISSION_SETTING。

CHOOSE_AVATAR 4

选择头像。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

CHOOSE_ADDRESS 5

选择地址。

起始版本: 5.0.0(12)

元服务API: 从版本5.0.0(12)开始,该接口支持在元服务中使用。

CHOOSE_INVOICE_TITLE 6

选择发票抬头。

起始版本: 5.0.0(12)

元服务API: 从版本5.0.0(12)开始,该接口支持在元服务中使用。

REAL_NAME_AUTHENTICATION 7

实名信息校验。

起始版本: 5.0.0(12)

元服务API: 从版本5.0.0(12)开始,该接口支持在元服务中使用。

说明:

REAL_NAME_AUTHENTICATION暂不对外开放使用。

FACE_AUTHENTICATION 8

人脸核身。

起始版本: 5.0.0(12)

元服务API: 从版本5.0.0(12)开始,该接口支持在元服务中使用。

说明:

FACE_AUTHENTICATION暂不对外开放使用。

CHOOSE_LOCATION 9

地图选点。

起始版本: 5.0.0(12)

元服务API: 从版本5.0.0(12)开始,该接口支持在元服务中使用。

SUBSCRIBE_LIVE_VIEW 10

实况窗订阅。

起始版本: 5.0.0(12)

说明:

SUBSCRIBE_LIVE_VIEW暂不对外开放使用。

PERMISSION_SETTING 11

权限设置。

起始版本: 5.0.2(14)

元服务API: 从版本5.0.2(14)开始,该接口支持在元服务中使用。

REQUEST_SUBSCRIBE_MESSAGE 12

服务动态授权码按钮的类型。

起始版本: 6.0.0(20)

元服务API: 从版本6.0.0(20)开始,该接口支持在元服务中使用。

SHARE 13

分享按钮的类型。

起始版本: 6.0.0(20)

元服务API: 从版本6.0.0(20)开始,该接口支持在元服务中使用。

FEEDBACK 14

反馈按钮的类型。

起始版本: 6.0.0(20)

元服务API: 从版本6.0.0(20)开始,该接口支持在元服务中使用。

GET_PHONE_NUMBER_AND_RISK_LEVEL 15

获取手机号和风险等级。

起始版本: 6.0.2(22)

元服务API: 从版本6.0.2(22)开始,该接口支持在元服务中使用。

SizeType

PhonePC/2in1TabletTV

该枚举定义了FunctionalButton的尺寸类型。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 4.1.0(11)

展开
名称 说明
DEFAULT 0 默认大小。
MINI 1 小尺寸。

HoverClassType

PhonePC/2in1TabletTV

该枚举定义了FunctionalButton点击态的类型。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 4.1.0(11)

展开
名称 说明
NONE 0 无效果。
HOVER_CLASS 1 默认样式。

ColorType

PhonePC/2in1TabletTV

该枚举定义了FunctionalButton的颜色类型。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 4.1.0(11)

展开
名称 说明
DEFAULT 0 蓝色。
PRIMARY 1 绿色。
WARN 2 红色。

CredentialType(deprecated)

PhonePC/2in1TabletTV

该枚举定义了FunctionalButton的认证类型。

说明

从5.0.0(12)开始新增此接口,功能不可用,从6.0.2(22)开始废弃,无替代接口。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本5.0.0(12)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 5.0.0(12)

展开
名称 说明
IDCard 0 身份证件类型。

RealNameAuthenticationInfo(deprecated)

PhonePC/2in1TabletTV

该接口定义了FunctionalButton组件的实名信息校验对象。

说明

从5.0.0(12)开始支持,从6.0.2(22)开始废弃,无替代接口。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本5.0.0(12)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 5.0.0(12)

展开
名称 类型 只读 可选 说明
openID string OpenID是华为账号用户在不同类型的产品的身份ID,同一个用户,不同应用,OpenID值不同。
realName string 证件姓名。
credentialID Uint8Array 证件号码。
credentialType(deprecated) CredentialType 证件类型。

StyleOption

PhonePC/2in1TabletTV

该接口定义了FunctionalButton组件的样式信息。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 4.1.0(11)

展开
名称 类型 只读 可选 说明
size SizeType 按钮尺寸类型。默认值:functionalButtonComponentManager.SizeType.DEFAULT,字体大小为:16fp。
bgColor ColorType 按钮颜色类型。默认值:functionalButtonComponentManager.ColorType.DEFAULT,默认蓝底白字按钮样式。
plain boolean 按钮是否镂空。true表示镂空,false表示不镂空,默认值:false。
disabled boolean 按钮是否禁用。true表示按钮禁用,false表示不禁用Button,默认值:false。
loading boolean 名称前是否带loading图标。true表示名称前带loading图标,false表示关闭loading动画,默认值:false。
hoverClass HoverClassType 按钮按下去的样式。默认值:functionalButtonComponentManager.HoverClassType.HOVER_CLASS,开启点击效果。
hoverStartTime number

按住后多久出现点击态,单位:ms。

默认值:0

取值范围: [0, +∞)

说明:

设置为小于0的值时,按值为0处理。

hoverStayTime number

手指松开后点击态保留时间,单位:ms。

默认值:0

取值范围: [0, +∞)

说明:

设置为小于0的值时,按值为0处理。

styleConfig ButtonConfig

按钮样式配置。

说明:

当styleConfig和StyleOption中定义的样式冲突时,最终以styleConfig的为准。

FunctionalButtonParams

PhonePC/2in1TabletTV

该接口定义了FunctionalButton组件的参数,定义Button功能以及样式等。

模型约束: 此接口仅可在Stage模型下使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 4.1.0(11)

展开
名称 类型 只读 可选 说明
openType OpenType

按钮功能场景类型。默认值:functionalButtonComponentManager.OpenType.GET_PHONE_NUMBER。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

label ResourceStr

按钮展示文字。默认值:空字符串。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

styleOption StyleOption

按钮样式。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

说明:

- 在Button外设置的样式属性不生效,仅生效styleOption中设置的样式。

- 使用buttonModifier、textModifier、loadingProgressModifier设置按钮样式时,对应属性会被覆盖。

appParam AppParam

需打开APP的信息。例如:{bundleName: "xxx", abilityName: "xxx"}。

bundleName:包名。

abilityName:Ability名称。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

说明:

openType为“functionalButtonComponentManager.OpenType.LAUNCH_APP”时必填。

realNameAuthenticationInfo(deprecated) RealNameAuthenticationInfo

实名信息校验按钮信息。

起始版本: 5.0.0(12)

元服务API: 从版本5.0.0(12)开始,该接口支持在元服务中使用。

说明:

从5.0.0(12)开始支持,从6.0.2(22)开始废弃,无替代接口。

subscribeLiveViewParam SubscribeLiveViewParam

实况窗订阅按钮信息。

起始版本: 5.0.0(12)

permissionListParam Array<Permissions>

权限设置Button参数。

起始版本: 5.0.2(14)

元服务API: 从版本5.0.2(14)开始,该接口支持在元服务中使用。

说明:

需设置权限的权限名称列表,权限名称可参考应用权限列表

subSceneId string

子场景ID,在服务动态授权码场景时,该参数必填。参考服务动态场景模板,由开发者传入。

起始版本: 6.0.0(20)

元服务API: 从版本6.0.0(20)开始,该接口支持在元服务中使用。

shareParam ShareParam

需要分享的Button参数。

起始版本: 6.0.0(20)

元服务API: 从版本6.0.0(20)开始,该接口支持在元服务中使用。

buttonModifier ButtonModifier

设置Button的属性,如设置按钮的样式,颜色等。

起始版本: 5.1.0(18)

元服务API: 从版本5.1.0(18)开始,该接口支持在元服务中使用。

textModifier TextModifier

设置文本的属性,如设置文本颜色,字体大小,字重等。

起始版本: 5.1.0(18)

元服务API: 从版本5.1.0(18)开始,该接口支持在元服务中使用。

loadingProgressModifier LoadingProgressModifier

设置加载动效的属性,如设置加载动效的样式,颜色,定制内容区等。

起始版本: 5.1.0(18)

元服务API: 从版本5.1.0(18)开始,该接口支持在元服务中使用。

说明:

使用loadingProgressModifier时,需配合styleOption设置loading为true才能生效。

GetPhoneNumberResult

PhonePC/2in1TabletTV

该接口定义了使用快速验证功能成功验证的响应。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

设备行为差异: 该接口在Phone、Tablet、PC/2in1、TV、Car中可正常调用,在其他设备类型中返回801错误码。

起始版本: 4.1.0(11)

展开
名称 类型 只读 可选 说明
code string

账号用户的临时登录凭证(Authorization Code)。

说明:

可通过临时登录凭证获取真实手机号,临时登录凭证时效5分钟,具体操作可参考“服务端开发”章节。

GetRealtimePhoneNumberResult

PhonePC/2in1TabletTV

该接口定义了使用实时验证功能成功验证的响应。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

设备行为差异: 该接口在Phone、Tablet、PC/2in1、TV、Car中可正常调用,在其他设备类型中返回801错误码。

起始版本: 4.1.0(11)

展开
名称 类型 只读 可选 说明
code string

账号用户的临时登录凭证(Authorization Code)。

说明:

可通过临时登录凭证获取真实手机号,临时登录凭证时效5分钟,具体操作可参考“服务端开发”章节。

OpenSettingResult

PhonePC/2in1TabletTV

该接口定义了使用打开授权设置页功能,成功跳转授权设置页后返回应用或结束设置应用,应用权限设置情况的响应。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

设备行为差异: 该接口在Phone、Tablet、PC/2in1、TV、Car中可正常调用,在其他设备类型中返回801错误码。

起始版本: 4.1.0(11)

展开
名称 类型 只读 可选 说明
permissions Map<string, boolean>

权限字典表。

key为权限名称,value为权限是否开启,true表示开启权限,false表示关闭权限。

ChooseAvatarResult

PhonePC/2in1TabletTV

该接口定义了使用选择头像功能成功选择的响应。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

设备行为差异: 该接口在Phone、Tablet、PC/2in1中可正常调用,在其他设备类型中返回801错误码。

起始版本: 4.1.0(11)

展开
名称 类型 只读 可选 说明
avatarUri string

所选头像图片的地址。

说明:

返回的地址为裁剪之后的图片对应的地址。

AppParam

PhonePC/2in1TabletTV

该接口定义了FunctionalButton为打开APP功能时,通过该参数指定打开的应用对应的包名和Ability名称。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

设备行为差异: 该接口在Phone、Tablet、PC/2in1、TV、Car中可正常调用,在其他设备类型中返回801错误码。

起始版本: 4.1.0(11)

展开
名称 类型 只读 可选 说明
bundleName ResourceStr 包名。
abilityName ResourceStr Ability名称。默认值:EntryAbility。

ChooseAddressResult

PhonePC/2in1TabletTV

该接口定义了FunctionalButton为选择收货地址功能时,通过该参数指定选择收货地址对应的返回体。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本5.0.0(12)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

设备行为差异: 该接口在Phone、Tablet、PC/2in1、TV中可正常调用,在其他设备类型中返回801错误码。

起始版本: 5.0.0(12)

展开
名称 类型 只读 可选 说明
userName string 用户名称。
mobileNumber string 手机号码。
telNumber string 固定电话号码。
zipCode string 邮政编码。
countryCode string 国家/地区代码。
provinceName string 省份名称。
cityName string 城市名称。
districtName string 地区名称。
streetName string 街道名称。
detailedAddress string 详细地址。

ChooseInvoiceTitleResult

PhonePC/2in1TabletTV

该接口定义了FunctionalButton为选择发票抬头功能时,通过该参数指定选择发票抬头对应的返回体。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本5.0.0(12)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

设备行为差异: 该接口在Phone、Tablet、PC/2in1中可正常调用,在其他设备类型中返回801错误码。

起始版本: 5.0.0(12)

展开
名称 类型 只读 可选 说明
type string 发票类型,0-个人 1-企业。
title string 发票抬头。
taxNumber string 税号。
companyAddress string 公司地址。
telephone string 电话号码。
bankName string 银行名称。
bankAccount string 银行账户。

RealNameAuthenticationResult

PhonePC/2in1TabletTV

该接口定义了FunctionalButton为实名信息校验功能时,通过该参数指定实名信息校验对应的返回体。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本5.0.0(12)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

设备行为差异: 该接口在Phone、Tablet中可正常调用,在PC/2in1中返回1001500003错误码,在TV中返回801错误码。

起始版本: 5.0.0(12)

展开
名称 类型 只读 可选 说明
authCode string 临时凭据,有效时间5分钟,并且只能使用一次。
openID string OpenID是华为账号用户在不同类型的产品的身份ID,同一个用户,不同应用,OpenID值不同。

FaceAuthenticationResult

PhonePC/2in1TabletTV

该接口定义了FunctionalButton为人脸核身功能时,通过该参数指定人脸认证对应的返回体。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本5.0.0(12)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

设备行为差异: 该接口在Phone、Tablet中可正常调用,在PC/2in1中返回1001500003错误码,在TV中返回801错误码。

起始版本: 5.0.0(12)

展开
名称 类型 只读 可选 说明
authCode string 临时凭据,有效时间5分钟,并且只能使用一次。
openID string OpenID是华为账号用户在不同类型的产品的身份ID,同一个用户,不同应用,OpenID值不同。

FaceVerificationResult

PhonePC/2in1TabletTV

该接口定义了FunctionalButton为人脸核身功能时,通过该参数指定人脸核身对应的返回体。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本5.0.0(12)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

设备行为差异: 该接口在Phone、Tablet中可正常调用,在PC/2in1中返回1001500003错误码,在TV中返回801错误码。

起始版本: 5.0.0(12)

展开
名称 类型 只读 可选 说明
facialRecognitionVerificationToken string 验证成功后返回的token。
state string 响应体中返回的state,字符包含0-9、a-z、A-Z、英文点号、英文冒号、斜杆、下划线等,长度限制255,校验规则^[0-9a-zA-Z:/.-_]{1,255}$。与请求体中传入的state比较,校验是否是当前请求,防止跨站攻击。

ChooseLocationResult

PhonePC/2in1TabletTV

该接口定义了FunctionalButton为地图选点功能时,通过该参数指定地图选点对应的返回体。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本5.0.0(12)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

设备行为差异: 该接口在Phone、Tablet、PC/2in1中可正常调用,在其他设备类型中返回801错误码。

起始版本: 5.0.0(12)

展开
名称 类型 只读 可选 说明
name string 位置名称。
longitude number 经度,取值范围:[-180, 180]。
latitude number 纬度,取值范围:[-90, 90]。
address string 地址。

SubscribeLiveViewParam

PhonePC/2in1TabletTV

该接口定义了FunctionalButton组件为实况窗订阅功能时,通过该参数指定实况窗订阅对应的订阅事件和计时器。

模型约束: 此接口仅可在Stage模型下使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

设备行为差异: 该接口在Phone、Tablet中可正常调用,在其他设备类型中返回801错误码。

起始版本: 5.0.0(12)

展开
名称 类型 只读 可选 说明
event string

订阅事件。

固定值:SUBSCRIBE_TIMER。

alertTime number

计时器提醒时间,毫秒级时间戳。

说明:

1. 参数不能为空。

2. 0<=startTime-alertTime。

3. startTime和alertTime晚于当前时间。

4. startTime-alertTime <= 3600000(可在push侧配置)。

startTime number

计时器开始时间,毫秒级时间戳。

说明:

1. 参数不能为空。

2. 0<=startTime-alertTime。

3. startTime和alertTime晚于当前时间。

4. startTime-alertTime <= 3600000(可在push侧配置)。

SubscribeLiveViewResult

PhonePC/2in1TabletTV

该接口定义了FunctionalButton组件为实况窗订阅功能时,通过该参数指定实况窗订阅对应的返回体。

模型约束: 此接口仅可在Stage模型下使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

设备行为差异: 该接口在Phone、Tablet中可正常调用,在其他设备类型中返回801错误码。

起始版本: 5.0.0(12)

展开
名称 类型 只读 可选 说明
subscribeId string 订阅事件ID。

PermissionSettingResult

PhonePC/2in1TabletTV

该接口定义了FunctionalButton组件为权限设置功能时,通过该参数指定权限设置的返回体,用于UIAbility/UIExtensionAbility二次拉起权限设置弹框。

在调用此接口前,应用需要先调用requestPermissionsFromUser,如果用户在首次弹窗授权时已授权,调用当前接口将无法拉起弹窗。

说明

仅支持UIAbility/UIExtensionAbility。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本5.0.2(14)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

设备行为差异: 该接口在Phone、Tablet、PC/2in1、TV、Car中可正常调用,在其他设备类型中返回801错误码。

起始版本: 5.0.2(14)

展开
名称 类型 只读 可选 说明
permissionResult Array<abilityAccessCtrl.GrantStatus> 权限设置结果。

RequestSubscribeMessageResult

PhonePC/2in1TabletTV

该接口定义请求订阅消息的返回体。

说明

仅提供给元服务使用。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本6.0.0(20)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

设备行为差异: 该接口在Phone、Tablet、PC/2in1中可正常调用,在其他设备类型中返回801错误码。

起始版本: 6.0.0(20)

展开
名称 类型 只读 可选 说明
code string 服务动态授权码 。用于校验服务是否合法,服务动态等

ShareParam

PhonePC/2in1TabletTV

该接口定义分享的参数。

说明

仅提供给元服务使用。

模型约束: 此接口仅可在Stage模型下使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

设备行为差异: 该接口在Phone、Tablet、PC/2in1中可正常调用,在其他设备类型中返回801错误码。

起始版本: 6.0.0(20)

展开
名称 类型 只读 可选 说明
description string

元服务描述,支持开发者传入,默认是元服务描述。

元服务API: 从版本6.0.0(20)开始,该接口支持在元服务中使用。

previewUri string

元服务预览图,由开发者传入图片,否则返回默认元服务icon图标;本地文件路径、代码包文件路径或者网络图片路径。

元服务API: 从版本6.0.0(20)开始,该接口支持在元服务中使用。

uniformDataType uniformTypeDescriptor.UniformDataType

元服务数据类型,取值范围:[HYPERLINK, IMAGE, VIDEO, TEXT, FILE],默认值:HYPERLINK。

HYPERLINK:分享当前元服务。

IMAGE:图片分享。

VIDEO:视频分享。

TEXT:文本分享。

FILE:文件分享。

起始版本: 26.0.0

元服务API: 从API版本26.0.0开始,该接口支持在元服务中使用。

content string

元服务分享内容,链接(包含元服务App Linking)、文本类型的内容通过该字段传递。

HYPERLINK:自定义参数json字符串作为content字段,长度限制1~1024。

IMAGE:图片uri作为content字段。

VIDEO:视频uri作为content字段。

TEXT:文本内容作为content字段。

FILE:文件uri作为content字段。

起始版本: 26.0.0

元服务API: 从API版本26.0.0开始,该接口支持在元服务中使用。

title string

元服务分享的标题,如果是文本、链接等内容,建议填入title标识其标题。缺省时,若分享内容为文本类型,则文本内容作为title字段;若分享内容为文件类型,则文件名作为title字段。

起始版本: 26.0.0

元服务API: 从API版本26.0.0开始,该接口支持在元服务中使用。

GetPhoneNumberAndRiskLevelResult

PhonePC/2in1TabletTV

该接口定义获取手机号和风险等级的返回体。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本6.0.2(22)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 6.0.2(22)

展开
名称 类型 只读 可选 说明
code string 手机号和风险等级授权码。成功获取授权码时返回。
errCode number 错误码。获取授权码失败时返回。
errMsg string 错误信息。获取授权码失败时返回。

事件

PhonePC/2in1TabletTV

不支持通用事件,仅支持以下事件:

FunctionalButtonController

PhonePC/2in1TabletTV

FunctionalButton组件控制器,用来回调组件内部的点击事件。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 4.1.0(11)

onGetPhoneNumber

PhonePC/2in1TabletTV

onGetPhoneNumber(callback: AsyncCallback<GetPhoneNumberResult>): FunctionalButtonController

注册FunctionalButton组件为快速验证手机号的点击事件,使用callback异步回调。

该接口功能依赖Account Kit,参见createAuthorizationWithHuaweiIDRequest

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

设备行为差异: 该接口在Phone、Tablet、PC/2in1、TV、Car中可正常调用,在其他设备类型中返回801错误码。

起始版本: 4.1.0(11)

参数:

展开
参数名 类型 必填 说明
callback AsyncCallback<GetPhoneNumberResult>

回调函数。当获取电话号码成功,err为undefined,data为获取到的账号用户的临时登录凭证(Authorization Code);否则为错误对象。

说明:

可通过临时登录凭证获取真实手机号,临时登录凭证时效5分钟,具体操作可参考“服务端开发”章节。

返回值:

展开
类型 说明
FunctionalButtonController FunctionalButton组件控制器。

示例:

收起
自动换行
深色代码主题
复制
  1. import { FunctionalButton, functionalButtonComponentManager } from '@kit.ScenarioFusionKit';
  2. import { hilog } from '@kit.PerformanceAnalysisKit';
  3. @Entry
  4. @Component
  5. struct Index {
  6. build() {
  7. Row() {
  8. Column() {
  9. // 构建FunctionalButton组件实例。
  10. FunctionalButton({
  11. params: {
  12. // OpenType.GET_PHONE_NUMBER表示该按钮用于快速验证手机号码。
  13. openType: functionalButtonComponentManager.OpenType.GET_PHONE_NUMBER,
  14. label: '快速验证手机号',
  15. // 调整按钮样式。
  16. styleOption: {
  17. styleConfig: new functionalButtonComponentManager.ButtonConfig()
  18. .fontSize(20)
  19. },
  20. },
  21. // 当OpenType为GET_PHONE_NUMBER时,回调必须为onGetPhoneNumber。
  22. controller: new functionalButtonComponentManager.FunctionalButtonController()
  23. .onGetPhoneNumber((err, data) => {
  24. if (err) {
  25. // 错误日志处理。
  26. hilog.error(0x0000, 'testTag', 'Failed to authenticate, error: %{public}d %{public}s', err.code, err.message);
  27. return;
  28. }
  29. // 成功日志处理。
  30. hilog.info(0x0000, 'testTag', 'succeeded in authenticating');
  31. // 获取授权码。
  32. let authorizationCode = data.code;
  33. })
  34. })
  35. }.width('100%')
  36. }.height('100%')
  37. }
  38. }

onGetRealtimePhoneNumber

PhonePC/2in1TabletTV

onGetRealtimePhoneNumber(callback: AsyncCallback<GetRealtimePhoneNumberResult>): FunctionalButtonController

注册FunctionalButton组件为实时验证手机号的点击事件,使用callback异步回调。

该接口功能依赖Account Kit,参见createAuthorizationWithHuaweiIDRequest

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

设备行为差异: 该接口在Phone、Tablet、PC/2in1、TV、Car中可正常调用,在其他设备类型中返回801错误码。

起始版本: 4.1.0(11)

参数:

展开
参数名 类型 必填 说明
callback AsyncCallback<GetRealtimePhoneNumberResult>

回调函数。当获取实时电话号码成功,err为undefined,data为获取到的账号用户的临时登录凭证(Authorization Code);否则为错误对象。

说明:

可通过临时登录凭证获取真实手机号,临时登录凭证时效5分钟,具体操作可参考“服务端开发”章节。

返回值:

展开
类型 说明
FunctionalButtonController FunctionalButton组件控制器。

示例:

收起
自动换行
深色代码主题
复制
  1. import {FunctionalButton, functionalButtonComponentManager} from '@kit.ScenarioFusionKit';
  2. import { hilog } from '@kit.PerformanceAnalysisKit';
  3. @Entry
  4. @Component
  5. struct Index {
  6. build() {
  7. Row() {
  8. Column() {
  9. // 构建FunctionalButton组件实例。
  10. FunctionalButton({
  11. params: {
  12. // OpenType.GET_REALTIME_PHONENUMBER表示该按钮用于实时验证手机号码。
  13. openType: functionalButtonComponentManager.OpenType.GET_REALTIME_PHONENUMBER,
  14. label: '实时验证手机号',
  15. // 调整按钮样式。
  16. styleOption: {
  17. styleConfig: new functionalButtonComponentManager.ButtonConfig()
  18. .fontSize(20)
  19. },
  20. },
  21. // 当OpenType为GET_REALTIME_PHONENUMBER时,回调必须为onGetRealtimePhoneNumber。
  22. controller: new functionalButtonComponentManager.FunctionalButtonController()
  23. .onGetRealtimePhoneNumber((err, data) => {
  24. if (err) {
  25. // 错误日志处理。
  26. hilog.error(0x0000, 'testTag', 'Failed to authenticate, error: %{public}d %{public}s', err.code, err.message);
  27. return;
  28. }
  29. // 成功日志处理。
  30. hilog.info(0x0000, 'testTag', 'succeeded in authenticating');
  31. // 获取授权码。
  32. let authorizationCode = data.code;
  33. })
  34. })
  35. }
  36. .width('100%')
  37. }
  38. .height('100%')
  39. }
  40. }

onLaunchApp

PhonePC/2in1TabletTV

onLaunchApp(callback: AsyncCallback<void>): FunctionalButtonController

注册FunctionalButton组件为打开APP的点击事件,使用callback异步回调。

该接口功能依赖Ability Kit,参见startAbility

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

设备行为差异: 该接口在Phone、Tablet、PC/2in1、TV、Car中可正常调用,在其他设备类型中返回801错误码。

起始版本: 4.1.0(11)

参数:

展开
参数名 类型 必填 说明
callback AsyncCallback<void> 回调函数。当打开APP完成,err为undefined,否则返回错误对象。

返回值:

展开
类型 说明
FunctionalButtonController FunctionalButton组件控制器。

示例:

收起
自动换行
深色代码主题
复制
  1. import { FunctionalButton, functionalButtonComponentManager } from '@kit.ScenarioFusionKit';
  2. import { hilog } from '@kit.PerformanceAnalysisKit';
  3. @Entry
  4. @Component
  5. struct Index {
  6. build() {
  7. Row() {
  8. Column() {
  9. // 构建FunctionalButton组件实例。
  10. FunctionalButton({
  11. params: {
  12. // OpenType.LAUNCH_APP表示该按钮用于启动应用。
  13. openType: functionalButtonComponentManager.OpenType.LAUNCH_APP,
  14. label: '打开APP',
  15. // 当OpenType为functionButtonComponentManager.OpenType.LAUNCH_APP时,appParam为必填项。
  16. appParam: {
  17. bundleName: "xxx",
  18. abilityName: "xxx"
  19. },
  20. // 调整按钮样式。
  21. styleOption: {
  22. styleConfig: new functionalButtonComponentManager.ButtonConfig()
  23. .fontSize(20)
  24. },
  25. },
  26. // 当OpenType设置为LAUNCH_APP时,回调函数必须是onLaunchApp。
  27. controller: new functionalButtonComponentManager.FunctionalButtonController().onLaunchApp((err) => {
  28. if (err) {
  29. // 错误日志处理。
  30. hilog.error(0x0000, 'testTag', 'Failed to launch app, error: %{public}d %{public}s', err.code, err.message);
  31. return;
  32. }
  33. // 处理成功。成功时不会返回任何值。
  34. hilog.info(0x0000, 'testTag', 'succeeded in launching app');
  35. })
  36. })
  37. }.width('100%')
  38. }.height('100%')
  39. }
  40. }
说明

“bundleName”为包名,“abilityName”为Ability名称。

onOpenSetting

PhonePC/2in1TabletTV

onOpenSetting(callback: AsyncCallback<OpenSettingResult>): FunctionalButtonController

注册FunctionalButton组件为打开授权设置页的点击事件,使用callback异步回调。

该接口功能依赖Ability Kit,参见startAbilityForResult

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

设备行为差异: 该接口在Phone、Tablet、PC/2in1、TV、Car中可正常调用,在其他设备类型中返回801错误码。

起始版本: 4.1.0(11)

参数:

展开
参数名 类型 必填 说明
callback AsyncCallback<OpenSettingResult> 回调函数。当打开授权设置页成功,err为undefined,data为打开设置成功时返回的响应;否则为错误对象。

返回值:

展开
类型 说明
FunctionalButtonController FunctionalButton组件控制器。

示例:

收起
自动换行
深色代码主题
复制
  1. import { FunctionalButton, functionalButtonComponentManager } from '@kit.ScenarioFusionKit';
  2. import { hilog } from '@kit.PerformanceAnalysisKit';
  3. @Entry
  4. @Component
  5. struct Index {
  6. build() {
  7. Row() {
  8. Column() {
  9. // 构建FunctionalButton组件实例。
  10. FunctionalButton({
  11. params: {
  12. // OpenType.OPEN_SETTING表示该按钮用于打开授权设置页面。
  13. openType: functionalButtonComponentManager.OpenType.OPEN_SETTING,
  14. label: '打开授权设置页',
  15. // 调整按钮样式。
  16. styleOption: {
  17. styleConfig: new functionalButtonComponentManager.ButtonConfig()
  18. .fontSize(20)
  19. },
  20. },
  21. // 当OpenType为OPEN_SETTING时,回调必须为onOpenSetting。
  22. controller: new functionalButtonComponentManager.FunctionalButtonController().onOpenSetting((err, data) => {
  23. if (err) {
  24. // 错误日志处理。
  25. hilog.error(0x0000, 'testTag', 'Failed to open setting, error: %{public}d %{public}s', err.code, err.message);
  26. return;
  27. }
  28. // 成功处理,当应用程序进程停止时触发。
  29. hilog.info(0x0000, 'testTag', 'succeeded in opening setting');
  30. data.permissions!.forEach((value, key) => {
  31. hilog.info(0x0000, 'testTag', 'key: %{public}s value: %{public}s', String(key), value);
  32. })
  33. })
  34. })
  35. }.width('100%')
  36. }.height('100%')
  37. }
  38. }

onChooseAvatar

PhonePC/2in1TabletTV

onChooseAvatar(callback: AsyncCallback<ChooseAvatarResult>): FunctionalButtonController

注册FunctionalButton组件为选择头像的点击事件,使用callback异步回调。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

设备行为差异: 该接口在Phone、Tablet、PC/2in1中可正常调用,在其他设备类型中返回801错误码。

起始版本: 4.1.0(11)

参数:

展开
参数名 类型 必填 说明
callback AsyncCallback<ChooseAvatarResult>

回调函数。当选择头像调用成功,err为undefined,data为选择头像成功时返回的所选头像图片的地址;否则为错误对象。

说明:

返回的地址为裁剪之后的图片对应的地址。

返回值:

展开
类型 说明
FunctionalButtonController FunctionalButton组件控制器。

示例:

收起
自动换行
深色代码主题
复制
  1. import { FunctionalButton, functionalButtonComponentManager } from '@kit.ScenarioFusionKit';
  2. import { hilog } from '@kit.PerformanceAnalysisKit';
  3. @Entry
  4. @Component
  5. struct Index {
  6. // 将account.png文件添加到/resources/base/media/目录中。否则,将显示错误信息,提示找不到该文件。
  7. @State url: ResourceStr = $r('app.media.account');
  8. build() {
  9. Column() {
  10. // 构建FunctionalButton组件实例。
  11. FunctionalButton({
  12. params: {
  13. // OpenType.CHOOSE_AVATAR表示该按钮用于选择头像。
  14. openType: functionalButtonComponentManager.OpenType.CHOOSE_AVATAR,
  15. label: '',
  16. // 调整按钮样式。
  17. styleOption: {
  18. styleConfig: new functionalButtonComponentManager.ButtonConfig()
  19. .type(ButtonType.Normal)
  20. .backgroundImage(this.url)
  21. .backgroundImageSize(ImageSize.Cover)
  22. .width(80)
  23. .height(80)
  24. .backgroundColor('#E5E5E5')
  25. },
  26. },
  27. // 当OpenType设置为CHOOSE_AVATAR时,回调函数必须是onChooseAvatar。
  28. controller: new functionalButtonComponentManager.FunctionalButtonController().onChooseAvatar((err, data) => {
  29. if (err) {
  30. // 错误日志处理。
  31. hilog.error(0x0000, 'testTag', 'Failed to choose avatar, error: %{public}d %{public}s', err.code, err.message);
  32. return;
  33. }
  34. // 成功日志处理。
  35. hilog.info(0x0000, 'testTag', 'succeeded in choosing avatar');
  36. this.url = data.avatarUri!;
  37. })
  38. })
  39. }
  40. .padding({ top: 200 })
  41. .height('100%')
  42. .width('100%')
  43. }
  44. }

onChooseAddress

PhonePC/2in1TabletTV

onChooseAddress(callback: AsyncCallback<ChooseAddressResult>): FunctionalButtonController

注册FunctionalButton组件为选择收货地址的点击事件,使用callback异步回调。

该接口功能依赖Account Kit,参见chooseAddress

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本5.0.0(12)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

设备行为差异: 该接口在Phone、Tablet、PC/2in1、TV中可正常调用,在其他设备类型中返回801错误码。

起始版本: 5.0.0(12)

参数:

展开
参数名 类型 必填 说明
callback AsyncCallback<ChooseAddressResult> 回调函数。当选择收货地址点击成功,err为undefined,data为选择收货地址的返回结果;否则为错误对象。

返回值:

展开
类型 说明
FunctionalButtonController FunctionalButton组件控制器。

示例:

收起
自动换行
深色代码主题
复制
  1. import { FunctionalButton, functionalButtonComponentManager } from '@kit.ScenarioFusionKit';
  2. import { hilog } from '@kit.PerformanceAnalysisKit';
  3. @Entry
  4. @Component
  5. struct Index {
  6. build() {
  7. Row() {
  8. Column() {
  9. // 构建FunctionalButton组件实例。
  10. FunctionalButton({
  11. params: {
  12. // OpenType.CHOOSE_ADDRESS表示该按钮用于选择收货地址。
  13. openType: functionalButtonComponentManager.OpenType.CHOOSE_ADDRESS,
  14. label: '选择收货地址',
  15. // 调整按钮样式。
  16. styleOption: {
  17. bgColor:functionalButtonComponentManager.ColorType.DEFAULT,
  18. size: functionalButtonComponentManager.SizeType.DEFAULT,
  19. plain: false,
  20. disabled:false,
  21. loading: false,
  22. hoverClass: functionalButtonComponentManager.HoverClassType.HOVER_CLASS,
  23. hoverStartTime: 0,
  24. hoverStayTime: 0,
  25. styleConfig: new functionalButtonComponentManager.ButtonConfig()
  26. .fontSize(20)
  27. },
  28. },
  29. // 当OpenType设置为CHOOSE_ADDRESS时,回调必须为onChooseAddress。
  30. controller: new functionalButtonComponentManager.FunctionalButtonController()
  31. .onChooseAddress((err, data) => {
  32. if (err) {
  33. // 错误日志处理。
  34. hilog.error(0x0000, 'testTag', 'Failed to choose address, error: %{public}d %{public}s', err.code, err.message);
  35. return;
  36. }
  37. // 成功日志处理。
  38. hilog.info(0x0000, 'testTag', 'succeeded in choosing address');
  39. // 获取地址信息。
  40. let userName: string = data.userName;
  41. let mobileNumber: string = data.mobileNumber as string;
  42. let countryCode: string = data.countryCode as string;
  43. let provinceName: string = data.provinceName as string;
  44. let cityName: string = data.cityName as string;
  45. let districtName: string = data.districtName as string;
  46. let streetName: string = data.streetName as string;
  47. let detailedAddress: string = data.detailedAddress;
  48. })
  49. })
  50. }.width('100%')
  51. }.height('100%')
  52. }
  53. }

onChooseInvoiceTitle

PhonePC/2in1TabletTV

onChooseInvoiceTitle(callback: AsyncCallback<ChooseInvoiceTitleResult>): FunctionalButtonController

注册FunctionalButton组件为选择发票抬头的点击事件,使用callback异步回调。

该接口功能依赖Account Kit,参见selectInvoiceTitle

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本5.0.0(12)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

设备行为差异: 该接口在Phone、Tablet、PC/2in1中可正常调用,在其他设备类型中返回801错误码。

起始版本: 5.0.0(12)

参数:

展开
参数名 类型 必填 说明
callback AsyncCallback<ChooseInvoiceTitleResult> 回调函数。当选择发票抬头点击成功,err为undefined,data为选择发票抬头的返回结果;否则为错误对象。

返回值:

展开
类型 说明
FunctionalButtonController FunctionalButton组件控制器。

示例:

收起
自动换行
深色代码主题
复制
  1. import { FunctionalButton, functionalButtonComponentManager } from '@kit.ScenarioFusionKit';
  2. import { hilog } from '@kit.PerformanceAnalysisKit';
  3. @Entry
  4. @Component
  5. struct Index {
  6. build() {
  7. Row() {
  8. Column() {
  9. // 构建FunctionalButton组件实例。
  10. FunctionalButton({
  11. params: {
  12. // OpenType.CHOOSE_INVOICE_TITLE表示该按钮用于选择发票抬头。
  13. openType: functionalButtonComponentManager.OpenType.CHOOSE_INVOICE_TITLE,
  14. label: '选择发票抬头',
  15. // 调整按钮样式。
  16. styleOption: {
  17. bgColor:functionalButtonComponentManager.ColorType.DEFAULT,
  18. size: functionalButtonComponentManager.SizeType.DEFAULT,
  19. plain: false,
  20. disabled:false,
  21. loading: false,
  22. hoverClass: functionalButtonComponentManager.HoverClassType.HOVER_CLASS,
  23. hoverStartTime: 0,
  24. hoverStayTime: 0,
  25. styleConfig: new functionalButtonComponentManager.ButtonConfig()
  26. .fontSize(20)
  27. },
  28. },
  29. // 当OpenType为CHOOSE_INVOICE_TITLE时,回调必须为onChooseInvoiceTitle。
  30. controller: new functionalButtonComponentManager.FunctionalButtonController()
  31. .onChooseInvoiceTitle((err, data) => {
  32. if (err) {
  33. // 错误日志处理。
  34. hilog.error(0x0000, 'testTag', 'Failed to obtain invoice title, error: %{public}d %{public}s', err.code, err.message);
  35. return;
  36. }
  37. // 成功日志处理。
  38. hilog.info(0x0000, 'testTag', 'succeeded in obtaining invoice title');
  39. // 获取发票信息。
  40. let type: string = data.type;
  41. let title: string = data.title;
  42. let taxNumber: string = data.taxNumber;
  43. let companyAddress: string | undefined = data.companyAddress;
  44. let telephone: string | undefined = data.telephone;
  45. let bankName: string | undefined = data.bankName;
  46. let bankAccount: string | undefined = data.bankAccount;
  47. })
  48. })
  49. }.width('100%')
  50. }.height('100%')
  51. }
  52. }

onRealNameAuthentication

PhonePC/2in1TabletTV

onRealNameAuthentication(callback: AsyncCallback<RealNameAuthenticationResult>): FunctionalButtonController

注册FunctionalButton组件为实名信息校验的点击事件,使用callback异步回调。

该接口功能依赖Account Kit,参见createAuthorizationWithHuaweiIDRequestAuthenticationControllerexecuteRequest

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本5.0.0(12)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

设备行为差异: 该接口在Phone、Tablet中可正常调用,在PC/2in1中返回1001500003错误码,在TV中返回801错误码。

起始版本: 5.0.0(12)

参数:

展开
参数名 类型 必填 说明
callback AsyncCallback<RealNameAuthenticationResult> 回调函数。当实名信息校验成功,err为undefined,data为获取到的实名信息校验鉴权对应的返回体:authCode、openID;否则为错误对象。

返回值:

展开
类型 说明
FunctionalButtonController FunctionalButton组件控制器。

示例:

收起
自动换行
深色代码主题
复制
  1. import { FunctionalButton, functionalButtonComponentManager } from '@kit.ScenarioFusionKit';
  2. import { hilog } from '@kit.PerformanceAnalysisKit';
  3. import { http } from '@kit.NetworkKit';
  4. import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
  5. interface Result {
  6. state?: number;
  7. realNameLevel?: number;
  8. verifyResult?: number;
  9. verifyToken?: string;
  10. }
  11. @Entry
  12. @Component
  13. struct SecondPage {
  14. obtainRealNameDataInfo(authCode: string, sceneID:number, openID: string, realName: string, idNo: string,
  15. callback: AsyncCallback<Result>) {
  16. // 每个httpRequest对应一个HTTP请求任务,且不可重复使用。
  17. let httpRequest = http.createHttp();
  18. // 监听HTTP响应头事件,该事件比HTTP请求的响应返回得更早。是否监听HTTP响应头事件由您决定。
  19. httpRequest.on('headersReceive', (header) => {
  20. hilog.info(0x0000, "testTag", "header: %{public}s", header as string);
  21. });
  22. httpRequest.request(
  23. // 请自行在extraData中自定义EXAMPLE_URL。是否向URL添加参数由您决定。
  24. "EXAMPLE_URL",
  25. {
  26. method: http.RequestMethod.POST,
  27. // 您可以根据服务需求添加头部字段。
  28. header: {
  29. 'Content-Type': 'application/json'
  30. },
  31. // 使用此字段在POST请求中传递信息。
  32. extraData: {
  33. "authCode": authCode,
  34. "sceneID": sceneID,
  35. "openID": openID,
  36. "realname": realName,
  37. "idNo": idNo,
  38. },
  39. expectDataType: http.HttpDataType.STRING,
  40. usingCache: true,
  41. priority: 1,
  42. connectTimeout: 60000,
  43. readTimeout: 60000,
  44. usingProtocol: http.HttpProtocol.HTTP1_1,
  45. }, (err, data) => {
  46. if (!err) {
  47. let res: Result = JSON.parse(data.result as string);
  48. callback(undefined, res);
  49. } else {
  50. let error: BusinessError = {code: err.code, message: err.message, name: ''};
  51. callback(error, undefined);
  52. // 取消订阅HTTP响应头事件。
  53. httpRequest.off('headersReceive');
  54. // 在httpRequest完成后调用destroy()方法以释放资源。
  55. httpRequest.destroy();
  56. }
  57. })
  58. }
  59. build() {
  60. Row() {
  61. Column() {
  62. FunctionalButton({
  63. params: {
  64. // OpenType.REAL_NAME_AUTHENTICATION表示该按钮用于实名信息校验。
  65. openType: functionalButtonComponentManager.OpenType.REAL_NAME_AUTHENTICATION,
  66. label: '实名信息校验',
  67. // 调整按钮样式。
  68. styleOption: {
  69. styleConfig: new functionalButtonComponentManager.ButtonConfig()
  70. .fontSize(20)
  71. },
  72. },
  73. // 当OpenType设置为REAL_NAME_AUTHENTICATION时,回调必须为onRealNameAuthentication。
  74. controller: new functionalButtonComponentManager.FunctionalButtonController()
  75. .onRealNameAuthentication((err, data) => {
  76. if (err) {
  77. // 错误日志处理。
  78. hilog.error(0x0000, 'testTag', 'Failed to authenticate, error: %{public}d %{public}s', err.code, err.message);
  79. return;
  80. }
  81. // 成功日志处理。
  82. hilog.info(0x0000, 'testTag', 'succeeded in authenticating');
  83. // 获取授权码。
  84. let authCode: string = data.authCode as string;
  85. let openID: string = data.openID as string;
  86. // sceneid 表示场景ID。选项包括:0(实名验证)、1(人脸验证,验证姓名、证件类型、证件号码和人脸)和2(人脸验证,仅验证人脸)。
  87. this.obtainRealNameDataInfo(authCode, 0, openID, 'name', 'idNo', (err, data) => {
  88. if (err) {
  89. hilog.error(0x0000, 'testTag', 'Failed to verify, error: %{public}d %{public}s', err.code, err.message);
  90. return;
  91. }
  92. let state = data.state;
  93. let realNameLevel = data.realNameLevel;
  94. let verifyResult = data.verifyResult;
  95. let verifyToken = data.verifyToken;
  96. hilog.info(0x0000, 'testTag', 'succeeded in verifying');
  97. })
  98. })
  99. })
  100. }
  101. .width('100%')
  102. }
  103. .height('100%')
  104. }
  105. }

onFaceAuthentication

PhonePC/2in1TabletTV

onFaceAuthentication(callback: AsyncCallback<FaceAuthenticationResult>): FunctionalButtonController

注册FunctionalButton组件为人脸核身的点击事件,使用callback异步回调。

该接口功能依赖Account Kit,参见createAuthorizationWithHuaweiIDRequestAuthenticationControllerexecuteRequest

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本5.0.0(12)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

设备行为差异: 该接口在Phone、Tablet中可正常调用,在PC/2in1中返回1001500003错误码,在TV中返回801错误码。

起始版本: 5.0.0(12)

参数:

展开
参数名 类型 必填 说明
callback AsyncCallback<FaceAuthenticationResult> 回调函数。当人脸认证成功,err为undefined,data为获取到的人脸认证对应的返回体:authCode、openID;否则为错误对象。

返回值:

展开
类型 说明
FunctionalButtonController FunctionalButton组件控制器。

示例:

收起
自动换行
深色代码主题
复制
  1. import { FunctionalButton, functionalButtonComponentManager } from '@kit.ScenarioFusionKit';
  2. import { hilog } from '@kit.PerformanceAnalysisKit';
  3. import { http } from '@kit.NetworkKit';
  4. import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
  5. interface Result {
  6. state?: number;
  7. realNameLevel?: number;
  8. verifyResult?: number;
  9. verifyToken?: string;
  10. }
  11. @Entry
  12. @Component
  13. struct SecondPage {
  14. obtainFaceVerifyDataInfo(authCode: string, sceneID: number, openID: string, realName: string, idNo: string,
  15. callback: AsyncCallback<Result>) {
  16. // 每个httpRequest对应一个HTTP请求任务,且不可重复使用。
  17. let httpRequest = http.createHttp();
  18. // 监听HTTP响应头事件,该事件比HTTP请求的响应返回得更早。是否监听HTTP响应头事件由您决定。
  19. httpRequest.on('headersReceive', (header) => {
  20. hilog.info(0x0000, "testTag", "header: %{public}s", header as string);
  21. });
  22. httpRequest.request(
  23. // 请自行在extraData中自定义EXAMPLE_URL。是否向URL添加参数由您决定。
  24. "EXAMPLE_URL",
  25. {
  26. method: http.RequestMethod.POST,
  27. // 您可以根据服务需求添加头部字段。
  28. header: {
  29. 'Content-Type': 'application/json'
  30. },
  31. // 使用此字段在POST请求中传递信息。
  32. extraData: {
  33. "authCode": authCode,
  34. "sceneID": sceneID,
  35. "openID": openID,
  36. "realname": realName,
  37. "idNo": idNo,
  38. },
  39. expectDataType: http.HttpDataType.STRING,
  40. usingCache: true,
  41. priority: 1,
  42. connectTimeout: 60000,
  43. readTimeout: 60000,
  44. usingProtocol: http.HttpProtocol.HTTP1_1,
  45. }, (err, data) => {
  46. if (!err) {
  47. let res: Result = JSON.parse(data.result as string);
  48. callback(undefined, res);
  49. } else {
  50. let error: BusinessError = { code: err.code, message: err.message, name: '' };
  51. callback(error, undefined);
  52. // 取消订阅HTTP响应头事件。
  53. httpRequest.off('headersReceive');
  54. // 在httpRequest完成后调用destroy()方法以释放资源。
  55. httpRequest.destroy();
  56. }
  57. })
  58. }
  59. build() {
  60. Row() {
  61. Column() {
  62. FunctionalButton({
  63. params: {
  64. // OpenType.FACE_AUTHENTICATION表示该按钮用于人脸身份验证。
  65. openType: functionalButtonComponentManager.OpenType.FACE_AUTHENTICATION,
  66. label: '人脸核身',
  67. // 调整按钮样式。
  68. styleOption: {
  69. styleConfig: new functionalButtonComponentManager.ButtonConfig()
  70. .fontSize(20)
  71. },
  72. },
  73. // 当OpenType为FACE_AUTHENTICATION时,回调必须为onFaceAuthentication。
  74. controller: new functionalButtonComponentManager.FunctionalButtonController()
  75. .onFaceAuthentication((err, data) => {
  76. if (err) {
  77. // 错误日志处理。
  78. hilog.error(0x0000, 'testTag', 'Failed to authenticate, error: %{public}d %{public}s', err.code, err.message);
  79. return;
  80. }
  81. // 成功日志处理。
  82. hilog.info(0x0000, 'testTag', 'succeeded in authenticating');
  83. // 获取授权码。
  84. let authCode: string = data.authCode as string;
  85. let openID: string = data.openID as string;
  86. hilog.info(0x0000, 'testTag', 'succeeded in authCode');
  87. // sceneid 表示场景ID。选项包括:0(实名验证)、1(人脸验证,验证姓名、证件类型、证件号码和人脸)和2(人脸验证,仅验证人脸)。
  88. this.obtainFaceVerifyDataInfo(authCode, 2, openID, "", "", (err, data) => {
  89. if (err) {
  90. hilog.error(0x0000, 'testTag', 'error: %{public}d %{public}s', err.code, err.message);
  91. return;
  92. }
  93. let verifyToken: string = data.verifyToken as string;
  94. new functionalButtonComponentManager.FunctionalButtonController().onFaceVerification(verifyToken,
  95. (error, data) => {
  96. if (error) {
  97. // 错误日志处理。
  98. hilog.error(0x0000, 'testTag', 'Failed to authenticate, error: %{public}d %{public}s', error.code, error.message);
  99. return;
  100. }
  101. let facialRecognitionVerificationToken = data.facialRecognitionVerificationToken;
  102. let state = data.state;
  103. hilog.info(0x0000, 'testTag', 'auth result success');
  104. });
  105. })
  106. })
  107. })
  108. }
  109. .width('100%')
  110. }
  111. .height('100%')
  112. }
  113. }

onFaceVerification

PhonePC/2in1TabletTV

onFaceVerification(verifyToken: string, callback: AsyncCallback<FaceVerificationResult>): void

注册FunctionalButton组件为人脸验证的点击事件,使用callback异步回调。

该接口功能依赖Account Kit,参见createAuthorizationWithHuaweiIDRequestAuthenticationControllerexecuteRequest

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本5.0.0(12)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

设备行为差异: 该接口在Phone、Tablet中可正常调用,在PC/2in1中返回1001500003错误码,在TV中返回801错误码。

起始版本: 5.0.0(12)

参数:

展开
参数名 类型 必填 说明
verifyToken string 验证成功的idToken,三方应用拉起华为账号客户端人脸验证页面时传入此Token,供华为账号客户端校验验证结果,参见FacialRecognitionVerificationRequest
callback AsyncCallback<FaceVerificationResult> 回调函数。当人脸验证点击成功,err为undefined,data为人脸验证的返回结果;否则为错误对象。

示例:

收起
自动换行
深色代码主题
复制
  1. import { FunctionalButton, functionalButtonComponentManager } from '@kit.ScenarioFusionKit';
  2. import { hilog } from '@kit.PerformanceAnalysisKit';
  3. import { http } from '@kit.NetworkKit';
  4. import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit';
  5. interface Result {
  6. state?: number;
  7. realNameLevel?: number;
  8. verifyResult?: number;
  9. verifyToken?: string;
  10. }
  11. @Entry
  12. @Component
  13. struct SecondPage {
  14. obtainFaceVerifyDataInfo(authCode: string, sceneID: number, openID: string, realName: string, idNo: string,
  15. callback: AsyncCallback<Result>) {
  16. // 每个httpRequest对应一个HTTP请求任务,且不可重复使用。
  17. let httpRequest = http.createHttp();
  18. // 监听HTTP响应头事件,该事件比HTTP请求的响应返回得更早。是否监听HTTP响应头事件由您决定。
  19. httpRequest.on('headersReceive', (header) => {
  20. hilog.info(0x0000, "testTag", "header: %{public}s", header as string);
  21. });
  22. httpRequest.request(
  23. // 请自行在extraData中自定义EXAMPLE_URL。是否向URL添加参数由您决定。
  24. "EXAMPLE_URL",
  25. {
  26. method: http.RequestMethod.POST,
  27. // 您可以根据服务需求添加头部字段。
  28. header: {
  29. 'Content-Type': 'application/json'
  30. },
  31. // 使用此字段在POST请求中传递信息。
  32. extraData: {
  33. "authCode": authCode,
  34. "sceneID": sceneID,
  35. "openID": openID,
  36. "realname": realName,
  37. "idNo": idNo,
  38. },
  39. expectDataType: http.HttpDataType.STRING,
  40. usingCache: true,
  41. priority: 1,
  42. connectTimeout: 60000,
  43. readTimeout: 60000,
  44. usingProtocol: http.HttpProtocol.HTTP1_1,
  45. }, (err, data) => {
  46. if (!err) {
  47. let res: Result = JSON.parse(data.result as string);
  48. callback(undefined, res);
  49. } else {
  50. let error: BusinessError = { code: err.code, message: err.message, name: '' };
  51. callback(error, undefined);
  52. // 取消订阅HTTP响应头事件。
  53. httpRequest.off('headersReceive');
  54. // 在httpRequest完成后调用destroy()方法以释放资源。
  55. httpRequest.destroy();
  56. }
  57. })
  58. }
  59. build() {
  60. Row() {
  61. Column() {
  62. FunctionalButton({
  63. params: {
  64. // OpenType.FACE_AUTHENTICATION表示该按钮用于人脸身份验证。
  65. openType: functionalButtonComponentManager.OpenType.FACE_AUTHENTICATION,
  66. label: '人脸核身',
  67. // 调整按钮样式。
  68. styleOption: {
  69. styleConfig: new functionalButtonComponentManager.ButtonConfig()
  70. .fontSize(20)
  71. },
  72. },
  73. // 当OpenType为FACE_AUTHENTICATION时,回调必须为onFaceAuthentication。
  74. controller: new functionalButtonComponentManager.FunctionalButtonController()
  75. .onFaceAuthentication((err, data) => {
  76. if (err) {
  77. // 错误日志处理。
  78. hilog.error(0x0000, 'testTag', 'Failed to authenticate, error: %{public}d %{public}s', err.code, err.message);
  79. return;
  80. }
  81. // 成功日志处理。
  82. hilog.info(0x0000, 'testTag', 'succeeded in authenticating');
  83. // 获取授权码。
  84. let authCode: string = data.authCode as string;
  85. let openID: string = data.openID as string;
  86. hilog.info(0x0000, 'testTag', 'succeeded in authCode');
  87. // sceneid 表示场景ID。选项包括:0(实名验证)、1(人脸验证,验证姓名、证件类型、证件号码和人脸)和2(人脸验证,仅验证人脸)。
  88. this.obtainFaceVerifyDataInfo(authCode, 2, openID, "", "", (err, data) => {
  89. if (err) {
  90. hilog.error(0x0000, 'testTag', 'error: %{public}d %{public}s', err.code, err.message);
  91. return;
  92. }
  93. let verifyToken: string = data.verifyToken as string;
  94. new functionalButtonComponentManager.FunctionalButtonController().onFaceVerification(verifyToken,
  95. (error, data) => {
  96. if (error) {
  97. // 错误日志处理。
  98. hilog.error(0x0000, 'testTag', 'Failed to authenticate, error: %{public}d %{public}s', error.code, error.message);
  99. return;
  100. }
  101. let facialRecognitionVerificationToken = data.facialRecognitionVerificationToken;
  102. let state = data.state;
  103. hilog.info(0x0000, 'testTag', 'auth result success');
  104. });
  105. })
  106. })
  107. })
  108. }
  109. .width('100%')
  110. }
  111. .height('100%')
  112. }
  113. }

onChooseLocation

PhonePC/2in1TabletTV

onChooseLocation(callback: AsyncCallback<ChooseLocationResult>): FunctionalButtonController

注册FunctionalButton组件为打开地图选点的点击事件,使用callback异步回调。

该接口功能依赖Map Kit,参见chooseLocation

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本5.0.0(12)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

设备行为差异: 该接口在Phone、Tablet、PC/2in1中可正常调用,在其他设备类型中返回801错误码。

起始版本: 5.0.0(12)

参数:

展开
参数名 类型 必填 说明
callback AsyncCallback<ChooseLocationResult> 回调函数。当打开地图选点成功,err为undefined,data为地图选点的返回结果;否则为错误对象。

返回值:

展开
类型 说明
FunctionalButtonController FunctionalButton组件控制器。

示例:

收起
自动换行
深色代码主题
复制
  1. import { FunctionalButton, functionalButtonComponentManager } from '@kit.ScenarioFusionKit';
  2. import { hilog } from '@kit.PerformanceAnalysisKit';
  3. @Entry
  4. @Component
  5. struct Index {
  6. build() {
  7. Row() {
  8. Column() {
  9. // 构建FunctionalButton组件实例。
  10. FunctionalButton({
  11. params: {
  12. // OpenType.CHOOSE_LOCATION表示该按钮用于在地图上选择位置。
  13. openType: functionalButtonComponentManager.OpenType.CHOOSE_LOCATION,
  14. label: '地图选点',
  15. // 调整按钮样式。
  16. styleOption: {
  17. bgColor:functionalButtonComponentManager.ColorType.DEFAULT,
  18. size: functionalButtonComponentManager.SizeType.DEFAULT,
  19. plain: false,
  20. disabled:false,
  21. loading: false,
  22. hoverClass: functionalButtonComponentManager.HoverClassType.HOVER_CLASS,
  23. hoverStartTime: 0,
  24. hoverStayTime: 0,
  25. styleConfig: new functionalButtonComponentManager.ButtonConfig()
  26. .fontSize(20)
  27. },
  28. },
  29. // 当OpenType设置为CHOOSE_LOCATION时,回调必须为onChooseLocation。
  30. controller: new functionalButtonComponentManager.FunctionalButtonController()
  31. .onChooseLocation((err, data) => {
  32. if (err) {
  33. // 错误日志处理。
  34. hilog.error(0x0000, 'testTag', 'Failed to choose location, error: %{public}d %{public}s', err.code, err.message);
  35. return;
  36. }
  37. // 成功日志处理。
  38. hilog.info(0x0000, 'testTag', 'succeeded in choosing location');
  39. let name: string = data.name;
  40. let address: string = data.address;
  41. let longitude: number = data.longitude;
  42. let latitude: number = data.latitude;
  43. })
  44. })
  45. }.width('100%')
  46. }.height('100%')
  47. }
  48. }

onSubscribeLiveView

PhonePC/2in1TabletTV

onSubscribeLiveView(callback: AsyncCallback<SubscribeLiveViewResult>): FunctionalButtonController

注册FunctionalButton组件为实况窗订阅的点击事件,使用callback异步回调。

模型约束: 此接口仅可在Stage模型下使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

设备行为差异: 该接口在Phone、Tablet中可正常调用,在其他设备类型中返回801错误码。

起始版本: 5.0.0(12)

参数:

展开
参数名 类型 必填 说明
callback AsyncCallback<SubscribeLiveViewResult> 回调函数。当实况窗订阅点击成功,err为undefined,data为实况订阅的返回结果;否则为错误对象。

返回值:

展开
类型 说明
FunctionalButtonController FunctionalButton组件控制器。

示例:

收起
自动换行
深色代码主题
复制
  1. import { hilog } from '@kit.PerformanceAnalysisKit';
  2. import { FunctionalButton, functionalButtonComponentManager } from '@kit.ScenarioFusionKit';
  3. @Entry
  4. @Component
  5. struct Index {
  6. build() {
  7. Row() {
  8. Column() {
  9. // 构建FunctionalButton组件实例。
  10. FunctionalButton({
  11. params: {
  12. // OpenType.SUBSCRIBE_LIVE_VIEW表示该按钮用于实时视图订阅。
  13. openType: functionalButtonComponentManager.OpenType.SUBSCRIBE_LIVE_VIEW,
  14. label: '预约抢购',
  15. // 调整按钮样式。
  16. styleOption: {
  17. styleConfig: new functionalButtonComponentManager.ButtonConfig()
  18. .fontSize(20)
  19. },
  20. subscribeLiveViewParam: {
  21. event: "SUBSCRIBE_TIMER",
  22. alertTime: 172178838111,
  23. startTime: 172170198111
  24. },
  25. },
  26. // 当OpenType为SUBSCRIBE_LIVE_VIEW时,回调必须为onSubscribeLiveView。
  27. controller: new functionalButtonComponentManager.FunctionalButtonController().onSubscribeLiveView((err,
  28. data) => {
  29. if (err) {
  30. // 错误日志处理。
  31. hilog.error(0x0000, 'testTag', `Failed to subscribe LiveView, error code is: ${err?.code} message is ${err?.message}`);
  32. return;
  33. }
  34. let subscribeId = data.subscribeId;
  35. // 成功日志处理。
  36. hilog.info(0x0000, 'testTag', 'succeeded in subscribing LiveView');
  37. })
  38. })
  39. }
  40. .width('100%')
  41. }
  42. .height('100%')
  43. }
  44. }

onPermissionSetting

PhonePC/2in1TabletTV

onPermissionSetting(callback: AsyncCallback<PermissionSettingResult>): FunctionalButtonController

注册FunctionalButton组件为权限设置的点击事件,使用callback异步回调。

该接口功能依赖Ability Kit,参见requestPermissionOnSetting

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本5.0.2(14)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

设备行为差异: 该接口在Phone、Tablet、PC/2in1、TV、Car中可正常调用,在其他设备类型中返回801错误码。

起始版本: 5.0.2(14)

参数:

展开
参数名 类型 必填 说明
callback AsyncCallback<PermissionSettingResult> 回调函数。当权限设置点击成功,err为undefined,data为获取到的权限设置返回结果;否则为错误对象。

返回值:

展开
类型 说明
FunctionalButtonController FunctionalButton组件控制器。

示例:

收起
自动换行
深色代码主题
复制
  1. import { FunctionalButton, functionalButtonComponentManager } from '@kit.ScenarioFusionKit';
  2. import { hilog } from '@kit.PerformanceAnalysisKit';
  3. import { abilityAccessCtrl, common, PermissionRequestResult } from '@kit.AbilityKit';
  4. import { BusinessError } from '@kit.BasicServicesKit';
  5. @Entry
  6. @Component
  7. struct Index {
  8. build() {
  9. Row() {
  10. Column({ space: 3 }) {
  11. // 调用requestPermissionsFromUser接口Button。
  12. Button('请求用户授权')
  13. .fontSize(20)
  14. .onClick(() => {
  15. let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager();
  16. let context: Context = this.getUIContext().getHostContext() as common.UIAbilityContext;
  17. try {
  18. // 在module.json5文件中添加ohos.permission.READ_CALENDAR、ohos.permission.WRITE_CALENDAR权限。
  19. atManager.requestPermissionsFromUser(context,
  20. ['ohos.permission.READ_CALENDAR', 'ohos.permission.WRITE_CALENDAR'],
  21. (err: BusinessError, data: PermissionRequestResult) => {
  22. if (err) {
  23. hilog.error(0x0000, 'testTag', 'failed in requesting Permissions from user : %{public}d %{public}s',
  24. err.code, err.message);
  25. } else {
  26. hilog.info(0x0000, 'testTag', 'data permissions: %{public}s', data.permissions?.join(','));
  27. hilog.info(0x0000, 'testTag', 'data authResults: %{public}s', data.authResults?.join(','));
  28. hilog.info(0x0000, 'testTag', 'data dialogShownResults: %{public}s',data.dialogShownResults?.join(','));
  29. }
  30. })
  31. } catch (err) {
  32. hilog.error(0x0000, 'testTag', 'error: %{public}d %{public}s', err.code, err.message);
  33. }
  34. })
  35. // 构建FunctionalButton组件实例。
  36. FunctionalButton({
  37. params: {
  38. // OpenType.PERMISSION_SETTING表示该按钮用于设置权限。
  39. openType: functionalButtonComponentManager.OpenType.PERMISSION_SETTING,
  40. label: '权限设置',
  41. permissionListParam: ['ohos.permission.READ_CALENDAR', 'ohos.permission.WRITE_CALENDAR'],
  42. // 调整按钮样式。
  43. styleOption: {
  44. styleConfig: new functionalButtonComponentManager.ButtonConfig()
  45. .fontSize(20)
  46. },
  47. },
  48. // 当OpenType设置为PERMISSION_SETTING时,回调必须为onPermissionSetting。
  49. controller: new functionalButtonComponentManager.FunctionalButtonController().onPermissionSetting((err,
  50. data) => {
  51. if (err) {
  52. // 错误日志处理。
  53. hilog.error(0x0000, 'testTag', 'Failed to set permission, error: %{public}d %{public}s', err.code, err.message);
  54. return;
  55. }
  56. // 成功日志处理。
  57. hilog.info(0x0000, 'testTag', 'succeeded in setting permission ');
  58. let result = data.permissionResult;
  59. result.forEach(res => {
  60. hilog.info(0x0000, 'testTag', 'data: %{public}s', String(res));
  61. })
  62. })
  63. })
  64. }
  65. .width('100%')
  66. }
  67. .height('100%')
  68. }
  69. }

onRequestSubscribeMessage

PhonePC/2in1TabletTV

onRequestSubscribeMessage(callback: AsyncCallback<RequestSubscribeMessageResult>): FunctionalButtonController

注册FunctionalButton组件为服务动态授权码按钮的点击事件,使用callback异步回调。

说明

该接口在元服务中可正常使用。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本6.0.0(20)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

设备行为差异: 该接口在Phone、Tablet、PC/2in1中可正常调用,在其他设备类型中返回801错误码。

起始版本: 6.0.0(20)

参数:

展开
参数名 类型 必填 说明
callback AsyncCallback<RequestSubscribeMessageResult> 回调函数。当服务动态授权码按钮点击成功,err为undefined,data为获取到的code返回结果;否则为错误对象。

返回值:

展开
类型 说明
FunctionalButtonController FunctionalButton组件控制器。

错误码:

以下错误码的详细介绍请参见通用错误码ArkTS组件错误码

展开
错误码ID 错误信息
10004 Internal error.
10008 Not atomic service.

示例:

收起
自动换行
深色代码主题
复制
  1. import { FunctionalButton, functionalButtonComponentManager } from '@kit.ScenarioFusionKit';
  2. import { hilog } from '@kit.PerformanceAnalysisKit';
  3. @Entry
  4. @Component
  5. struct Index {
  6. build() {
  7. Row() {
  8. Column() {
  9. // 构建FunctionalButton组件实例。
  10. FunctionalButton({
  11. params: {
  12. // OpenType.REQUEST_SUBSCRIBE_MESSAGE表示该按钮用于获取服务动态授权码。
  13. openType: functionalButtonComponentManager.OpenType.REQUEST_SUBSCRIBE_MESSAGE,
  14. label: '服务动态授权码',
  15. // 在获取服务动态授权码时,名为subSceneId的参数是必填项。
  16. subSceneId: '',
  17. // 调整按钮样式。
  18. styleOption: {
  19. styleConfig: new functionalButtonComponentManager.ButtonConfig()
  20. .fontSize(20)
  21. },
  22. },
  23. // 当OpenType为REQUEST_SUBSCRIBE_MESSAGE时,回调必须为onRequestSubscribeMessage。
  24. controller: new functionalButtonComponentManager.FunctionalButtonController()
  25. .onRequestSubscribeMessage((err, data) => {
  26. if (err) {
  27. // 错误日志处理。
  28. hilog.error(0x0000, 'testTag', 'Failed to request subscribe message, error: %{public}d %{public}s', err.code, err.message);
  29. return;
  30. }
  31. // 成功日志处理。
  32. hilog.info(0x0000, 'testTag', 'succeeded in requesting subscribe message');
  33. // 处理服务代码。
  34. let code = data.code;
  35. })
  36. })
  37. }.width('100%')
  38. }.height('100%')
  39. }
  40. }

onShare

PhonePC/2in1TabletTV

onShare(callback: AsyncCallback<void>): FunctionalButtonController

注册FunctionalButton组件为分享按钮的点击事件,使用callback异步回调。

说明

仅提供给元服务使用。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本6.0.0(20)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

设备行为差异: 该接口在Phone、Tablet、PC/2in1中可正常调用,在其他设备类型中返回801错误码。

起始版本: 6.0.0(20)

参数:

展开
参数名 类型 必填 说明
callback AsyncCallback<void> 回调函数。当分享按钮点击成功,err为undefined,否则为错误对象。

返回值:

展开
类型 说明
FunctionalButtonController FunctionalButton组件控制器。

错误码:

以下错误码的详细介绍请参见通用错误码ArkTS组件错误码

展开
错误码ID 错误信息
10004 Internal error.
10006 Failed to get data.
10008 Not atomic service.
1007601001

Invalid share parameter value. Possible causes: 1. The uniformDataType parameter verification failed; 2. Invalid content parameter format.

适用版本: 26.0.0+

示例:

收起
自动换行
深色代码主题
复制
  1. import { FunctionalButton, functionalButtonComponentManager } from '@kit.ScenarioFusionKit';
  2. import { hilog } from '@kit.PerformanceAnalysisKit';
  3. @Entry
  4. @Component
  5. struct Index {
  6. build() {
  7. Row() {
  8. Column() {
  9. // 构建FunctionalButton组件实例。
  10. FunctionalButton({
  11. params: {
  12. // OpenType.SHARE 表示该按钮用于调出分享页面。
  13. openType: functionalButtonComponentManager.OpenType.SHARE,
  14. label: '元服务分享',
  15. shareParam: {
  16. previewUri: '',
  17. description: ''
  18. },
  19. // 调整按钮样式。
  20. styleOption: {
  21. styleConfig: new functionalButtonComponentManager.ButtonConfig()
  22. .fontSize(20)
  23. },
  24. },
  25. // 当OpenType设置为SHARE时,回调函数必须是onShare。
  26. controller: new functionalButtonComponentManager.FunctionalButtonController()
  27. .onShare((err) => {
  28. if (err) {
  29. // 错误日志处理。
  30. hilog.error(0x0000, 'testTag', 'Failed to pull up the sharing page, error: %{public}d %{public}s', err.code, err.message);
  31. return;
  32. }
  33. // 成功日志处理。
  34. hilog.info(0x0000, 'testTag', 'succeeded in pulling up the sharing page');
  35. })
  36. })
  37. }.width('100%')
  38. }.height('100%')
  39. }
  40. }

onFeedback

PhonePC/2in1TabletTV

onFeedback(callback: AsyncCallback<void>): FunctionalButtonController

注册FunctionalButton组件为反馈按钮的点击事件,使用callback异步回调。

说明

仅提供给元服务使用。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本6.0.0(20)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

设备行为差异: 该接口在Phone、Tablet、PC/2in1中可正常调用,在其他设备类型中返回801错误码。

起始版本: 6.0.0(20)

参数:

展开
参数名 类型 必填 说明
callback AsyncCallback<void> 回调函数。当反馈按钮点击成功,err为undefined,否则为错误对象。

返回值:

展开
类型 说明
FunctionalButtonController FunctionalButton组件控制器。

错误码:

以下错误码的详细介绍请参见通用错误码ArkTS组件错误码

展开
错误码ID 错误信息
10008 Not atomic service.

示例:

收起
自动换行
深色代码主题
复制
  1. import { FunctionalButton, functionalButtonComponentManager } from '@kit.ScenarioFusionKit';
  2. import { hilog } from '@kit.PerformanceAnalysisKit';
  3. @Entry
  4. @Component
  5. struct Index {
  6. build() {
  7. Row() {
  8. Column() {
  9. // 构建FunctionalButton组件实例。
  10. FunctionalButton({
  11. params: {
  12. // OpenType.FEEDBACK表示该按钮用于拉起反馈页面。
  13. openType: functionalButtonComponentManager.OpenType.FEEDBACK,
  14. label: '反馈与投诉',
  15. // 调整按钮样式。
  16. styleOption: {
  17. styleConfig: new functionalButtonComponentManager.ButtonConfig()
  18. .fontSize(20)
  19. },
  20. },
  21. // 当OpenType设置为FEEDBACK时,回调函数必须是onFeedback。
  22. controller: new functionalButtonComponentManager.FunctionalButtonController()
  23. .onFeedback((err) => {
  24. if (err) {
  25. // 错误日志处理。
  26. hilog.error(0x0000, 'testTag', 'Failed to pull up the feedback page, error: %{public}d %{public}s', err.code, err.message);
  27. return;
  28. }
  29. // 成功日志处理。
  30. hilog.info(0x0000, 'testTag', 'succeeded in pulling up the feedback page');
  31. })
  32. })
  33. }.width('100%')
  34. }.height('100%')
  35. }
  36. }

onGetPhoneNumberAndRiskLevel

PhonePC/2in1TabletTV

onGetPhoneNumberAndRiskLevel(callback: Callback<GetPhoneNumberAndRiskLevelResult>): FunctionalButtonController

注册FunctionalButton组件为获取手机号和风险等级的点击事件,使用callback同步回调。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本6.0.2(22)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 6.0.2(22)

参数:

展开
参数名 类型 必填 说明
callback Callback<GetPhoneNumberAndRiskLevelResult> 回调函数。返回获取手机号和风险等级的授权码。

返回值:

展开
类型 说明
FunctionalButtonController FunctionalButton组件控制器。

示例:

收起
自动换行
深色代码主题
复制
  1. import { FunctionalButton, functionalButtonComponentManager } from '@kit.ScenarioFusionKit';
  2. import { hilog } from '@kit.PerformanceAnalysisKit';
  3. @Entry
  4. @Component
  5. struct Index {
  6. build() {
  7. Row() {
  8. Column() {
  9. // 构建FunctionalButton组件实例。
  10. FunctionalButton({
  11. params: {
  12. // OpenType.GET_PHONE_NUMBER_AND_RISK_LEVEL表示该按钮用于获取手机号和风险等级。
  13. openType: functionalButtonComponentManager.OpenType.GET_PHONE_NUMBER_AND_RISK_LEVEL,
  14. label: '获取手机号和风险等级',
  15. // 调整按钮样式。
  16. styleOption: {
  17. styleConfig: new functionalButtonComponentManager.ButtonConfig()
  18. .fontSize(20)
  19. },
  20. },
  21. // 当OpenType为GET_PHONE_NUMBER_AND_RISK_LEVEL时,回调必须为onGetPhoneNumberAndRiskLevel。
  22. controller: new functionalButtonComponentManager.FunctionalButtonController()
  23. .onGetPhoneNumberAndRiskLevel((data) => {
  24. if (data?.errCode) {
  25. // 错误日志处理。
  26. hilog.error(0x0000, 'testTag', 'Failed to authenticate, error: %{public}d %{public}s', data?.errCode, data?.errMsg);
  27. return;
  28. }
  29. // 成功日志处理。
  30. hilog.info(0x0000, 'testTag', 'succeeded in authentication');
  31. // 授权码处理。
  32. let authorizationCode = data?.code;
  33. })
  34. })
  35. }
  36. .width('100%')
  37. }
  38. .height('100%')
  39. }
  40. }

ButtonConfig

PhonePC/2in1TabletTV

该类提供了实现FunctionalButton自定义属性的方法。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 4.1.0(11)

type

PhonePC/2in1TabletTV

type(value: ButtonType): ButtonConfig

设置FunctionalButton的显示样式属性。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 4.1.0(11)

参数:

展开
参数名 类型 必填 说明
value ButtonType

描述按钮显示样式。

默认值:ButtonType.Capsule

返回值:

展开
类型 说明
ButtonConfig ButtonConfig对象。

stateEffect

PhonePC/2in1TabletTV

stateEffect(value: boolean): ButtonConfig

设置FunctionalButton是否开启按压态显示效果属性。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 4.1.0(11)

参数:

展开
参数名 类型 必填 说明
value boolean

按钮按下时是否开启按压态显示效果,当设置为false时,按压效果关闭;设置为true时,按压效果开启。

默认值:true

返回值:

展开
类型 说明
ButtonConfig ButtonConfig对象。

fontColor

PhonePC/2in1TabletTV

fontColor(value: ResourceColor): ButtonConfig

设置FunctionalButton的字体颜色属性。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 4.1.0(11)

参数:

展开
参数名 类型 必填 说明
value ResourceColor

设置字体颜色。

默认值:#ffffff

返回值:

展开
类型 说明
ButtonConfig ButtonConfig对象。

fontSize

PhonePC/2in1TabletTV

fontSize(value: Length): ButtonConfig

设置FunctionalButton的字体大小属性。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 4.1.0(11)

参数:

展开
参数名 类型 必填 说明
value Length

设置字体大小,Length为number类型时,使用fp单位。

字体默认大小16fp。不支持设置百分比字符串。

返回值:

展开
类型 说明
ButtonConfig ButtonConfig对象。

fontWeight

PhonePC/2in1TabletTV

fontWeight(value: string | number | FontWeight): ButtonConfig

设置FunctionalButton的字体粗细属性。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 4.1.0(11)

参数:

展开
参数名 类型 必填 说明
value string | number | FontWeight

设置文本的字体粗细,number类型取值[100, 900],取值间隔为100,默认为400,取值越大,字体越粗。string类型仅支持number类型取值的字符串形式,例如"400",以及"bold","bolder","lighter","regular","medium","normal",分别对应FontWeight中相应的枚举值。

默认值:FontWeight.Normal

返回值:

展开
类型 说明
ButtonConfig ButtonConfig对象。

fontStyle

PhonePC/2in1TabletTV

fontStyle(value: FontStyle): ButtonConfig

设置FunctionalButton的字体样式属性。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 4.1.0(11)

参数:

展开
参数名 类型 必填 说明
value FontStyle

设置字体样式。

默认值:FontStyle.Normal

返回值:

展开
类型 说明
ButtonConfig ButtonConfig对象。

fontFamily

PhonePC/2in1TabletTV

fontFamily(value: string | Resource): ButtonConfig

设置FunctionalButton的字体属性。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 4.1.0(11)

参数:

展开
参数名 类型 必填 说明
value string | Resource 设置字体列表。默认字体'HarmonyOS Sans',当前支持'HarmonyOS Sans'字体和注册自定义字体

返回值:

展开
类型 说明
ButtonConfig ButtonConfig对象。

width

PhonePC/2in1TabletTV

width(value: Length): ButtonConfig

设置FunctionalButton的宽度属性。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 4.1.0(11)

参数:

展开
参数名 类型 必填 说明
value Length 设置组件自身的宽度,缺省时使用元素自身内容需要的宽度。

返回值:

展开
类型 说明
ButtonConfig ButtonConfig对象。

height

PhonePC/2in1TabletTV

height(value: Length): ButtonConfig

设置FunctionalButton的高度属性。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 4.1.0(11)

参数:

展开
参数名 类型 必填 说明
value Length 设置组件自身的高度,缺省时使用元素自身内容需要的高度。

返回值:

展开
类型 说明
ButtonConfig ButtonConfig对象。

size

PhonePC/2in1TabletTV

size(value: SizeOptions): ButtonConfig

设置FunctionalButton的高宽尺寸属性。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 4.1.0(11)

参数:

展开
参数名 类型 必填 说明
value SizeOptions

设置高宽尺寸。举例:

{

width: 20,

height: 50

}

单位:vp。

返回值:

展开
类型 说明
ButtonConfig ButtonConfig对象。

constraintSize

PhonePC/2in1TabletTV

constraintSize(value: ConstraintSizeOptions): ButtonConfig

设置FunctionalButton的约束尺寸属性。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 4.1.0(11)

参数:

展开
参数名 类型 必填 说明
value ConstraintSizeOptions

设置约束尺寸,组件布局时,进行尺寸范围限制。constraintSize的优先级高于width和height。取值结果参考constraintSize取值对width/height影响

默认值:

{

minWidth: 0,

maxWidth: Infinity,

minHeight: 0,

maxHeight: Infinity

}

单位:vp。

返回值:

展开
类型 说明
ButtonConfig ButtonConfig对象。

padding

PhonePC/2in1TabletTV

padding(value: Length | Padding): ButtonConfig

设置FunctionalButton的内边距属性。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 4.1.0(11)

参数:

展开
参数名 类型 必填 说明
value Length | Padding

设置内边距属性。

参数为Length类型时,四个方向内边距同时生效。

默认值:{left: 16, right: 16}

单位:vp。

返回值:

展开
类型 说明
ButtonConfig ButtonConfig对象。

margin

PhonePC/2in1TabletTV

margin(value: Length | Padding): ButtonConfig

设置FunctionalButton的外边距属性。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 4.1.0(11)

参数:

展开
参数名 类型 必填 说明
value Length | Padding

设置外边距属性。

参数为Length类型时,四个方向外边距同时生效。

默认值:0

单位:vp。

返回值:

展开
类型 说明
ButtonConfig ButtonConfig对象。

backgroundColor

PhonePC/2in1TabletTV

backgroundColor(value: ResourceColor): ButtonConfig

设置FunctionalButton的背景色属性。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 4.1.0(11)

参数:

展开
参数名 类型 必填 说明
value ResourceColor

设置组件的背景色。

默认值:#ff007dff

返回值:

展开
类型 说明
ButtonConfig ButtonConfig对象。

backgroundImage

PhonePC/2in1TabletTV

backgroundImage(src: ResourceStr, repeat?: ImageRepeat): ButtonConfig

设置FunctionalButton的背景图像属性。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 4.1.0(11)

参数:

展开
参数名 类型 必填 说明
src ResourceStr 图片地址,支持网络图片资源和本地图片资源地址,不支持svg类型的图片。
repeat ImageRepeat 设置背景图的重复样式,默认不重复。当设置的背景图片为透明底色图片,且同时设置了backgroundColor时,二者叠加显示,背景颜色在最底部。

返回值:

展开
类型 说明
ButtonConfig ButtonConfig对象。

backgroundImageSize

PhonePC/2in1TabletTV

backgroundImageSize(value: SizeOptions | ImageSize): ButtonConfig

设置FunctionalButton的背景图像的高度和宽度属性。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 4.1.0(11)

参数:

展开
参数名 类型 必填 说明
value SizeOptions | ImageSize

设置背景图像的高度和宽度。当输入为{width: Length, height: Length}对象时,如果只设置一个属性,则第二个属性保持图片原始宽高比进行调整。默认保持原图的比例不变。

width和height取值范围: [0, +∞)

默认值:ImageSize.Auto

说明:

设置为小于0的值时,按值为0显示。当设置了height未设置width时,width根据图片原始宽高比进行调整。

返回值:

展开
类型 说明
ButtonConfig ButtonConfig对象。

backgroundImagePosition

PhonePC/2in1TabletTV

backgroundImagePosition(value: Position | Alignment): ButtonConfig

设置FunctionalButton的背景图像的显示位置属性。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 4.1.0(11)

参数:

展开
参数名 类型 必填 说明
value Position | Alignment

设置背景图像在组件中显示位置,即相对于组件左上角的坐标,单位:vp。

默认值:

{

x: 0,

y: 0

}

x和y值设置百分比时,偏移量是相对组件自身宽高计算的。

返回值:

展开
类型 说明
ButtonConfig ButtonConfig对象。

opacity

PhonePC/2in1TabletTV

opacity(value: number | Resource): ButtonConfig

设置FunctionalButton的透明度属性。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 4.1.0(11)

参数:

展开
参数名 类型 必填 说明
value number | Resource

元素的不透明度,取值范围为0到1,默认值:1,1表示不透明,0表示完全透明,达到隐藏组件效果,但是在布局中占位。

说明:

子组件可以继承父组件的此属性。

返回值:

展开
类型 说明
ButtonConfig ButtonConfig对象。

border

PhonePC/2in1TabletTV

border(value: BorderOptions): ButtonConfig

统一设置FunctionalButton的边框宽度、边框颜色、边框圆角半径、边框样式属性。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 4.1.0(11)

参数:

展开
参数名 类型 必填 说明
value BorderOptions

统一边框样式设置接口。

- width:设置边框宽度。

- color:设置边框颜色。

- radius:设置边框圆角半径。

- style:设置边框样式。

说明:

边框宽度默认值为0,即不显示边框。

返回值:

展开
类型 说明
ButtonConfig ButtonConfig对象。

borderStyle

PhonePC/2in1TabletTV

borderStyle(value: BorderStyle | EdgeStyles): ButtonConfig

设置FunctionalButton的边框样式属性。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 4.1.0(11)

参数:

展开
参数名 类型 必填 说明
value BorderStyle | EdgeStyles

设置元素的边框样式。

默认值:BorderStyle.Solid

返回值:

展开
类型 说明
ButtonConfig ButtonConfig对象。

borderWidth

PhonePC/2in1TabletTV

borderWidth(value: Length | EdgeWidths): ButtonConfig

设置FunctionalButton的边框宽度属性。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 4.1.0(11)

参数:

展开
参数名 类型 必填 说明
value Length | EdgeWidths

设置元素的边框宽度,不支持百分比。

默认值:1,单位:vp。

返回值:

展开
类型 说明
ButtonConfig ButtonConfig对象。

borderColor

PhonePC/2in1TabletTV

borderColor(value: ResourceColor | EdgeColors): ButtonConfig

设置FunctionalButton的边框颜色属性。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 4.1.0(11)

参数:

展开
参数名 类型 必填 说明
value ResourceColor | EdgeColors

设置元素的边框颜色。

默认值:#000000

返回值:

展开
类型 说明
ButtonConfig ButtonConfig对象。

borderRadius

PhonePC/2in1TabletTV

borderRadius(value: Length | BorderRadiuses): ButtonConfig

设置FunctionalButton的边框圆角半径属性。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 4.1.0(11)

参数:

展开
参数名 类型 必填 说明
value Length | BorderRadiuses 设置元素的边框圆角半径,不支持百分比。

返回值:

展开
类型 说明
ButtonConfig ButtonConfig对象。

borderImage

PhonePC/2in1TabletTV

borderImage(value: BorderImageOption): ButtonConfig

设置FunctionalButton的图片边框属性。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 4.1.0(11)

参数:

展开
参数名 类型 必填 说明
value BorderImageOption

图片边框或者渐变色边框设置接口。

该接口支持在ArkTS卡片中使用。

返回值:

展开
类型 说明
ButtonConfig ButtonConfig对象。

scale

PhonePC/2in1TabletTV

scale(value: ScaleOptions): ButtonConfig

设置FunctionalButton的缩放属性。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 4.1.0(11)

参数:

展开
参数名 类型 必填 说明
value ScaleOptions

可以分别设置X轴、Y轴、Z轴的缩放比例,默认值为1.0,同时可以通过centerX和centerY设置缩放的中心点。

默认值:

{

x: 1.0,

y: 1.0,

z: 1.0,

centerX:'0.5',

centerY:'0.5'

}

返回值:

展开
类型 说明
ButtonConfig ButtonConfig对象。

align

PhonePC/2in1TabletTV

align(value: Alignment): ButtonConfig

设置FunctionalButton的对齐方式属性。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 4.1.0(11)

参数:

展开
参数名 类型 必填 说明
value Alignment

设置元素内容的对齐方式,只有当设置的width和height大小超过元素本身内容大小时生效。

默认值:Alignment.Center

返回值:

展开
类型 说明
ButtonConfig ButtonConfig对象。

markAnchor

PhonePC/2in1TabletTV

markAnchor(value: Position): ButtonConfig

设置FunctionalButton在位置定位时的锚点。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 4.1.0(11)

参数:

展开
参数名 类型 必填 说明
value Position

设置元素在位置定位时的锚点,以元素顶部起点作为基准点进行偏移,单位:vp。

默认值:

{

x: 0,

y: 1

}

返回值:

展开
类型 说明
ButtonConfig ButtonConfig对象。

offset

PhonePC/2in1TabletTV

offset(value: Position): ButtonConfig

设置FunctionalButton在位置坐标偏移量。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 4.1.0(11)

参数:

展开
参数名 类型 必填 说明
value Position

设置元素在位置定位时的锚点,以元素顶部起点作为基准点进行偏移,单位:vp。

默认值:

{

x: 0,

y: 1

}

返回值:

展开
类型 说明
ButtonConfig ButtonConfig对象。

enabled

PhonePC/2in1TabletTV

enabled(value: boolean): ButtonConfig

设置FunctionalButton的是否禁用属性。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 4.1.0(11)

参数:

展开
参数名 类型 必填 说明
value boolean

值为true表示组件可交互,响应点击等操作。

值为false表示组件不可交互,不响应点击等操作。

默认值:true

返回值:

展开
类型 说明
ButtonConfig ButtonConfig对象。

loadingColor

PhonePC/2in1TabletTV

loadingColor(value: ResourceColor): ButtonConfig

设置FunctionalButton中的LoadingProgress图标的颜色属性。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 4.1.0(11)

参数:

展开
参数名 类型 必填 说明
value ResourceColor

设置图标颜色。默认值:#FFFFFF

说明:

设置为异常值时,按值为'#ff666666'显示。

返回值:

展开
类型 说明
ButtonConfig ButtonConfig对象。

loadingWidth

PhonePC/2in1TabletTV

loadingWidth(value: Length): ButtonConfig

设置FunctionalButton中的LoadingProgress图标的宽度属性。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 4.1.0(11)

参数:

展开
参数名 类型 必填 说明
value Length

设置图标自身的宽度。默认值:20,单位:vp。

取值范围:(-∞, +∞)

填写为负数时,宽度不超过按钮大小;填写正数时,宽度不受限于按钮大小,请合理填写数值。

说明:

LoadingProgress图标始终保持正方形,在显示时边长会取loadingWidth和loadingHeight中的最小值。

返回值:

展开
类型 说明
ButtonConfig ButtonConfig对象。

loadingHeight

PhonePC/2in1TabletTV

loadingHeight(value: Length): ButtonConfig

设置FunctionalButton中的LoadingProgress图标的高度属性。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 4.1.0(11)

参数:

展开
参数名 类型 必填 说明
value Length

设置图标自身的高度。默认值:20,单位:vp。

取值范围:(-∞, +∞)

填写为负数时,高度不超过按钮大小。填写正数时,高度不受限于按钮大小,请合理填写数值。

说明:

LoadingProgress图标始终保持正方形,在显示时边长会取loadingWidth和loadingHeight中的最小值。

返回值:

展开
类型 说明
ButtonConfig ButtonConfig对象。

loadingPadding

PhonePC/2in1TabletTV

loadingPadding(value: Length | Padding): ButtonConfig

设置FunctionalButton中的LoadingProgress图标的内边距属性。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 4.1.0(11)

参数:

展开
参数名 类型 必填 说明
value Length | Padding

设置图标内边距属性。单位:vp。

默认值:0

取值范围:(-∞, +∞)

返回值:

展开
类型 说明
ButtonConfig ButtonConfig对象。

loadingMargin

PhonePC/2in1TabletTV

loadingMargin(value: Length | Padding): ButtonConfig

设置FunctionalButton中的LoadingProgress图标的外边距属性。

模型约束: 此接口仅可在Stage模型下使用。

元服务API: 从版本4.1.0(11)开始,该接口支持在元服务中使用。

系统能力: SystemCapability.AtomicserviceComponent.UIComponent

起始版本: 4.1.0(11)

参数:

展开
参数名 类型 必填 说明
value Length | Padding

设置图标外边距属性。单位:vp。

默认值:{left: -2, right: 2}

取值范围:(-∞, +∞)

返回值:

展开
类型 说明
ButtonConfig ButtonConfig对象。

示例

PhonePC/2in1TabletTV

示例一(场景化Button使用自定义Modifier设置按钮样式)

收起
自动换行
深色代码主题
复制
  1. import { FunctionalButton, functionalButtonComponentManager } from '@kit.ScenarioFusionKit';
  2. import { hilog } from '@kit.PerformanceAnalysisKit';
  3. import { ButtonModifier, LoadingProgressModifier, TextModifier } from '@kit.ArkUI';
  4. @Entry
  5. @Component
  6. struct Index {
  7. build() {
  8. Row() {
  9. Column() {
  10. // 构建FunctionalButton组件实例。
  11. FunctionalButton({
  12. params: {
  13. // OpenType.GET_PHONE_NUMBER表示该按钮用于快速验证手机号码。
  14. openType: functionalButtonComponentManager.OpenType.GET_PHONE_NUMBER,
  15. label: '快速验证手机号',
  16. // 调整按钮样式。
  17. styleOption: {
  18. loading: true,
  19. },
  20. textModifier: new TextModifier().fontColor(Color.Pink),
  21. buttonModifier: new ButtonModifier().backgroundColor(Color.Green),
  22. loadingProgressModifier: new LoadingProgressModifier().width(20).height(20),
  23. },
  24. // 当OpenType为GET_PHONE_NUMBER时,回调必须为onGetPhoneNumber。
  25. controller: new functionalButtonComponentManager.FunctionalButtonController()
  26. .onGetPhoneNumber((err, data) => {
  27. if (err) {
  28. // 错误日志处理。
  29. hilog.error(0x0000, 'testTag', 'Failed to authenticate, error: %{public}d %{public}s', err.code, err.message);
  30. return;
  31. }
  32. // 成功日志处理。
  33. hilog.info(0x0000, 'testTag', 'succeeded in authenticating');
  34. // 处理授权码。
  35. let authorizationCode = data.code;
  36. })
  37. })
  38. }
  39. .width('100%')
  40. }
  41. .height('100%')
  42. }
  43. }

在 API参考 中进行搜索
请输入您想要搜索的关键词