小程序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

👉 立即开发

相关推荐
excel5 分钟前
Vue 工具函数源码解析:URL 解析与分类逻辑详解
前端
excel8 分钟前
Vue SFC 样式预处理器(Style Preprocessor)源码解析
前端
excel9 分钟前
深度解析:Vue Scoped 样式编译原理 —— vue-sfc-scoped 插件源码详解
前端
excel11 分钟前
Vue SFC Trim 插件源码解析:自动清理多余空白的 PostCSS 实现
前端
excel15 分钟前
Vue SFC 样式变量机制源码深度解析:cssVarsPlugin 与编译流程
前端
excel17 分钟前
🧩 Vue 编译工具中的实用函数模块解析
前端
excel21 分钟前
🧩 深入剖析 Vue 编译器中的 TypeScript 类型系统(第五篇)
前端
excel27 分钟前
🧩 深入剖析 Vue 编译器中的 TypeScript 类型系统(第六篇 · 终篇)
前端
不吃香菜的猪30 分钟前
el-upload实现文件上传预览
前端·javascript·vue.js
excel35 分钟前
🧩 深入剖析 Vue 编译器中的 TypeScript 类型系统(第四篇)
前端