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

ty.getEnterOptions

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

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

参数

Object object

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

object.success 回调参数

参数

Object res

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

object.fail 回调参数

参数

Object res

属性 类型 说明
errorMsg string 插件错误信息
errorCode string 错误码
innerError object 插件外部依赖错误信息 {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 的同步版本

返回值

属性 类型 说明
path string 启动小程序的路径 (代码包路径)
query object 启动小程序的 query 参数
referrerInfo ReferrerInfo 分享转发
apiCategory string API 类别: 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

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

object.success 回调参数

参数

Object res

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

object.fail 回调参数

参数

Object res

属性 类型 说明
errorMsg string 插件错误信息
errorCode string 错误码
innerError object 插件外部依赖错误信息 {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 的同步版本

返回值

属性 类型 说明
path string 启动小程序的路径 (代码包路径)
query object 启动小程序的 query 参数
referrerInfo ReferrerInfo 分享转发
apiCategory string API 类别: 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

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

object.success 回调参数

参数

Object res

属性 类型 说明
serverTimestamp number 云端时间戳
appVersion string app 版本
language string 语言
countryCode string 国家码
regionCode string 地区码
appName string appName app 名称
appIcon string appIcon app 图标
appEnv number app 环境 0: 日常 1: 预发 2: 线上
appBundleId string app 包名
appScheme string app scheme

object.fail 回调参数

参数

Object res

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

ty.getAppInfo

拿到当前 App 的业务信息

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

参数

Object object

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

object.success 回调参数

参数

Object res

属性 类型 说明
serverTimestamp number 云端时间戳
appVersion string app 版本
language string 语言
countryCode string 国家码
regionCode string 地区码
appName string appName app 名称
appIcon string appIcon app 图标
appEnv number app 环境 0: 日常 1: 预发 2: 线上
appBundleId string app 包名
appScheme string app scheme

object.fail 回调参数

参数

Object res

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

ty.getTempDirectory

获取通用缓存路径

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

参数

Object object

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

object.success 回调参数

参数

Object res

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

object.fail 回调参数

参数

Object res

属性 类型 说明
errorMsg string 插件错误信息
errorCode string 错误码
innerError object 插件外部依赖错误信息 {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

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

object.success 回调参数

参数

Object res

属性 类型 说明
width number 宽度,单位:px
height number 高度,单位:px
top number 上边界坐标,单位:px
right number 右边界坐标,单位:px
bottom number 下边界坐标,单位:px
left number 左边界坐标,单位:px

object.fail 回调参数

参数

Object res

属性 类型 说明
errorMsg string 插件错误信息
errorCode string 错误码
innerError object 插件外部依赖错误信息 {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 的同步版本

返回值

属性 类型 说明
width number 宽度,单位:px
height number 高度,单位:px
top number 上边界坐标,单位:px
right number 右边界坐标,单位:px
bottom number 下边界坐标,单位:px
left number 左边界坐标,单位:px

函数定义示例

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

👉 立即开发

相关推荐
今阳2 小时前
鸿蒙开发笔记-6-装饰器之@Require装饰器,@Reusable装饰器
android·app·harmonyos
從南走到北4 小时前
挪车小程序挪车二维码php+uniapp
微信小程序·小程序·开源·微信公众平台
黑云压城After4 小时前
uniapp小程序自定义日历(签到、补签功能)
小程序·uni-app
黑云压城After5 小时前
小程序(物流、快递),接入GPS北斗获取路线以及当前车辆位置
小程序
零星_AagT5 小时前
Apache-CC6链审计笔记
java·笔记·apache·代码审计
万岳科技程序员小金6 小时前
互联网医院系统源码解析:如何开发智能化的电子处方小程序?
小程序·app开发·互联网医院系统源码·智慧医疗小程序·医院app
Java Fans7 小时前
微信小程序——访问服务器媒体文件的实现步骤
服务器·微信小程序·小程序
Evaporator Core10 小时前
微信小程序数据绑定与事件处理:打造动态交互体验
微信小程序·小程序·交互
家里有只小肥猫1 天前
uniApp小程序保存canvas图片
前端·小程序·uni-app
低代码布道师1 天前
性格测评小程序10生成报告
低代码·小程序