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

ty.preDownloadMiniApp

预下载智能小程序,此接口仅供提供预下载普通智能小程序调用,面板小程序的预下载需要使用另外的接口。

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

参数

Object object

属性 类型 默认值 必填 说明
miniAppId string 小程序 id
miniAppVersion string 指定小程序版本(可选参数)
complete function 接口调用结束的回调函数(调用成功、失败都会执行)
success function 接口调用成功的回调函数
fail function 接口调用失败的回调函数

函数定义示例

复制代码
/**
 * 预下载智能小程序,此接口仅供提供预下载普通智能小程序调用,面板小程序的预下载需要使用另外的接口。
 */
export function preDownloadMiniApp(params: {
  /** 小程序id */
  miniAppId: string;
  /** 指定小程序版本(可选参数) */
  miniAppVersion?: string;
  complete?: () => void;
  success?: (params: null) => void;
  fail?: (params: {
    errorMsg: string;
    errorCode: string | number;
    innerError: {
      errorCode: string | number;
      errorMsg: string;
    };
  }) => void;
}): void;

ty.showMenuButton

显示右上角胶囊按钮

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

参数

Object object

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

函数定义示例

复制代码
/**
 * 显示右上角胶囊按钮
 */
export function showMenuButton(params?: {
  complete?: () => void;
  success?: (params: null) => void;
  fail?: (params: {
    errorMsg: string;
    errorCode: string | number;
    innerError: {
      errorCode: string | number;
      errorMsg: string;
    };
  }) => void;
}): void;

ty.hideMenuButton

隐藏右上角胶囊按钮

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

参数

Object object

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

函数定义示例

复制代码
/**
 * 隐藏右上角胶囊按钮
 */
export function hideMenuButton(params?: {
  complete?: () => void;
  success?: (params: null) => void;
  fail?: (params: {
    errorMsg: string;
    errorCode: string | number;
    innerError: {
      errorCode: string | number;
      errorMsg: string;
    };
  }) => void;
}): void;

ty.setPageOrientation

屏幕旋转设置,auto / portrait / landscape。pad 模式下不支持屏幕旋转

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

参数

Object object

属性 类型 默认值 必填 说明
pageOrientation string 屏幕旋转设置, auto(暂不支持) / portrait / landscape
complete function 接口调用结束的回调函数(调用成功、失败都会执行)
success function 接口调用成功的回调函数
fail function 接口调用失败的回调函数

函数定义示例

复制代码
/**
 * 屏幕旋转设置,auto / portrait / landscape。pad模式下不支持屏幕旋转
 */
export function setPageOrientation(params: {
  /** 屏幕旋转设置, auto(暂不支持) / portrait / landscape */
  pageOrientation: string;
  complete?: () => void;
  success?: (params: null) => void;
  fail?: (params: {
    errorMsg: string;
    errorCode: string | number;
    innerError: {
      errorCode: string | number;
      errorMsg: string;
    };
  }) => void;
}): void;

MiniWidgetDialogTask ty.openMiniWidget

用来控制小部件弹窗显示和关闭

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

参数

Object object

打开小部件弹窗的回调函数

回调参数 Object res

属性 类型 默认值 必填 说明
appId string 要打开的小部件 appid
pagePath string 对应的小部件页面相对 URL,如果为空则打开首页 path 中 ? 后面的部分会成为 query
deviceId string 面板类型设备 id
groupId string 面板群组类型群组 id
style string 小部件样式,默认 middle
versionType WidgetVersionType 版本类型,默认 release
version string 版本号
position WidgetPosition 展示位置,默认 bottom
autoDismiss boolean 点击空白处是否关闭
autoCache boolean 是否优先展示默认缓存,对应属性在小程序容器 3.1.0 生效
supportDark boolean 是否支持深色模式
complete function 接口调用结束的回调函数(调用成功、失败都会执行)
success function 接口调用成功的回调函数
fail function 接口调用失败的回调函数

object.fail 回调参数

参数

Object res

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

返回值

MiniWidgetDialogTask 用来控制小部件弹窗显示和关闭

函数定义示例

复制代码
/**
 * 用来控制小部件弹窗显示和关闭
 */
interface MiniWidgetDialogTask {
  /**
   * 关闭小部件弹窗
   */
  dismissMiniWidget(params: {
    complete?: () => void;
    success?: (params: null) => void;
    fail?: (params: {
      errorMsg: string;
      errorCode: string | number;
      innerError: {
        errorCode: string | number;
        errorMsg: string;
      };
    }) => void;
  }): void;
 
  /**
   * 监听 widget 关闭事件
   */
  onWidgetDismiss(
    listener: (params: {
      /** widget 弹窗 ID */
      dialogId: string;
    }) => void,
  ): void;
 
  /**
   * 取消监听 widget 关闭事件
   */
  offWidgetDismiss(
    listener: (params: {
      /** widget 弹窗 ID */
      dialogId: string;
    }) => void,
  ): void;
}
export function openMiniWidget(params: {
  /** 要打开的小部件 appid */
  appId: string;
  /** 对应的小部件页面相对 URL,如果为空则打开首页 path 中 ? 后面的部分会成为 query */
  pagePath?: string;
  /** 面板类型设备 ID */
  deviceId?: string;
  /** 面板群组类型群组 ID */
  groupId?: string;
  /** 小部件样式,默认 middle */
  style?: string;
  /** 版本类型,默认 release */
  versionType?: WidgetVersionType;
  /** 版本号 */
  version?: string;
  /** 展示位置,默认 bottom */
  position?: WidgetPosition;
  /** 点击空白处是否关闭 */
  autoDismiss?: boolean;
  /**
   * 是否优先展示默认缓存
   * 对应属性在小程序容器 3.1.0 生效
   */
  autoCache?: boolean;
  /** 是否支持深色模式 */
  supportDark?: boolean;
  complete?: () => void;
  success?: (params: null) => void;
  fail?: (params: {
    errorMsg: string;
    errorCode: string | number;
    innerError: {
      errorCode: string | number;
      errorMsg: string;
    };
  }) => void;
}): MiniWidgetDialogTask;

MiniWidgetDialogTask

MiniWidgetDialogTask.dismissMiniWidget

关闭小部件弹窗

参数

Object object

关闭小部件弹窗的回调函数

回调参数 Object res

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

函数定义示例

复制代码
/**
 * 关闭小部件弹窗
 */
export function dismissMiniWidget(params: {
  /** 接口调用结束的回调函数(调用成功、失败都会执行) */
  complete?: () => void;
  /** 接口调用成功的回调函数 */
  success?: (params: null) => void;
  /** 接口调用失败的回调函数 */
  fail?: (params: {
    errorMsg: string;
    errorCode: string | number;
    innerError: {
      errorCode: string | number;
      errorMsg: string;
    };
  }) => void;
}): void;

MiniWidgetDialogTask.onWidgetDismiss

监听 widget 关闭事件

参数

function callback

监听 widget 关闭事件的回调函数

回调参数 Object res

属性 类型 默认值 必填 说明
dialogId string widget 弹窗 ID

MiniWidgetDialogTask.offWidgetDismiss

取消监听 widget 关闭事件

参数

function callback

取消监听 widget 关闭事件的回调函数

回调参数 Object res

属性 类型 默认值 必填 说明
dialogId string widget 弹窗 ID

👉 立即开发

相关推荐
夏梦春蝉11 分钟前
ES6从入门到精通:其他特性
前端·javascript·es6
2301_14725836917 分钟前
7月1日作业
java·前端·算法
汪子熙19 分钟前
Angular 应用中手动调用 subscribe 方法的时机与实践探讨
前端
csdn_aspnet27 分钟前
在 React 中使用 WebSockets 构建实时聊天应用程序
javascript·react.js·node.js
mg6681 小时前
微信小程序入门实例_____打造你的专属单词速记小程序
微信小程序·小程序
【ql君】qlexcel1 小时前
Notepad++ 复制宏、编辑宏的方法
开发语言·javascript·notepad++··宏编辑·宏复制
MiyueFE1 小时前
14 个逻辑驱动的 UI 设计技巧,助您改善任何界面
前端·设计
啃火龙果的兔子1 小时前
前端单元测试覆盖率工具有哪些,分别有什么优缺点
前端·单元测试
程序员陆通1 小时前
Vibe Coding开发微信小程序实战案例
微信小程序·小程序·notepad++·ai编程
「、皓子~1 小时前
后台管理系统的诞生 - 利用AI 1天完成整个后台管理系统的微服务后端+前端
前端·人工智能·微服务·小程序·go·ai编程·ai写作