小程序API能力汇总——基础容器API(一)

ty.getEnterOptions

获取本次小程序启动时的参数。如果当前是冷启动,则返回值与 App.onLaunch 的回调参数一致;如果当前是热启动,则返回值与 App.onShow 一致。

需引入MiniKit,且在>=2.0.0版本才可使用

参数

Object object

属性类型默认值必填说明
completefunction接口调用结束的回调函数(调用成功、失败都会执行)
successfunction接口调用成功的回调函数
failfunction接口调用失败的回调函数

object.success 回调参数

参数

Object res

属性类型说明
pathstring启动小程序的路径 (代码包路径)
queryobject启动小程序的 query 参数
referrerInfoReferrerInfo分享转发
apiCategorystringAPI 类别: default 默认类别; embedded 内嵌,通过打开半屏小程序能力打开的小程序

object.fail 回调参数

参数

Object res

属性类型说明
errorMsgstring插件错误信息
errorCodestring错误码
innerErrorobject插件外部依赖错误信息 {errorMsg: string, errorCode: string }

函数定义示例

/*** 获取本次小程序启动时的参数。如果当前是冷启动,则返回值与App.onLaunch的回调参数一致;如果当前是热启动,则返回值与App.onShow 一致。*/
export function getEnterOptions(params?: {complete?: () => void;success?: (params: {/** 启动小程序的路径 (代码包路径) */path: string;/** 启动小程序的 query 参数 */query: Record<string, any>;/** 分享转发 */referrerInfo: ReferrerInfo;/** API 类别: default	默认类别; embedded 内嵌,通过打开半屏小程序能力打开的小程序 */apiCategory?: string;}) => void;fail?: (params: {errorMsg: string;errorCode: string | number;innerError: {errorCode: string | number;errorMsg: string;};}) => void;
}): void;

 

ty.getEnterOptionsSync

获取本次小程序启动时的参数。如果当前是冷启动,则返回值与 App.onLaunch 的回调参数一致;如果当前是热启动,则返回值与 App.onShow 一致。同步方法

需引入MiniKit,且在>=2.0.0版本才可使用

ty.getEnterOptions 的同步版本

返回值

属性类型说明
pathstring启动小程序的路径 (代码包路径)
queryobject启动小程序的 query 参数
referrerInfoReferrerInfo分享转发
apiCategorystringAPI 类别: default 默认类别; embedded 内嵌,通过打开半屏小程序能力打开的小程序

函数定义示例

/*** 获取本次小程序启动时的参数。如果当前是冷启动,则返回值与App.onLaunch的回调参数一致;如果当前是热启动,则返回值与App.onShow 一致。*/
export function getEnterOptionsSync(): {/** 启动小程序的路径 (代码包路径) */path: string;/** 启动小程序的 query 参数 */query: Record<string, any>;/** 分享转发 */referrerInfo: ReferrerInfo;/** API 类别: default	默认类别; embedded 内嵌,通过打开半屏小程序能力打开的小程序 */apiCategory?: string;
};

 

ty.getLaunchOptions

获取小程序启动时的参数。与 App.onLaunch 的回调参数一致。

需引入MiniKit,且在>=2.0.0版本才可使用

参数

Object object

属性类型默认值必填说明
completefunction接口调用结束的回调函数(调用成功、失败都会执行)
successfunction接口调用成功的回调函数
failfunction接口调用失败的回调函数

object.success 回调参数

参数

Object res

属性类型说明
pathstring启动小程序的路径 (代码包路径)
queryobject启动小程序的 query 参数
referrerInfoReferrerInfo分享转发
apiCategorystringAPI 类别: default 默认类别; embedded 内嵌,通过打开半屏小程序能力打开的小程序

object.fail 回调参数

参数

Object res

属性类型说明
errorMsgstring插件错误信息
errorCodestring错误码
innerErrorobject插件外部依赖错误信息 {errorMsg: string, errorCode: string }

函数定义示例

/*** 获取小程序启动时的参数。与App.onLaunch的回调参数一致。*/
export function getLaunchOptions(params?: {complete?: () => void;success?: (params: {/** 启动小程序的路径 (代码包路径) */path: string;/** 启动小程序的 query 参数 */query: Record<string, any>;/** 分享转发 */referrerInfo: ReferrerInfo;/** API 类别: default	默认类别; embedded 内嵌,通过打开半屏小程序能力打开的小程序 */apiCategory?: string;}) => void;fail?: (params: {errorMsg: string;errorCode: string | number;innerError: {errorCode: string | number;errorMsg: string;};}) => void;
}): void;

 

ty.getLaunchOptionsSync

获取小程序启动时的参数。与 App.onLaunch 的回调参数一致。同步方法

需引入MiniKit,且在>=2.0.0版本才可使用

ty.getLaunchOptions 的同步版本

返回值

属性类型说明
pathstring启动小程序的路径 (代码包路径)
queryobject启动小程序的 query 参数
referrerInfoReferrerInfo分享转发
apiCategorystringAPI 类别: default 默认类别; embedded 内嵌,通过打开半屏小程序能力打开的小程序

函数定义示例

/*** 获取小程序启动时的参数。与App.onLaunch的回调参数一致。*/
export function getLaunchOptionsSync(): {/** 启动小程序的路径 (代码包路径) */path: string;/** 启动小程序的 query 参数 */query: Record<string, any>;/** 分享转发 */referrerInfo: ReferrerInfo;/** API 类别: default	默认类别; embedded 内嵌,通过打开半屏小程序能力打开的小程序 */apiCategory?: string;
};

 

ty.getAppInfo

拿到当前 App 的业务信息

需引入BizKit,且在>=3.0.0版本才可使用

参数

Object object

属性类型默认值必填说明
completefunction接口调用结束的回调函数(调用成功、失败都会执行)
successfunction接口调用成功的回调函数
failfunction接口调用失败的回调函数

object.success 回调参数

参数

Object res

属性类型说明
serverTimestampnumber云端时间戳
appVersionstringapp 版本
languagestring语言
countryCodestring国家码
regionCodestring地区码
appNamestringappName app 名称
appIconstringappIcon app 图标
appEnvnumberapp 环境 0: 日常 1: 预发 2: 线上
appBundleIdstringapp 包名
appSchemestringapp scheme

object.fail 回调参数

参数

Object res

属性类型说明
errorMsgstring插件错误信息
errorCodestring错误码
innerErrorobject插件外部依赖错误信息 {errorMsg: string, errorCode: string }

 

ty.getAppInfo

拿到当前 App 的业务信息

需引入BizKit,且在>=3.0.0版本才可使用

参数

Object object

属性类型默认值必填说明
completefunction接口调用结束的回调函数(调用成功、失败都会执行)
successfunction接口调用成功的回调函数
failfunction接口调用失败的回调函数

object.success 回调参数

参数

Object res

属性类型说明
serverTimestampnumber云端时间戳
appVersionstringapp 版本
languagestring语言
countryCodestring国家码
regionCodestring地区码
appNamestringappName app 名称
appIconstringappIcon app 图标
appEnvnumberapp 环境 0: 日常 1: 预发 2: 线上
appBundleIdstringapp 包名
appSchemestringapp scheme

object.fail 回调参数

参数

Object res

属性类型说明
errorMsgstring插件错误信息
errorCodestring错误码
innerErrorobject插件外部依赖错误信息 {errorMsg: string, errorCode: string }

 

ty.getTempDirectory

获取通用缓存路径

需引入BaseKit,且在>=2.2.3版本才可使用

参数

Object object

属性类型默认值必填说明
completefunction接口调用结束的回调函数(调用成功、失败都会执行)
successfunction接口调用成功的回调函数
failfunction接口调用失败的回调函数

object.success 回调参数

参数

Object res

属性类型说明
tempDirectorystring【待废弃, 不建议使用】临时文件夹路径

object.fail 回调参数

参数

Object res

属性类型说明
errorMsgstring插件错误信息
errorCodestring错误码
innerErrorobject插件外部依赖错误信息 {errorMsg: string, errorCode: string }

函数定义示例

/*** 获取通用缓存路径*/
export function getTempDirectory(params?: {complete?: () => void;success?: (params: {/** 【待废弃, 不建议使用】临时文件夹路径 */tempDirectory: string;}) => void;fail?: (params: {errorMsg: string;errorCode: string | number;innerError: {errorCode: string | number;errorMsg: string;};}) => void;
}): void;

 

ty.getMenuButtonBoundingClientRect

获取菜单按钮(右上角胶囊按钮)的布局位置信息。坐标信息以屏幕左上角为原点。

需引入MiniKit,且在>=2.3.0版本才可使用

参数

Object object

属性类型默认值必填说明
completefunction接口调用结束的回调函数(调用成功、失败都会执行)
successfunction接口调用成功的回调函数
failfunction接口调用失败的回调函数

object.success 回调参数

参数

Object res

属性类型说明
widthnumber宽度,单位:px
heightnumber高度,单位:px
topnumber上边界坐标,单位:px
rightnumber右边界坐标,单位:px
bottomnumber下边界坐标,单位:px
leftnumber左边界坐标,单位:px

object.fail 回调参数

参数

Object res

属性类型说明
errorMsgstring插件错误信息
errorCodestring错误码
innerErrorobject插件外部依赖错误信息 {errorMsg: string, errorCode: string }

函数定义示例

/*** 获取菜单按钮(右上角胶囊按钮)的布局位置信息。坐标信息以屏幕左上角为原点。*/
export function getMenuButtonBoundingClientRect(params?: {complete?: () => void;success?: (params: {/** 宽度,单位:px */width: number;/** 高度,单位:px */height: number;/** 上边界坐标,单位:px */top: number;/** 右边界坐标,单位:px */right: number;/** 下边界坐标,单位:px */bottom: number;/** 左边界坐标,单位:px */left: number;}) => void;fail?: (params: {errorMsg: string;errorCode: string | number;innerError: {errorCode: string | number;errorMsg: string;};}) => void;
}): void;

ty.getMenuButtonBoundingClientRectSync

获取菜单按钮(右上角胶囊按钮)的布局位置信息。坐标信息以屏幕左上角为原点。同步方法

需引入MiniKit,且在>=2.3.0版本才可使用

ty.getMenuButtonBoundingClientRect 的同步版本

返回值

属性类型说明
widthnumber宽度,单位:px
heightnumber高度,单位:px
topnumber上边界坐标,单位:px
rightnumber右边界坐标,单位:px
bottomnumber下边界坐标,单位:px
leftnumber左边界坐标,单位:px

函数定义示例

/*** 获取菜单按钮(右上角胶囊按钮)的布局位置信息。坐标信息以屏幕左上角为原点。*/
export function getMenuButtonBoundingClientRectSync(): {/** 宽度,单位:px */width: number;/** 高度,单位:px */height: number;/** 上边界坐标,单位:px */top: number;/** 右边界坐标,单位:px */right: number;/** 下边界坐标,单位:px */bottom: number;/** 左边界坐标,单位:px */left: number;
};

👉 立即开发。