接口文档AdapterBridge

Class: AdapterBridge

互动适配层提供了接口用于对App的设置、获取用户数据等操作能力,通常在组件内调用

注意: 所有的方法都是异步方法,接口会返回一个Promise对象

如果需要获取返回值,需要在 await 之后或者接口调用的 then 方法中获取

常见的调用方式如下:

方式一: 需要获得接口返回值

const { code, msg, result } = await this.bridge.invoke('bridge', apiMethod, apiParam);

方式二: 不需要获取返回值,并且后面的流程在执行顺序上不依赖此接口

this.bridge.invoke('bridge', apiMethod, apiParam);

方式三: 不需要获取返回值,但是后续流程在执行顺序上依赖此接口


// 使用 await 的方式
await this.bridge.invoke('bridge', apiMethod, apiParam);
// 后续执行逻辑

// 使用 Promise.then 的方式
this.bridge.invoke('bridge', apiMethod, apiParam).then(() => {
  // 后续流程
})

Hierarchy

Implements

Index

Events

Methods

Events

Static DEVICEMOTION

DEVICEMOTION: string = "devicemotion"

设备的位置和方向的改变速度事件。在设备的位置和方向的改变速度生变化时触发,常见于制作VR效果等

更多可以参考:https://developer.mozilla.org/zh-CN/docs/Web/API/DeviceMotionEvent


Static DEVICEORIENTATION

DEVICEORIENTATION: string = "deviceorientation"

设备方向变化事件。在设备方向发生变化时触发,常见于制作VR效果等

更多可以参考:https://developer.mozilla.org/zh-CN/docs/Web/API/Detecting_device_orientation


Static LOGIN_STATUS_CHANGE

LOGIN_STATUS_CHANGE: string = "loginStatusChange"

登录态变化事件,在当前登录态发生变化时触发


Static NETWORK_STATE_CHANGE

NETWORK_STATE_CHANGE: string = "networkStateChange"

网络状态变化事件。当网络状态发生变化时触发


Static PAGE_APPEAER

PAGE_APPEAER: string = "pageAppear"

当前页面可见事件。在当前页面显示时或者切换到前台时触发


Static PAGE_DISAPPEAR

PAGE_DISAPPEAR: string = "pageDisappear"

当前页面不可见事件。在当前页面隐藏或者切换到后台时触发

Methods

accessLocal

accessLocal(param: object): Promise‹IResult

本地数据存储操作

example

// set | update
const { code, msg, result } = await this.bridge.invoke('brige', 'accessLocal', {
  type: 'set',
  key: 'name',
  value: 'hello'
});
if (code === 0) {
  // 设置成功
} else {
  // 操作失败
  console.log(msg);
}

// get
const { code , msg, result } = await this.bridge.invoke('bridge', 'accessLocal', {
  type: 'get',
  key: 'name'
});
if (code === 0) {
  // 获取值
  console.log(result.textValue.name);
} else {
  // 操作失败
  console.log(msg);
}

Parameters:

param: object

Name Type Description
key string 要操作的key,只有type 为 set / update 时才需要
type string 操作类型, 取值为 : get / set / update
value string 要设置的value,只有type 为 set / update 时才需要

Returns: Promise‹IResult


accessStore

accessStore(param: object): Promise‹IResult

服务端数据存储操作

example

// set | update
const { code, msg, result } = await this.bridge.invoke('brige', 'accessStore', {
  type: 'set',
  key: 'name',
  value: 'hello'
});
if (code === 0) {
  // 设置成功
} else {
  // 操作失败
  console.log(msg);
}

// get
const { code , msg, result } = await this.bridge.invoke('bridge', 'accessStore', {
  type: 'get'
});
if (code === 0) {
  // 获取值
  console.log(result.textValue);
} else {
  // 操作失败
  console.log(msg);
}

Parameters:

param: object

Name Type Description
isTest boolean 是否为接口测试环境,默认 false
key string 要操作的key,只有type 为 set / update 时才需要
type string 操作类型, 取值为 : get / set / update
value string 要设置的value,只有type 为 set / update 时才需要

Returns: Promise‹IResult


addCalendarNotice

addCalendarNotice(param: object): Promise‹IResult

添加到日历提醒

example

const { code, msg, result } = await this.bridge.invoke('bridge', 'addCalendarNotice', {
  title: '今天吃烤肉',
  startTime: 1565700408,
  location: '深圳腾讯滨海大厦',
  alarmStr: '喝酒',
  notes: '烤肉派对',
  url: 'https://qq.com'
});
if (code === 0) {
  // 添加日历提醒成功
} else {
  // 添加日历提醒失败
  console.log(msg)
}

Parameters:

param: object

Name Type Description
alarmStr? string 提醒文本
allDay? number 是否全天
location? string 地点
notes? string 提醒备注
startTime string 开始时间,单位: 秒
title string 标题
url? string 提醒跳转url

Returns: Promise‹IResult


addShortcut

addShortcut(param: object): Promise‹IResult

添加到桌面快捷方式

example

const { code, msg, result } = await this.bridge.invoke('bridge', 'addShortcur', {
  title: '游戏标题',
  icon: 'https://example.com/path/to/icon.png',
  url: 'https://example.com/path/to/page.html',
  h5url: 'https://example.com/path/to/h5page.html',
});
if (code === 0) {
  // 添加成功
} else {
  // 添加失败
 console.log(msg)
}

Parameters:

param: object

Name Type Description
icon string 图标,在iPhone下,图标由中间页来指定
title string 标题
url string 快捷方式对应的链接

Returns: Promise‹IResult


close

close(): Promise‹IResult

关闭当前webview

example

this.bridge.invoke('bridge', 'close');

Returns: Promise‹IResult


collectAction

collectAction(param: object): Promise‹IResult

收藏操作

example

// 添加收藏
const { code, msg } = await this.bridge.invoke('bridge', 'collectAction', {
  type: 0,
});
if (code === 0) {
  // 收藏成功
} else {
  // 收藏失败
  console.log(msg)
}

Parameters:

param: object

Name Type Description
type string 操作类型。添加收藏: 0, 取消收藏: 1, 查询是否收藏: 2

Returns: Promise‹IResult


compareAppVer

compareAppVer(param: object): Promise‹IResult

比较版本

example

const { result } = await this.bridge.invoke('bridge', 'compareAppVer', {
  v1: '1.0.0',
  v2: '1.1.1'
});
console.log(result) // -1

Parameters:

param: object

Name Type Description
v1 string 版本1
v2 string 版本2

Returns: Promise‹IResult


copyToClipBoard

copyToClipBoard(param: object): Promise‹IResult

复制到粘贴板

example

const { code, msg } = await this.bridge.invoke('bridge', 'copyToClipBoard', {
  content: 'hello world'
});
if (code === 0) {
  // 复制成功
} else {
  // 复制失败
  console.log(msg)
}

Parameters:

param: object

Name Type Description
content string 需要复制的文本

Returns: Promise‹IResult


destroyAllSound

destroyAllSound(): Promise‹IResult

销毁全部音频

example

this.bridge.invoke('bridge', 'destroyAllSound');

Returns: Promise‹IResult


destroySound

destroySound(id: string): Promise‹IResult

销毁音频

example

this.bridge.invoke('bridge', 'destroySound', {
  id: '123',
});

Parameters:

Name Type Description
id string 音频id

Returns: Promise‹IResult


downloadGame

downloadGame(param: object): Promise‹IResult

游戏下载

example

this.bridge.invoke('bridge', 'downloadGamue', {
  gameInfo: {
    gameId: '', // 游戏在爱玩平台的游戏id
    qqGameAppId: '', // 游戏在QQ平台的appid
    android: {}, // 参考 http://athena.pages.oa.com/components/download/
    ios: {} // 参考 http://athena.pages.oa.com/components/download/
  },
  extra: {  // 传递给客户端进行染色上报数据
    reportParams: ''
  }
})

Parameters:

param: object

Name Type
extra object
gameInfo object

Returns: Promise‹IResult


excuteVExpression

excuteVExpression(expressionInfo: object): Promise‹IResult

执行v数值表达式

example

this.bridge.invoke('bridge', 'excuteVExpression', {
  nodeId: '123',
  time: 2,
  expression: '1+1'
})

Parameters:

expressionInfo: object

Name Type
expression string
nodeId string
time? number

Returns: Promise‹IResult


getAppData

getAppData(): Promise‹IResult

获取App数据

example

const { code, msg, result } = await this.bridge.invoke('bridge', 'getAppData');
if (code === 0) {
  // 获取成功
  console.log(result);
} else {
  // 获取失败
  console.log(msg);
}

Returns: Promise‹IResult


getAuthCode

getAuthCode(): Promise‹IResult

获取用户登录凭据code

example

const { code, msg, result } = await this.bridge.invoke('bridge', 'getAuthCode');
if ( code === 0) {
  // 获取用户登录凭据code成功
  console.log(result.code)
} else {
  // 获取用户登录凭据失败
  console.log(msg);
}

Returns: Promise‹IResult


getBrightness

getBrightness(): Promise‹IResult

获取屏幕亮度

example

const { code, msg, result } = await this.bridge.invoke('bridge', 'getBrightness');
if (code === 0) {
  // 获取屏幕亮度成功
  console.log(result.brightness); // 亮度
} else {
  // 获取屏幕亮度失败
  console.log(msg)
}

Returns: Promise‹IResult


getDeviceId

getDeviceId(): Promise‹IResult

获取设备id

example

const { code, msg, result } = await this.bridge.invoke('bridge', 'getDevice');
if(code === 0) {
  // 获取设备id成功
  console.log(result.id)
} else {
  // 获取设备id失败
  console.log(msg);
}

Returns: Promise‹IResult


getDeviceInfo

getDeviceInfo(): Promise‹IResult

获取设备信息

example

const { code, msg, result } = await this.bridge.invoke('bridge', 'getDeviceInfo');

if (code === 0) {
  // 获取成功
  console.log(result);
} else {
  // 获取失败
  console.log(msg);
}

Returns: Promise‹IResult


getHostID

getHostID(): Promise‹IResult

获取宿主ID

example

const { code, msg, result } = await this.bridge.invoke('bridge', 'getHostID');
if (code === 0) {
  // 获取成功
  console.log(result.host);
} else {
  // 获取失败
  console.log(msg);
}

Returns: Promise‹IResult


getImageBase64String

getImageBase64String(param: object): Promise‹IResult

获取base64url图片链接

example

const { code, msg, result } = await this.bridge.invoke('bridge', 'getImageBase64String', {
   url: 'https://example.com/path/to/some.png',
});
if (code === 0) {
  // 获取成功,返回值为base64格式的图片
  console.log(result.url)
} else {
  // 获取失败
  console.log(msg);
}

Parameters:

param: object

Name Type Description
url string 图片在线地址

Returns: Promise‹IResult


getNetworkState

getNetworkState(): Promise‹IResult

获取网络状态

example

const { code, msg, result } = await this.bridge.invoke('bridge’,'getNetworkState');
if (code === 0) {
  console.log(result.state); // 网络状态 0-无网络 1-wifi 2-2g 3-3g 4-4g 5-其他网络
} else {
  // 获取网络状态失败
  console.log(msg)
}

Returns: Promise‹IResult


getPayState

getPayState(param: object): Promise‹IResult

查询支付状态

example

this.bridge.invoke('bridge', 'getPayState', {
  dramaId: '',
  productId: '',
  isTest: false
})

Parameters:

param: object

Name Type
dramaId string
isTest? boolean
productId? string

Returns: Promise‹IResult


getPlatform

getPlatform(): Promise‹IResult

获取当前运行的平台

example

const { code, msg, result } = await this.bridge.invoke('bridge', 'getPlatform');
if (code === 0) {
  // 获取当前运行平台成功
  console.log(result.platform) // 运行平台,例如:tenvideo_ios, tenvideo_android
} else {
  // 获取当前运行平台失败
  console.log(msg)
}

Returns: Promise‹IResult


getProductList

getProductList(param: object): Promise‹IResult

拉取道具列表

example

this.bridge.invoke('bridge', 'getProductList', {
  dramaId: '',
  vid: '',
  isTest: false
});

Parameters:

param: object

Name Type
dramaId string
isTest? boolean
vid? string

Returns: Promise‹IResult


getQRCode

getQRCode(): Promise‹IResult

获取二维码

example

const { code, msg, result } = await this.bridge.invoke('bridge', 'getQRCode');
if (code === 0) {
  // 获取成功
  console.log(result);
} else {
  // 获取失败
  console.log(msg);
}

Returns: Promise‹IResult


getRankList

getRankList(param: object): Promise‹IResult

排行榜

example

this.bridge.invoke('bridge', 'getRankList', {
  metaId: '',
  rankId: '',
  pageNum: 1,
  pageSize: 10,
})

Parameters:

param: object

Name Type
isTest? boolean
metaId string
pageNum? number
pageSize? number
rankId string

Returns: Promise‹IResult


getUserInfo

getUserInfo(): Promise‹IResult

获取用户信息

example

const { code, msg, result } = await this.bridge.invoke('bridge', 'getUserInfo');
if (code === 0) {
  // 获取用户信息成功
  console.log(result);
  // result 结构示意
  // result: {
  //     appid, // 应用appid
  //     openid, // 应用openid
  //     token, // 应用token
  //     baseInfo: {
  //       nickname, // 昵称
  //       avatar, // 头像
  //       vip, // 是否会员
  //     },
  //     type, // 登录态: qq或者wx
  // }
} else {
  // 获取用户信息失败
  console.log(msg);
}

Returns: Promise‹IResult


getVersion

getVersion(): Promise‹IResult

获取版本号

example

const { result } = await this.bridge.invoke('bridge', 'getVersion');
const {
  sdkVersion, // sdk版本
  appVersion, // app版本
  osVersion   // 操作系统版本
} = result;

Returns: Promise‹IResult


getVolume

getVolume(): Promise‹IResult

获取音量

example

const { code, msg, result } = await this.bridge.invoke('bridge', 'getVolume');
if (code === 0) {
  console.log(result.volume)
} else {
  // 获取音量失败
  console.log(msg);
}

Returns: Promise‹IResult


hideClip

hideClip(): Promise‹IResult

隐藏插播 H5 视频

Returns: Promise‹IResult


hideInteract

hideInteract(): Promise‹IResult

隐藏互动层

example

this.bridge.invoke('bridge', 'hideInteract');

Returns: Promise‹IResult


isLogin

isLogin(): Promise‹IResult

是否登录

example

const { code, msg, result } = await this.bridge.invoke('bridge', 'isLogin');
if (code === 0 && result.isLogin) {
  // 已登录
} else if (code === 0) {
  // 未登录
} else {
  // 方法在该平台不支持
}

Returns: Promise‹IResult


launch3rdApp

launch3rdApp(param: object): Promise‹IResult

拉起第三方应用

example

this.bridge.invoke('bridge', 'launch3rdApp', {
  pkgName: 'com.tencent.mm',
  pkgUrl: 'weixin://',
});

Parameters:

param: object

Name Type Description
pkgName string 应用包名
pkgUrl string 应用拉起协议url

Returns: Promise‹IResult


loadSound

loadSound(soundInfo: object | string): Promise‹IResult

加载音频

可以使用自定义的音频id,只是一个标记,用于判断当前音频是否已经加载,防止重复加载

example

// 方法一: 指定音频id的方式加载音频
const { code, msg, result } = this.bridge.invoke('bridge', 'loadSound', {
  id: '123',
  src: 'https://example.com/path/to/some.mp3',
});
if (code === 0) {
  // 加载成功
  // result.id === '123'
} else {
  // 加载失败
  console.log(result.msg)
}

// 方法二: 直接加载音频地址
const { code, msg, result } = this.bridge.invoke('bridge', 'loadSound', 'https://example.com/path/to/some.mp3');
if (code === 0) {
  // 加载成功
  // result.id 是随机的值
} else {
  console.log(result.msg)
}

Parameters:

Name Type
soundInfo object | string

Returns: Promise‹IResult


login

login(): Promise‹IResult

登录

example

const { code, msg, result } = await this.bridge.invoke('bridge', 'login');
if (code === 0) {
  // 登录成功
} else {
  // 登录失败
  console.log(msg)
}

Returns: Promise‹IResult


logout

logout(): Promise‹IResult

退出登录

example

const { code, msg, result } = await this.bridge.invoke('bridge', 'logout');
if (code === 0) {
  // 退出登录成功
} else {
  // 登出失败
  console.log(msg)
}

Returns: Promise‹IResult


off

off(event: string, callback?: Function): void

取消事件监听

Parameters:

Name Type
event string
callback? Function

Returns: void


on

on(event: string, callback: Function): void

事件监听 支持的事件参考 Events

Parameters:

Name Type
event string
callback Function

Returns: void


once

once(event: string, callback: Function): void

单次事件监听

Parameters:

Name Type
event string
callback Function

Returns: void


openCamera

openCamera(): Promise‹IResult

打开摄像头

example

const { code, msg, result } = await this.bridge.invoke('bridge', 'openCamera');
if (code === 0) {
  // 调用成功
  console.log(result);
} else {
  // 调用失败
  console.log(msg)
}

Returns: Promise‹IResult


openPayPage

openPayPage(param: object): Promise‹IResult

打开支付页面

example

this.bridge.invoke('bridge','openPayPage', {
  appid: '123',
  actid: '123',
  orderid: '123',
  needpay: 200,
  close: 1,
  sandbox: 1,
  autopay: 1
});

Parameters:

param: object

Name Type Description
actid? string 支付用到的actid
appid? string 支付需要用到的引用appid
autopay? number 是否需要进入支付页时立刻拉起支付。是: 1, 否: 2
close? number 支付完是否需要关闭支付页。是: 1, 否: 2
needpay? number 需要支付的数量
orderid? string 订单id
ru? string 支付完之后的跳转页面
sandbox? number 是否在测试环境(沙箱环境)支付。是: 1, 否: 2
title? string 支付页的标题

Returns: Promise‹IResult


openPayVipView

openPayVipView(param: object): Promise‹IResult

打开会员开通页

example

this.bridge.invoke('bridge','openPayVipView', {
  actid: '',
  nt: 'month',
  n: 1,
  sp: 1,
  ptag: 'test',
  aid: '1',
  dsp: 0,
  tab: 'vip',
  dnp: 1,
  unwx: 0,
});

Parameters:

param: object

Name Type Description
actid? string 支付用到的actid, 不传即默认显示正价套餐
aid? string 上一页面指定aid
dnp? string 隐藏普通价格套餐,1:隐藏
dsp? string 是否强制隐藏连续包月套餐。0:不隐藏,1:隐藏
n? string 默认选中的月份或天数
nt? string 默认选中的支付类型, serial:连续包月,day:按天支付,month:按月支付
ptag? string 页面ptag
sp? string 隐藏除了选中套餐之外的其余套餐,1:隐藏
tab? string 默认tab,vip:腾讯视频VIP, svip:超级影视VIP
unwx? string 屏蔽微信登录
url? string 调用接口的页面url

Returns: Promise‹IResult


openWebview

openWebview(param: object): Promise‹IResult

打开新的webview加载url

example

this.bridge.invoke('bridge','openWebview',{
  url: 'https://qq.com'
});

Parameters:

param: object

Name Type Description
close? number 是否关闭当前webview。1: 关闭, 0: 不关闭。默认:0
style? number 新开webview的样式: 0: 导航显示更多按钮, 1: 导航不显示更多按钮, 2: 关闭loading(仅android支持)。默认:0
url string 页面url

Returns: Promise‹IResult


orderGame

orderGame(param: object): Promise‹IResult

游戏预约

example

this.bridge.invoke('bridge', 'orderGame', {
  type: 'Normal', // Normal | Front | Behind
  giftId: '9605',
  gameId: '25791',
  gameName: '饥荒合辑版',
  gameIcon: 'https://inews.gtimg.com/newsapp_ls/0/5042838072/0',
});

Parameters:

param: object

Name Type
gameIcon string
gameId string
gameName string
giftId string
type string

Returns: Promise‹IResult


pay

pay(param: object): Promise‹IResult

单点支付

example

this.bridge.invoke('bridge', 'pay', {
  dramaId: '',
  productId: '',
  isTest: false
});

Parameters:

param: object

Name Type
dramaId string
isTest? boolean
productId? string

Returns: Promise‹IResult


playSound

playSound(playInfo: object): Promise‹IResult

播放音频

example

this.bridge.invoke('bridge', 'playSound', {
  id: '123',
  loop: false,
  time: 200
});

Parameters:

playInfo: object

Name Type Description
id string 音频id
loop boolean 是否循环播放
time number 从音频的第多少毫秒开始播

Returns: Promise‹IResult


redirect

redirect(url: string): Promise‹IResult

页面重定向

example

this.bridge.invoke('bridge', 'redirect', 'https://qq.com');

Parameters:

Name Type Description
url string 重定向的url

Returns: Promise‹IResult


refreshTitle

refreshTitle(param: object): Promise‹IResult

刷新标题

example

const { code, msg, result } = await this.bridge.invoke('bridge', 'refreshTitle', {
  title: 'new title',
});
if (code === 0) {
  // 刷新标题成功
} else {
  // 刷新标题失败
}

Parameters:

param: object

Name Type Description
title string 新的标题

Returns: Promise‹IResult


refreshToken

refreshToken(param: object): Promise‹IResult

刷新用户登录票据

example

const { code, msg, result } = await this.bridge.invoke('bridge', 'refreshToken');
if (code === 0) {
  // 刷新票据成功,拿到新的accesstoken
  console.log(result.accesstoken);
} else {
  // 刷新票据失败
  console.log(msg);
}

Parameters:

param: object

Name Type Description
isTest? boolean 是否后台测试环境
openId string 对应的openId

Returns: Promise‹IResult


reload

reload(isForce: boolean): Promise‹IResult

刷新主页面

example

this.bridge.invoke('bridge', 'reload', true);

Parameters:

Name Type Description
isForce boolean 是否强制刷新

Returns: Promise‹IResult


report

report(reportParam: object): Promise‹IResult

通用上报接口,用于上报用户行为数据等

example

this.bridge.invoke('bridge', 'report', {
  type: 'click',
  data: {
    id: '123'
  }
});

Parameters:

reportParam: object

Name Type Description
data? any 需要上报数据
type? string 上报类型 例如: 'click', 'expose', 'pageview' 等

Returns: Promise‹IResult


requestService

requestService(param: object): Promise‹IResult

请求后台服务接口

example

const { code, msg, result } = await this.bridge.invoke('bridge', 'requestService', {
  service: 'getUserInfo',
});

if (code === 0) {
  console.log(result)
} else {
  // 请求失败
  console.log(msg)
}

Parameters:

param: object

Name Type Description
isTest? boolean 是否测试环境的后台接口
param? any 请求后台接口的参数
service string 服务名字

Returns: Promise‹IResult


saveDataAtService

saveDataAtService(param: any): Promise‹IResult

存储接口

example

const { code, msg, result } = await this.bridge.invoke('bridge', 'saveDataAtService', {});
if (code === 0) {
  // 保存成功
  console.log(result)
} else {
  // 保存失败
  console.log(msg)
}

Parameters:

Name Type
param any

Returns: Promise‹IResult


saveImage

saveImage(param: object): Promise‹IResult

保存图片

example

this.bridge.invoke('bridge', 'saveImage', {
  url: 'https://example.com/path/to/some.png',
});

Parameters:

param: object

Name Type Description
url string 图片url,在线链接和本地链接均可

Returns: Promise‹IResult


scanQRCode

scanQRCode(): Promise‹IResult

扫描二维码获取url

xample

const { code, msg, result } = await this.bridge.invoke('bridge', 'scanQRCode');
if (code === 0) {
  console.log(result.url);
} else {
  // 扫描失败
  console.log(msg);
}

Returns: Promise‹IResult


scrollTo

scrollTo(param: object): Promise‹IResult

设置页面滚动高度

通常用于手机输入法收起时,会将当前webview撑高,导致webview底部露出,可调用此方法来还原webview位置

example

this.bridge.invoke('bridge', 'scrollTo', {
  top: 0,
  left: 0
});

Parameters:

param: object

Name Type Description
left? number 左边滚动距离
top? number 顶部滚动高度

Returns: Promise‹IResult


setBrightness

setBrightness(param: object): Promise‹IResult

设置系统亮度

example

const { code, msg, result } = await this.bridge.invoke('bridge', 'setBrightness', {
  brightness: 0.5
});
if (code === 0) {
  // 设置成功
} else {
  // 设置失败
  console.log(msg)
}

Parameters:

param: object

Name Type Description
brightness number 亮度, 取值范围[0, 1]

Returns: Promise‹IResult


setRequestedOrientation

setRequestedOrientation(param: object): Promise‹IResult

设置屏幕旋转

example

this.bridge.invoke('bridge', 'setRequestedOrientation', {
  orientation: 1
});

Parameters:

param: object

Name Type Description
orientation number 旋转方向。 0: 竖屏 ; 1: (从竖屏)逆时针旋转90度; 2: (从竖屏)顺时针旋转90

Returns: Promise‹IResult


setScreenSleep

setScreenSleep(param: object): Promise‹IResult

设置屏幕常亮,禁止休眠

example

const { code, msg, reuslt } = await this.bridge.invoke('bridge', 'setScreenSleep', {
  noSleep: true,
  isForce: false
});
if (code === 0) {
  // 设置成功
} else {
  // 设置失败
  console.log(msg)
}

Parameters:

param: object

Name Type Description
isForce? boolean 是否强制禁止休眠
noSleep boolean 是否禁止休眠

Returns: Promise‹IResult


setServerEnv

setServerEnv(param: object): Promise‹IResult

切换后台接口环境

example

const { code } = await this.bridge.invoke('bridge', 'setServerEnv', {
  isTest: true
});
if (code === 0) {
 // 切换为测试环境
}

Parameters:

param: object

Name Type Description
isPreview? boolean 是否为接口预览环境
isTest? boolean 是否为接口测试环境
session? string 预览环境接口需要额外的session凭据

Returns: Promise‹IResult


setVolume

setVolume(param: object): Promise‹IResult

设置音量

example

const { code, msg, result } = await this.bridge.invoke('bridge', 'setVolume', {
  volume: 0.5
});
if (code === 0) {
  // 设置音量成功
} else {
  // 设置失败
  console.log(msg)
}

Parameters:

param: object

Name Type Description
volume number 音量

Returns: Promise‹IResult


shakeDevice

shakeDevice(param: object): Promise‹IResult

震动设备

example

// 长震动
this.bridge.invoke('bridge', 'shakeDevice', {
  type: 'long'
});

Parameters:

param: object

Name Type Description
type string 震动类型, 短震动: 'short',长震动: 'long'

Returns: Promise‹IResult


share

share(param: object): Promise‹IResult

分享

example

this.bridge.invoke('bridge', 'share', {
  title: '分享标题',
  url: 'https://qq.com',
  imageUrl: 'https://example.com/path/to/share.png',
});

Parameters:

param: object

Name Type Description
imageUrl string 分享图标
pcShareImageHeight? string PC端分享图片的高度
pcShareImageUrl? string PC端分享图片url
pcShareImageWidth? string PC端分享图片的宽度
sharePageLaunchUrl? string 分享页拉起APP的url
sharePageTitle? string -
subTitle? string 副标题
title string 标题
url string 分享链接

Returns: Promise‹IResult


shareImage

shareImage(param: object): Promise‹IResult

分享图片

example

this.bridge.invoke('bridge', 'shareImage', {
  imageUrl: 'https://example.com/path/to/share.png',
});

Parameters:

param: object

Name Type Description
imageUrl? string 在线图片链接
localImageUrl? string 本地图片链接
needPreview? boolean 是否需要预览
subTitle? string 子标题
title? string 标题

Returns: Promise‹IResult


showClip

showClip(param: object): Promise‹IResult

展示插播 H5 视频

example

this.bridge.invoke('bridge', 'showClip', {
  vid: 'e093980z464',
  x: 0,
  y: 0,
  width: 100,
  height: 100,
  hideCloseBtn: false // 是否隐藏右上角关闭按钮,默认为false
})

Parameters:

param: object

Name Type
height number
hideCloseBtn? boolean
vid string
width number
x number
y number

Returns: Promise‹IResult


showInteract

showInteract(forceShow?: boolean): Promise‹IResult

展示互动层

example

this.bridge.innvoke('bridge', 'showInteract');

Parameters:

Name Type
forceShow? boolean

Returns: Promise‹IResult


stopSound

stopSound(id: string): Promise‹IResult

停止音频播放

example

this.bridge.invoke('bridge', 'stopSound', id);

Parameters:

Name Type Description
id string 音频id

Returns: Promise‹IResult


toast

toast(content: string): Promise‹IResult

弹出提示

example

this.bridge.invoke('bridge', 'toast', {
  content: 'test'
});

Parameters:

Name Type Description
content string 显示内容

Returns: Promise‹IResult


toggleBackButton

toggleBackButton(param: object): Promise‹IResult

隐藏/显示左上角系统返回按钮

example

this.bridge.invoke('bridge', 'toggleBackButton', {
  hide: true
});

Parameters:

param: object

Name Type Description
hide boolean 是否隐藏。 隐藏: true, 显示: false

Returns: Promise‹IResult


writeLog

writeLog(param: object): Promise‹IResult

写本地日志

example

this.bridge.invoke('bridge', 'writeLog', {
  content: 'log',
  isReportServer: false,
  isConsoleLog: true
});

Parameters:

param: object

Name Type Description
content string 日志内容
isConsoleLog? boolean -
isReportServer? boolean 日志内容是否上报到服务端

Returns: Promise‹IResult