接口文档Utils

Class: Utils

description 命名空间utils

expample

// 在组件内的使用方式

// broadcast为方法
// eventName和data为broadcast方法的参数
this.bridge.invoke('utils', 'broadcast', eventName, data);

// preloadImg为方法
// imageUrl为preloadImg方法的参数
this.bridge.invoke('utils', 'preloadImg', imageUrl);

Hierarchy

Index

Methods

Methods

broadcast

broadcast(event: string, ...data: any[]): void

广播自定义事件给其他组件

example

// 组件A监听evt1
this.bridge.on('utils', 'evt1', (t)=>{
  // t == 1
});

// 组件B触发事件evt1, 附带参数的值为1
this.bridge.invoke('utils', 'broadcast', 'evt1', 1);

Parameters:

Name Type Description
event string 事件名
...data any[] 事件触发时附带的数据

Returns: void


getConditionValue

getConditionValue(condition: string): Promise‹any›

获取某个条件的值

example

// 假设数值v123=3
const value = await this.bridge.invoke('utils', 'getConditionValue', 'v123>0'); // value == true

Parameters:

Name Type
condition string

Returns: Promise‹any›


getString

getString(keys: Array‹string›): any

kv存储的读接口

example

// 假设test1存了字符串'a',test2存了字符串'bb'
const { test1, test2 } = await this.bridge.invoke('utils', 'getString', ['test1', 'test2']);
// test1 == 'a' test2 == 'bb'

Parameters:

Name Type Description
keys Array‹string› kv存储的key的数组

Returns: any


getValue

getValue(props: string): Promise‹any›

获取某个数值的值

example

// 假设数值v123=3
const value = await this.bridge.getValue('v123'); // value == 3

Parameters:

Name Type Description
props string 数值变量名

Returns: Promise‹any›


getValueName

getValueName(props: string): string

获取某个数值的名称

example

// 假设数值v123对应的名称是'好感度'
const value = await this.bridge.getValue('v123'); // value == '好感度'

Parameters:

Name Type Description
props string 数值变量名

Returns: string


listenCondition

listenCondition(condition: string): void

用户监听表达式变化

Parameters:

Name Type
condition string

Returns: void


percent2Px

percent2Px(__namedParameters: object): object

百分比转像素

example

// 假设视频画面是160px * 90px,那么10% * 10% 转换成像素就是16px * 9px
const { x, y } = await this.bridge.invoke('utils', 'percent2Px', {
  x: 0.1, // 0.1 == 10%
  y: 0.1
});
// x == 16, y == 9

Parameters:

__namedParameters: object

Name Type Default
x number 0
y number 0

Returns: object


preloadImg

preloadImg(param: any): void

预加载图片

example

this.bridge.invoke('utils', 'preloadImg', 'https://xxx.com/xxx.jpg');
this.bridge.invoke('utils', 'preloadImg', ['https://xxx.com/xxx.jpg', ...]);

Parameters:

Name Type Description
param any 字符串或者字符串数组,字符串为图片的下载地址

Returns: void


px2Percent

px2Percent(__namedParameters: object): object

像素单位转百分比

example

// 假设视频画面是160px * 90px,那么16px * 9px 转换成百分比就是10% * 10%
const { x, y } = await this.bridge.invoke('utils', 'px2Percent', {
  x: 16,
  y: 9
});
// x == 0.1, y == 0.1

Parameters:

__namedParameters: object

Name Type Default
x number 0
y number 0

Returns: object


setString

setString(kv: object): any

kv存储的写接口

example

await this.bridge.invoke('utils', 'setString', {
  key: 'test1',
  value: 'a'
});

Parameters:

kv: object

Name Type Description
key string kv存储的key
value string kv存储的value

Returns: any