miniprogram-api-typings
Version:
Type definitions for APIs of Wechat Mini Program in TypeScript
1,405 lines (1,397 loc) • 1.51 MB
TypeScript
/*! *****************************************************************************
Copyright (c) 2025 Tencent, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
***************************************************************************** */
/// <reference path="./lib.wx.xr-frame.d.ts" />
declare namespace WechatMiniprogram {
interface AccessOption {
/** 要判断是否存在的文件/目录路径 (本地路径) */
path: string
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
complete?: AccessCompleteCallback
/** 接口调用失败的回调函数 */
fail?: AccessFailCallback
/** 接口调用成功的回调函数 */
success?: AccessSuccessCallback
}
/** 账号信息 */
interface AccountInfo {
/** 小程序账号信息 */
miniProgram: MiniProgram
/** 插件账号信息(仅在插件中调用时包含这一项) */
plugin: Plugin
}
interface AddArcOption {
/** 终点 */
end: MapPostion
/** 圆弧 id */
id: number
/** 起始点 */
start: MapPostion
/** 夹角角度 */
angle?: number
/** 线的颜色 */
color?: number
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
complete?: AddArcCompleteCallback
/** 接口调用失败的回调函数 */
fail?: AddArcFailCallback
/** 途经点 */
pass?: MapPostion
/** 接口调用成功的回调函数 */
success?: AddArcSuccessCallback
/** 线宽 */
width?: number
}
interface AddCardOption {
/** 需要添加的卡券列表 */
cardList: AddCardRequestInfo[]
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
complete?: AddCardCompleteCallback
/** 接口调用失败的回调函数 */
fail?: AddCardFailCallback
/** 接口调用成功的回调函数 */
success?: AddCardSuccessCallback
}
/** 需要添加的卡券列表 */
interface AddCardRequestInfo {
/** 卡券的扩展参数。需将 CardExt 对象 JSON 序列化为**字符串**传入 */
cardExt: string
/** 卡券 ID */
cardId: string
}
/** 卡券添加结果列表 */
interface AddCardResponseInfo {
/** 卡券的扩展参数,结构请参考下文 */
cardExt: string
/** 用户领取到卡券的 ID */
cardId: string
/** 加密 code,为用户领取到卡券的code加密后的字符串,解密请参照:[code 解码接口](https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1499332673_Unm7V) */
code: string
/** 是否成功 */
isSuccess: boolean
}
interface AddCardSuccessCallbackResult {
/** 卡券添加结果列表 */
cardList: AddCardResponseInfo[]
errMsg: string
}
interface AddCustomLayerOption {
/** 个性化图层id */
layerId: string
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
complete?: AddCustomLayerCompleteCallback
/** 接口调用失败的回调函数 */
fail?: AddCustomLayerFailCallback
/** 接口调用成功的回调函数 */
success?: AddCustomLayerSuccessCallback
}
interface AddFileToFavoritesOption {
/** 要收藏的文件地址,必须为本地路径或临时路径 */
filePath: string
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
complete?: AddFileToFavoritesCompleteCallback
/** 接口调用失败的回调函数 */
fail?: AddFileToFavoritesFailCallback
/** 自定义文件名,若留空则使用filePath中的文件名 */
fileName?: string
/** 接口调用成功的回调函数 */
success?: AddFileToFavoritesSuccessCallback
}
interface AddGroundOverlayOption {
/** 图片覆盖的经纬度范围 */
bounds: MapBounds
/** 图片图层 id */
id: string
/** 图片路径,支持网络图片、临时路径、代码包路径 */
src: string
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
complete?: AddGroundOverlayCompleteCallback
/** 接口调用失败的回调函数 */
fail?: AddGroundOverlayFailCallback
/** 图层透明度 */
opacity?: number
/** 接口调用成功的回调函数 */
success?: AddGroundOverlaySuccessCallback
/** 是否可见 */
visible?: boolean
/** 图层绘制顺序 */
zIndex?: number
}
interface AddMarkersOption {
/** 同传入 map 组件的 marker 属性 */
markers: any[]
/** 是否先清空地图上所有 marker */
clear?: boolean
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
complete?: AddMarkersCompleteCallback
/** 接口调用失败的回调函数 */
fail?: AddMarkersFailCallback
/** 接口调用成功的回调函数 */
success?: AddMarkersSuccessCallback
}
interface AddPhoneCalendarOption {
/** 开始时间的 unix 时间戳 */
startTime: number
/** 日历事件标题 */
title: string
/** 是否提醒,默认 true */
alarm?: boolean
/** 提醒提前量,单位秒,默认 0 表示开始时提醒 */
alarmOffset?: number
/** 是否全天事件,默认 false */
allDay?: boolean
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
complete?: AddPhoneCalendarCompleteCallback
/** 事件说明 */
description?: string
/** 结束时间的 unix 时间戳,默认与开始时间相同 */
endTime?: string
/** 接口调用失败的回调函数 */
fail?: AddPhoneCalendarFailCallback
/** 事件位置 */
location?: string
/** 需要基础库: `3.7.6`
*
* 跳转小程序路径,必须要和 signature 一起使用,填入后会自动生成跳转链接拼接在事件说明中 */
path?: string
/** 需要基础库: `3.7.6`
*
* 跳转小程序路径签名,必须要和 path 一起使用,用 session_key 对 path 签名得到的结果,即 `hmac_sha256(session_key, path)`。详见 [用户数据的签名验证和加解密](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/signature.html) */
signature?: string
/** 接口调用成功的回调函数 */
success?: AddPhoneCalendarSuccessCallback
}
interface AddPhoneContactOption {
/** 名字 */
firstName: string
/** 联系地址城市 */
addressCity?: string
/** 联系地址国家 */
addressCountry?: string
/** 联系地址邮政编码 */
addressPostalCode?: string
/** 联系地址省份 */
addressState?: string
/** 联系地址街道 */
addressStreet?: string
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
complete?: AddPhoneContactCompleteCallback
/** 电子邮件 */
email?: string
/** 接口调用失败的回调函数 */
fail?: AddPhoneContactFailCallback
/** 住宅地址城市 */
homeAddressCity?: string
/** 住宅地址国家 */
homeAddressCountry?: string
/** 住宅地址邮政编码 */
homeAddressPostalCode?: string
/** 住宅地址省份 */
homeAddressState?: string
/** 住宅地址街道 */
homeAddressStreet?: string
/** 住宅传真 */
homeFaxNumber?: string
/** 住宅电话 */
homePhoneNumber?: string
/** 公司电话 */
hostNumber?: string
/** 姓氏 */
lastName?: string
/** 中间名 */
middleName?: string
/** 手机号 */
mobilePhoneNumber?: string
/** 昵称 */
nickName?: string
/** 公司 */
organization?: string
/** 头像本地文件路径 */
photoFilePath?: string
/** 备注 */
remark?: string
/** 接口调用成功的回调函数 */
success?: AddPhoneContactSuccessCallback
/** 职位 */
title?: string
/** 网站 */
url?: string
/** 微信号 */
weChatNumber?: string
/** 工作地址城市 */
workAddressCity?: string
/** 工作地址国家 */
workAddressCountry?: string
/** 工作地址邮政编码 */
workAddressPostalCode?: string
/** 工作地址省份 */
workAddressState?: string
/** 工作地址街道 */
workAddressStreet?: string
/** 工作传真 */
workFaxNumber?: string
/** 工作电话 */
workPhoneNumber?: string
}
interface AddPhoneRepeatCalendarOption {
/** 开始时间的 unix 时间戳 (1970年1月1日开始所经过的秒数) */
startTime: number
/** 日历事件标题 */
title: string
/** 是否提醒,默认 true */
alarm?: boolean
/** 提醒提前量,单位秒,默认 0 表示开始时提醒 */
alarmOffset?: number
/** 是否全天事件,默认 false */
allDay?: boolean
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
complete?: AddPhoneRepeatCalendarCompleteCallback
/** 事件说明 */
description?: string
/** 结束时间的 unix 时间戳,默认与开始时间相同 */
endTime?: string
/** 接口调用失败的回调函数 */
fail?: AddPhoneRepeatCalendarFailCallback
/** 事件位置 */
location?: string
/** 需要基础库: `3.7.6`
*
* 跳转小程序路径,必须要和 signature 一起使用,填入后会自动生成跳转链接拼接在事件说明中 */
path?: string
/** 重复周期结束时间的 unix 时间戳,不填表示一直重复 */
repeatEndTime?: number
/** 重复周期,默认 month 每月重复
*
* 可选值:
* - 'day': 每天重复;
* - 'week': 每周重复;
* - 'month': 每月重复。该模式日期不能大于 28 日;
* - 'year': 每年重复; */
repeatInterval?: 'day' | 'week' | 'month' | 'year'
/** 需要基础库: `3.7.6`
*
* 跳转小程序路径签名,必须要和 path 一起使用,用 session_key 对 path 签名得到的结果,即 `hmac_sha256(session_key, path)`。详见 [用户数据的签名验证和加解密](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/signature.html) */
signature?: string
/** 接口调用成功的回调函数 */
success?: AddPhoneRepeatCalendarSuccessCallback
}
interface AddServiceOption {
/** 描述service的Object */
service: BLEPeripheralService
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
complete?: AddServiceCompleteCallback
/** 接口调用失败的回调函数 */
fail?: AddServiceFailCallback
/** 接口调用成功的回调函数 */
success?: AddServiceSuccessCallback
}
interface AddVideoToFavoritesOption {
/** 要收藏的视频地址,必须为本地路径或临时路径 */
videoPath: string
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
complete?: AddVideoToFavoritesCompleteCallback
/** 接口调用失败的回调函数 */
fail?: AddVideoToFavoritesFailCallback
/** 接口调用成功的回调函数 */
success?: AddVideoToFavoritesSuccessCallback
/** 缩略图路径,若留空则使用视频首帧 */
thumbPath?: string
}
interface AddVisualLayerOption {
/** 可视化图层id([创建图层指引](https://lbs.qq.com/dev/console/layers/layerEdit)) */
layerId: string
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
complete?: AddVisualLayerCompleteCallback
/** 接口调用失败的回调函数 */
fail?: AddVisualLayerFailCallback
/** 刷新周期,单位秒 */
interval?: number
/** 图层透明度 */
opacity?: number
/** 接口调用成功的回调函数 */
success?: AddVisualLayerSuccessCallback
/** 图层绘制顺序 */
zIndex?: number
}
/** 广播自定义参数 */
interface AdvertiseReqObj {
/** 需要基础库: `2.20.1`
*
* 以 beacon 设备形式广播的参数。 */
beacon?: BeaconInfoObj
/** 当前设备是否可连接 */
connectable?: boolean
/** 广播中 deviceName 字段,默认为空 */
deviceName?: string
/** 广播的制造商信息。仅安卓支持,iOS 因系统限制无法定制。 */
manufacturerData?: ManufacturerData[]
/** 要广播的服务 UUID 列表。使用 16/32 位 UUID 时请参考注意事项。 */
serviceUuids?: string[]
}
/** 订单金额信息。 */
interface Amount {
/** 订单总需支付金额,也即是真正下单总金额,单位为分。示例值:1300 */
order_amount: number
/** 货币类型。示例值:CNY
*
* 可选值:
* - 'CNY': 人民币; */
currency?: 'CNY'
/** 订单总计优惠金额,单位为分。示例值:500 */
discount?: number
/** 订单运费,单位为分。示例值:200 */
freight?: number
/** 订单其他费用总金额,单位为分。示例值:600 */
other_fee?: number
/** 订单所有商品的原价总和,单位为分。示例值:1000 */
product_amount?: number
}
/** animationData */
interface AnimationExportResult {
actions: IAnyObject[]
}
/** 动画效果 */
interface AnimationOption {
/** 动画变化时间,单位 ms */
duration?: number
/** 动画变化方式
*
* 可选值:
* - 'linear': 动画从头到尾的速度是相同的;
* - 'easeIn': 动画以低速开始;
* - 'easeOut': 动画以低速结束;
* - 'easeInOut': 动画以低速开始和结束; */
timingFunc?: 'linear' | 'easeIn' | 'easeOut' | 'easeInOut'
}
interface AppAuthorizeSetting {
/** 允许微信使用相册的开关(仅 iOS 有效) */
albumAuthorized: 'authorized' | 'denied' | 'not determined'
/** 允许微信使用蓝牙的开关(安卓基础库 3.5.0 以上有效) */
bluetoothAuthorized: 'authorized' | 'denied' | 'not determined'
/** 允许微信使用摄像头的开关 */
cameraAuthorized: 'authorized' | 'denied' | 'not determined'
/** 允许微信使用定位的开关 */
locationAuthorized: 'authorized' | 'denied' | 'not determined'
/** 定位准确度。true 表示模糊定位,false 表示精确定位(仅 iOS 有效) */
locationReducedAccuracy: boolean
/** 允许微信使用麦克风的开关 */
microphoneAuthorized: 'authorized' | 'denied' | 'not determined'
/** 允许微信通知带有提醒的开关(仅 iOS 有效) */
notificationAlertAuthorized: 'authorized' | 'denied' | 'not determined'
/** 允许微信通知的开关 */
notificationAuthorized: 'authorized' | 'denied' | 'not determined'
/** 允许微信通知带有标记的开关(仅 iOS 有效) */
notificationBadgeAuthorized: 'authorized' | 'denied' | 'not determined'
/** 允许微信通知带有声音的开关(仅 iOS 有效) */
notificationSoundAuthorized: 'authorized' | 'denied' | 'not determined'
/** 允许微信读写日历的开关 */
phoneCalendarAuthorized: 'authorized' | 'denied' | 'not determined'
}
interface AppBaseInfo {
/** 客户端基础库版本 */
SDKVersion: string
/** 是否已打开调试。可通过右上角菜单或 [wx.setEnableDebug](https://developers.weixin.qq.com/miniprogram/dev/api/base/debug/wx.setEnableDebug.html) 打开调试。 */
enableDebug: boolean
/** 微信字体大小缩放比例 */
fontSizeScaleFactor: number
/** 需要基础库: `2.23.4`
*
* 微信字体大小,单位px */
fontSizeSetting: number
/** 当前小程序运行的宿主环境 */
host: AppBaseInfoHost
/** 微信设置的语言 */
language: string
/** 微信版本号 */
version: string
/** 系统当前主题,取值为`light`或`dark`,全局配置`"darkmode":true`时才能获取,否则为 undefined (不支持小游戏)
*
* 可选值:
* - 'dark': 深色主题;
* - 'light': 浅色主题; */
theme?: 'dark' | 'light'
}
/** 当前小程序运行的宿主环境 */
interface AppBaseInfoHost {
/** 宿主 app(第三方App) 对应的 appId (当小程序运行在第三方App环境时才返回) */
appId: string
}
interface AppendFileOption {
/** 要追加的文本或二进制数据 */
data: string | ArrayBuffer
/** 要追加内容的文件路径 (本地路径) */
filePath: string
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
complete?: AppendFileCompleteCallback
/** 指定写入文件的字符编码
*
* 可选值:
* - 'ascii': ;
* - 'base64': ;
* - 'binary': ;
* - 'hex': ;
* - 'ucs2': 以小端序读取;
* - 'ucs-2': 以小端序读取;
* - 'utf16le': 以小端序读取;
* - 'utf-16le': 以小端序读取;
* - 'utf-8': ;
* - 'utf8': ;
* - 'latin1': ; */
encoding?:
| 'ascii'
| 'base64'
| 'binary'
| 'hex'
| 'ucs2'
| 'ucs-2'
| 'utf16le'
| 'utf-16le'
| 'utf-8'
| 'utf8'
| 'latin1'
/** 接口调用失败的回调函数 */
fail?: AppendFileFailCallback
/** 接口调用成功的回调函数 */
success?: AppendFileSuccessCallback
}
interface ApplyBlusherStickMakeupOption {
/** 上色程度 0-1 */
alpha: number
blendMode: string
/** 左腮红资源路径 */
path: string
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
complete?: ApplyBlusherStickMakeupCompleteCallback
/** 接口调用失败的回调函数 */
fail?: ApplyBlusherStickMakeupFailCallback
/** 接口调用成功的回调函数 */
success?: ApplyBlusherStickMakeupSuccessCallback
}
interface ApplyEyeBrowMakeupOption {
/** 上色程度 0-1 */
alpha: number
blendMode: string
path: string
shrinkRate: number
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
complete?: ApplyEyeBrowMakeupCompleteCallback
/** 接口调用失败的回调函数 */
fail?: ApplyEyeBrowMakeupFailCallback
/** 接口调用成功的回调函数 */
success?: ApplyEyeBrowMakeupSuccessCallback
}
interface ApplyEyeShadowMakeupOption {
/** 上色程度 0-1 */
alpha: number
blendMode: string
/** 眼影资源路径 */
path: string
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
complete?: ApplyEyeShadowMakeupCompleteCallback
/** 接口调用失败的回调函数 */
fail?: ApplyEyeShadowMakeupFailCallback
/** 细致效果图片资源路径 */
shimmerPosition?: string
/** 细致效果图片资源 md5 */
shimmerPositionMD5?: string
/** 接口调用成功的回调函数 */
success?: ApplyEyeShadowMakeupSuccessCallback
}
interface ApplyFaceContourMakeupOption {
alpha: number
/** 高光资源路径 */
path: string
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
complete?: ApplyFaceContourMakeupCompleteCallback
/** 接口调用失败的回调函数 */
fail?: ApplyFaceContourMakeupFailCallback
/** 接口调用成功的回调函数 */
success?: ApplyFaceContourMakeupSuccessCallback
}
interface ApplyFilterOption {
/** 滤镜效果透明度,范围是 0-1 */
alpha: number
/** 滤镜资源路径 */
path: string
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
complete?: ApplyFilterCompleteCallback
/** 接口调用失败的回调函数 */
fail?: ApplyFilterFailCallback
/** 滤镜资源 md5 */
md5?: string
/** 接口调用成功的回调函数 */
success?: ApplyFilterSuccessCallback
}
interface ApplyLipStickMakeupOption {
/** 上色程度 0-1 */
alpha: number
blendMode: string
faceModel: string
path: string
shimmerPath: string
shimmerType: string
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
complete?: ApplyLipStickMakeupCompleteCallback
/** 接口调用失败的回调函数 */
fail?: ApplyLipStickMakeupFailCallback
/** 接口调用成功的回调函数 */
success?: ApplyLipStickMakeupSuccessCallback
}
interface ApplyStickerOption {
/** 贴纸类型 */
stickers: Sticker[]
/** 贴纸类型 */
type: string
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
complete?: ApplyStickerCompleteCallback
/** 接口调用失败的回调函数 */
fail?: ApplyStickerFailCallback
/** 接口调用成功的回调函数 */
success?: ApplyStickerSuccessCallback
templateTransSet?: IAnyObject
}
interface Asset {
src: string
/** 可选值:
* - 'font': 字体;
* - 'image': 图片; */
type: 'font' | 'image'
}
/** 需要基础库: `2.19.0`
*
* AudioBuffer接口表示存在内存里的一段短小的音频资源,利用[WebAudioContext.decodeAudioData](https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/WebAudioContext.decodeAudioData.html)方法从一个音频文件构建,或者利用 [WebAudioContext.createBuffer](https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/WebAudioContext.createBuffer.html)从原始数据构建。把音频放入AudioBuffer后,可以传入到一个 AudioBufferSourceNode进行播放。 */
interface AudioBuffer {
/** 返回存储在缓存区的PCM数据的时长(单位为秒) */
duration: number
/** 返回存储在缓存区的PCM数据的采样帧率 */
length: number
/** 储存在缓存区的PCM数据的通道数 */
numberOfChannels: number
/** 存储在缓存区的PCM数据的采样率(单位为sample/s) */
sampleRate: number
/** [AudioBuffer.copyFromChannel()](https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/AudioBuffer.copyFromChannel.html)
*
* 在插件中使用:不支持
*
* 从AudioBuffer的指定频道复制到数组终端。 */
copyFromChannel(): void
/** [AudioBuffer.copyToChannel(Float32Array source, number channelNumber, number startInChannel)](https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/AudioBuffer.copyToChannel.html)
*
* 在插件中使用:不支持
*
* 从指定数组复制样本到audioBuffer的特定通道
*
* **示例代码**
*
* 示例代码参考AudioBuffer.copyFromChannel */
copyToChannel(
/** 需要复制的源数组 */
source: Float32Array,
/** 需要复制到的目的通道号 */
channelNumber: number,
/** 复制偏移数据量 */
startInChannel: number
): void
/** [Float32Array AudioBuffer.getChannelData(number channel)](https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/AudioBuffer.getChannelData.html)
*
* 在插件中使用:不支持
*
* 返回一个 Float32Array,包含了带有频道的PCM数据,由频道参数定义(有0代表第一个频道) */
getChannelData(
/** 要获取特定通道数据的索引 */
channel: number
): Float32Array
}
/** 空间音频监听器,代表在一个音频场景内唯一的位置和方向信息。 */
interface AudioListener {
/** 表示监听器的前向系统在同一笛卡尔坐标系中的水平位置,作为位置(位置x,位置和位置和位置)值。 */
forwardX: number
/** 表示听众的前向方向在同一笛卡尔坐标系中作为位置(位置x,位置和位置和位置)值的垂直位置。 */
forwardY: number
/** 表示与position (positionX、positionY和positionZ)值在同一笛卡尔坐标系下的听者前进方向的纵向(前后)位置。 */
forwardZ: number
/** 右手笛卡尔坐标系中X轴的位置。 */
positionX: number
/** 右手笛卡尔坐标系中Y轴的位置。 */
positionY: number
/** 右手笛卡尔坐标系中Z轴的位置。 */
positionZ: number
/** 设置监听器的方向 */
setOrientation: (...args: any[]) => any
/** 设置监听器的位置 */
setPosition: (...args: any[]) => any
/** 表示在与position (positionX、positionY和positionZ)值相同的笛卡尔坐标系中侦听器向前方向的水平位置。 */
upX: number
/** 表示在与position (positionX、positionY和positionZ)值相同的笛卡尔坐标系中侦听器向上方向的水平位置。 */
upY: number
/** 表示在与position (positionX、positionY和positionZ)值相同的笛卡尔坐标系中侦听器向后方向的水平位置。 */
upZ: number
}
/** 需要基础库: `2.19.0`
*
* AudioParam 接口代表音频相关的参数,通常是 AudioNode(例如 GainNode.gain)的参数 */
interface AudioParam {
/** 代表被具体的 AudioNode 创建的 AudioParam 的属性的初始值(只读) */
defaultValue: number
/** 代表参数有效范围的最大可能值(只读) */
maxValue: number
/** 代表参数有效范围的最小可能值(只读) */
minValue: number
/** 当前属性的值(比如音量值或播放倍速值)(可读可写) */
value: number
}
interface AuthPrivateMessageOption {
/** shareTicket。可以从 wx.getEnterOptionsSync 中获取。详情 [shareTicket](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share.html) */
shareTicket: string
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
complete?: AuthPrivateMessageCompleteCallback
/** 接口调用失败的回调函数 */
fail?: AuthPrivateMessageFailCallback
/** 接口调用成功的回调函数 */
success?: AuthPrivateMessageSuccessCallback
}
interface AuthPrivateMessageSuccessCallbackResult {
/** 经过加密的activityId,解密后可得到原始的activityId。若解密后得到的activityId可以与开发者后台的活动id对应上则验证通过,否则表明valid字段不可靠(被篡改) 详细见[加密数据解密算法](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/signature.html) */
encryptedData: string
/** 错误信息 */
errMsg: string
/** 加密算法的初始向量,详细见[加密数据解密算法](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/signature.html) */
iv: string
/** 验证是否通过 */
valid: boolean
}
/** 用户授权设置信息,详情参考[权限](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/authorize.html) */
interface AuthSetting {
/** 是否授权系统日历,对应接口 [wx.addPhoneRepeatCalendar](https://developers.weixin.qq.com/miniprogram/dev/api/device/calendar/wx.addPhoneRepeatCalendar.html)、[wx.addPhoneCalendar](https://developers.weixin.qq.com/miniprogram/dev/api/device/calendar/wx.addPhoneCalendar.html) */
'scope.addPhoneCalendar'?: boolean
/** 是否添加通讯录联系人,对应接口 [wx.addPhoneContact](https://developers.weixin.qq.com/miniprogram/dev/api/device/contact/wx.addPhoneContact.html) */
'scope.addPhoneContact'?: boolean
/** 是否授权通讯地址,已取消此项授权,会默认返回true */
'scope.address'?: boolean
/** 是否授权蓝牙,对应接口 [wx.openBluetoothAdapter](https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth/wx.openBluetoothAdapter.html)、[wx.createBLEPeripheralServer](https://developers.weixin.qq.com/miniprogram/dev/api/device/bluetooth-peripheral/wx.createBLEPeripheralServer.html) */
'scope.bluetooth'?: boolean
/** 是否授权摄像头,对应[[camera](https://developers.weixin.qq.com/miniprogram/dev/component/camera.html)](https://developers.weixin.qq.com/miniprogram/dev/component/camera.html) 组件 */
'scope.camera'?: boolean
/** 是否授权获取发票,已取消此项授权,会默认返回true */
'scope.invoice'?: boolean
/** 是否授权发票抬头,已取消此项授权,会默认返回true */
'scope.invoiceTitle'?: boolean
/** 是否授权录音功能,对应接口 [wx.getRecorderManager](https://developers.weixin.qq.com/miniprogram/dev/api/media/recorder/wx.getRecorderManager.html) */
'scope.record'?: boolean
/** 是否授权模糊地理位置,对应接口 [wx.getFuzzyLocation](https://developers.weixin.qq.com/miniprogram/dev/api/location/wx.getFuzzyLocation.html) */
'scope.userFuzzyLocation'?: boolean
/** 是否授权用户信息,对应接口 [wx.getUserInfo](https://developers.weixin.qq.com/miniprogram/dev/api/open-api/user-info/wx.getUserInfo.html) */
'scope.userInfo'?: boolean
/** 是否授权精确地理位置,对应接口 [wx.getLocation](https://developers.weixin.qq.com/miniprogram/dev/api/location/wx.getLocation.html), [wx.chooseLocation](https://developers.weixin.qq.com/miniprogram/dev/api/location/wx.chooseLocation.html) */
'scope.userLocation'?: boolean
/** 是否授权微信运动步数,对应接口 [wx.getWeRunData](https://developers.weixin.qq.com/miniprogram/dev/api/open-api/werun/wx.getWeRunData.html) */
'scope.werun'?: boolean
/** 是否授权保存到相册 [wx.saveImageToPhotosAlbum](https://developers.weixin.qq.com/miniprogram/dev/api/media/image/wx.saveImageToPhotosAlbum.html), [wx.saveVideoToPhotosAlbum](https://developers.weixin.qq.com/miniprogram/dev/api/media/video/wx.saveVideoToPhotosAlbum.html) */
'scope.writePhotosAlbum'?: boolean
}
interface AuthorizeForMiniProgramOption {
/** 需要获取权限的 scope,详见 [scope 列表](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/authorize.html#scope-列表)
*
* 可选值:
* - 'scope.record': ;
* - 'scope.writePhotosAlbum': ;
* - 'scope.camera': ; */
scope: 'scope.record' | 'scope.writePhotosAlbum' | 'scope.camera'
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
complete?: AuthorizeForMiniProgramCompleteCallback
/** 接口调用失败的回调函数 */
fail?: AuthorizeForMiniProgramFailCallback
/** 接口调用成功的回调函数 */
success?: AuthorizeForMiniProgramSuccessCallback
}
interface AuthorizeOption {
/** 需要获取权限的 scope,详见 [scope 列表](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/authorize.html#scope-列表) */
scope: string
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
complete?: AuthorizeCompleteCallback
/** 接口调用失败的回调函数 */
fail?: AuthorizeFailCallback
/** 接口调用成功的回调函数 */
success?: AuthorizeSuccessCallback
}
/** 设备特征列表 */
interface BLECharacteristic {
/** 该特征支持的操作类型 */
properties: BLECharacteristicProperties
/** 蓝牙设备特征的 UUID */
uuid: string
}
/** 该特征支持的操作类型 */
interface BLECharacteristicProperties {
/** 该特征是否支持 indicate 操作 */
indicate: boolean
/** 该特征是否支持 notify 操作 */
notify: boolean
/** 该特征是否支持 read 操作 */
read: boolean
/** 该特征是否支持 write 操作 */
write: boolean
/** 该特征是否支持有回复写操作 */
writeDefault: boolean
/** 该特征是否支持无回复写操作 */
writeNoResponse: boolean
}
interface BLEPeripheralServerCloseOption {
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
complete?: SocketTaskCloseCompleteCallback
/** 接口调用失败的回调函数 */
fail?: SocketTaskCloseFailCallback
/** 接口调用成功的回调函数 */
success?: SocketTaskCloseSuccessCallback
}
/** 描述service的Object */
interface BLEPeripheralService {
/** characteristics列表 */
characteristics: Characteristic[]
/** 蓝牙服务的 UUID */
uuid: string
}
/** 设备服务列表 */
interface BLEService {
/** 该服务是否为主服务 */
isPrimary: boolean
/** 蓝牙设备服务的 UUID */
uuid: string
}
/** BackgroundAudioManager 实例,可通过 [wx.getBackgroundAudioManager](https://developers.weixin.qq.com/miniprogram/dev/api/media/background-audio/wx.getBackgroundAudioManager.html) 获取。
*
* **示例代码**
*
* ```js
const backgroundAudioManager = wx.getBackgroundAudioManager()
backgroundAudioManager.title = '此时此刻'
backgroundAudioManager.epname = '此时此刻'
backgroundAudioManager.singer = '许巍'
backgroundAudioManager.coverImgUrl = 'http://y.gtimg.cn/music/photo_new/T002R300x300M000003rsKF44GyaSk.jpg?max_age=2592000'
// 设置了 src 之后会自动播放
backgroundAudioManager.src = 'https://wx_test.mp3'
``` */
interface BackgroundAudioManager {
/** 需要基础库: `3.4.8`
*
* 音频类型。可设置 "audio" 和 "music" 两种值,默认为 "audio"。不同音频类型对应的播放器样式不一样(实验特性,目前仅iOS和Android端支持) */
audioType: string
/** 音频已缓冲的时间,仅保证当前播放时间点到此时间点内容已缓冲。(只读) */
buffered: number
/** 封面图 URL,用于做原生音频播放器背景图。原生音频播放器中的分享功能,分享出去的卡片配图及背景也将使用该图。 */
coverImgUrl: string
/** 当前音频的播放位置(单位:s),只有在有合法 src 时返回。(只读) */
currentTime: number
/** 当前音频的长度(单位:s),只有在有合法 src 时返回。(只读) */
duration: number
/** 专辑名,原生音频播放器中的分享功能,分享出去的卡片简介,也将使用该值。 */
epname: string
/** 当前是否暂停或停止。(只读) */
paused: boolean
/** 需要基础库: `2.11.0`
*
* 播放速度。范围 0.5-2.0,默认为 1。(Android 需要 6 及以上版本) */
playbackRate: number
/** 需要基础库: `1.9.94`
*
* 音频协议。默认值为 'http',设置 'hls' 可以支持播放 HLS 协议的直播音频。 */
protocol: string
/** 需要基础库: `3.4.8`
*
* 关联页面路径。设置后,当点击播放器上的小程序跳转链接时,将跳转到这个关联页面路径(实验特性,目前仅Android端支持) */
referrerPath: string
/** 需要基础库: `2.13.0`
*
* `origin`: 发送完整的referrer; `no-referrer`: 不发送。格式固定为 `https://servicewechat.com/{appid}/{version}/page-frame.html`,其中 {appid} 为小程序的 appid,{version} 为小程序的版本号,版本号为 0 表示为开发版、体验版以及审核版本,版本号为 devtools 表示为开发者工具,其余为正式版本; */
referrerPolicy: string
/** 歌手名,原生音频播放器中的分享功能,分享出去的卡片简介,也将使用该值。 */
singer: string
/** 音频的数据源([2.2.3](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html) 开始支持云文件ID)。默认为空字符串,**当设置了新的 src 时,会自动开始播放**,目前支持的格式有 m4a, aac, mp3, wav。 */
src: string
/** 音频开始播放的位置(单位:s)。 */
startTime: number
/** 音频标题,用于原生音频播放器音频标题(必填)。原生音频播放器中的分享功能,分享出去的卡片标题,也将使用该值。 */
title: string
/** 页面链接,原生音频播放器中的分享功能,分享出去的卡片简介,也将使用该值。 */
webUrl: string
/** [BackgroundAudioManager.onCanplay(function listener)](https://developers.weixin.qq.com/miniprogram/dev/api/media/background-audio/BackgroundAudioManager.onCanplay.html)
*
* 在插件中使用:支持
*
* 监听背景音频进入可播放状态事件。 但不保证后面可以流畅播放 */
onCanplay(
/** 背景音频进入可播放状态事件的监听函数 */
listener: OnCanplayCallback
): void
/** [BackgroundAudioManager.onEnded(function listener)](https://developers.weixin.qq.com/miniprogram/dev/api/media/background-audio/BackgroundAudioManager.onEnded.html)
*
* 在插件中使用:支持
*
* 监听背景音频自然播放结束事件 */
onEnded(
/** 背景音频自然播放结束事件的监听函数 */
listener: OnEndedCallback
): void
/** [BackgroundAudioManager.onError(function listener)](https://developers.weixin.qq.com/miniprogram/dev/api/media/background-audio/BackgroundAudioManager.onError.html)
*
* 在插件中使用:支持
*
* 监听背景音频播放错误事件 */
onError(
/** 背景音频播放错误事件的监听函数 */
listener: BackgroundAudioManagerOnErrorCallback
): void
/** [BackgroundAudioManager.onNext(function listener)](https://developers.weixin.qq.com/miniprogram/dev/api/media/background-audio/BackgroundAudioManager.onNext.html)
*
* 在插件中使用:支持
*
* 监听用户在系统音乐播放面板点击下一曲事件 */
onNext(
/** 用户在系统音乐播放面板点击下一曲事件的监听函数 */
listener: OnNextCallback
): void
/** [BackgroundAudioManager.onPause(function listener)](https://developers.weixin.qq.com/miniprogram/dev/api/media/background-audio/BackgroundAudioManager.onPause.html)
*
* 在插件中使用:支持
*
* 监听背景音频暂停事件 */
onPause(
/** 背景音频暂停事件的监听函数 */
listener: OnPauseCallback
): void
/** [BackgroundAudioManager.onPlay(function listener)](https://developers.weixin.qq.com/miniprogram/dev/api/media/background-audio/BackgroundAudioManager.onPlay.html)
*
* 在插件中使用:支持
*
* 监听背景音频播放事件 */
onPlay(
/** 背景音频播放事件的监听函数 */
listener: OnPlayCallback
): void
/** [BackgroundAudioManager.onPrev(function listener)](https://developers.weixin.qq.com/miniprogram/dev/api/media/background-audio/BackgroundAudioManager.onPrev.html)
*
* 在插件中使用:支持
*
* 监听用户在系统音乐播放面板点击上一曲事件 */
onPrev(
/** 用户在系统音乐播放面板点击上一曲事件的监听函数 */
listener: OnPrevCallback
): void
/** [BackgroundAudioManager.onSeeked(function listener)](https://developers.weixin.qq.com/miniprogram/dev/api/media/background-audio/BackgroundAudioManager.onSeeked.html)
*
* 在插件中使用:支持
*
* 监听背景音频完成跳转操作事件 */
onSeeked(
/** 背景音频完成跳转操作事件的监听函数 */
listener: OnSeekedCallback
): void
/** [BackgroundAudioManager.onSeeking(function listener)](https://developers.weixin.qq.com/miniprogram/dev/api/media/background-audio/BackgroundAudioManager.onSeeking.html)
*
* 在插件中使用:支持
*
* 监听背景音频开始跳转操作事件 */
onSeeking(
/** 背景音频开始跳转操作事件的监听函数 */
listener: OnSeekingCallback
): void
/** [BackgroundAudioManager.onStop(function listener)](https://developers.weixin.qq.com/miniprogram/dev/api/media/background-audio/BackgroundAudioManager.onStop.html)
*
* 在插件中使用:支持
*
* 监听背景音频停止事件 */
onStop(
/** 背景音频停止事件的监听函数 */
listener: InnerAudioContextOnStopCallback
): void
/** [BackgroundAudioManager.onTimeUpdate(function listener)](https://developers.weixin.qq.com/miniprogram/dev/api/media/background-audio/BackgroundAudioManager.onTimeUpdate.html)
*
* 在插件中使用:支持
*
* 监听背景音频播放进度更新事件,只有小程序在前台时会回调。 */
onTimeUpdate(
/** 背景音频播放进度更新事件的监听函数 */
listener: OnTimeUpdateCallback
): void
/** [BackgroundAudioManager.onWaiting(function listener)](https://developers.weixin.qq.com/miniprogram/dev/api/media/background-audio/BackgroundAudioManager.onWaiting.html)
*
* 在插件中使用:支持
*
* 监听音频加载中事件。当音频因为数据不足,需要停下来加载时会触发 */
onWaiting(
/** 音频加载中事件的监听函数 */
listener: OnWaitingCallback
): void
/** [BackgroundAudioManager.pause()](https://developers.weixin.qq.com/miniprogram/dev/api/media/background-audio/BackgroundAudioManager.pause.html)
*
* 在插件中使用:支持
*
* 暂停音乐 */
pause(): void
/** [BackgroundAudioManager.play()](https://developers.weixin.qq.com/miniprogram/dev/api/media/background-audio/BackgroundAudioManager.play.html)
*
* 在插件中使用:支持
*
* 播放音乐 */
play(): void
/** [BackgroundAudioManager.seek(number currentTime)](https://developers.weixin.qq.com/miniprogram/dev/api/media/background-audio/BackgroundAudioManager.seek.html)
*
* 在插件中使用:支持
*
* 跳转到指定位置 */
seek(
/** 跳转的位置,单位 s。精确到小数点后 3 位,即支持 ms 级别精确度 */
currentTime: number
): void
/** [BackgroundAudioManager.stop()](https://developers.weixin.qq.com/miniprogram/dev/api/media/background-audio/BackgroundAudioManager.stop.html)
*
* 在插件中使用:支持
*
* 停止音乐 */
stop(): void
}
interface BatchGetStorageOption {
/** 本地缓存中指定的 keyList */
keyList: string[]
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
complete?: BatchGetStorageCompleteCallback
/** 接口调用失败的回调函数 */
fail?: BatchGetStorageFailCallback
/** 接口调用成功的回调函数 */
success?: BatchGetStorageSuccessCallback
}
interface BatchSetStorageOption {
/** [{ key, value }] */
kvList: any[]
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
complete?: BatchSetStorageCompleteCallback
/** 接口调用失败的回调函数 */
fail?: BatchSetStorageFailCallback
/** 接口调用成功的回调函数 */
success?: BatchSetStorageSuccessCallback
}
/** Beacon 设备 */
interface BeaconInfo {
/** Beacon 设备的距离,单位 m。iOS 上,proximity 为 0 时,accuracy 为 -1。 */
accuracy: number
/** Beacon 设备的主 ID */
major: number
/** Beacon 设备的次 ID */
minor: number
/** 表示设备距离的枚举值(仅iOS)
*
* 可选值:
* - 0: 信号太弱不足以计算距离,或非 iOS 设备;
* - 1: 十分近;
* - 2: 比较近;
* - 3: 远; */
proximity: 0 | 1 | 2 | 3
/** 表示设备的信号强度,单位 dBm */
rssi: number
/** Beacon 设备广播的 UUID */
uuid: string
}
/** 需要基础库: `2.20.1`
*
* 以 beacon 设备形式广播的参数。 */
interface BeaconInfoObj {
/** Beacon 设备的主 ID */
major: number
/** Beacon 设备的次 ID */
minor: number
/** Beacon 设备广播的 UUID */
uuid: string
/** 用于判断距离设备 1 米时 RSSI 大小的参考值 */
measuredPower?: number
}
interface BindWifiOption {
/** 当前 wifi 网络的 BSSID ,可通过 wx.getConnectedWifi 获取 */
BSSID: string
}
interface BlueToothDevice {
/** 当前蓝牙设备的信号强度,单位 dBm */
RSSI: number
/** 当前蓝牙设备的广播数据段中的 ManufacturerData 数据段。 */
advertisData: ArrayBuffer
/** 当前蓝牙设备的广播数据段中的 ServiceUUIDs 数据段 */
advertisServiceUUIDs: string[]
/** 当前蓝牙设备是否可连接( Android 8.0 以下不支持返回该值 ) */
connectable: boolean
/** 蓝牙设备 id */
deviceId: string
/** 当前蓝牙设备的广播数据段中的 LocalName 数据段 */
localName: string
/** 蓝牙设备名称,某些设备可能没有 */
name: string
/** 当前蓝牙设备的广播数据段中的 ServiceData 数据段 */
serviceData: IAnyObject
}
/** 搜索到的设备列表 */
interface BluetoothDeviceInfo {
/** 用于区分设备的 id */
deviceId: string
/** 蓝牙设备名称,某些设备可能没有 */
name: string
}
interface BlurOption {
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
complete?: BlurCompleteCallback
/** 接口调用失败的回调函数 */
fail?: BlurFailCallback
/** 接口调用成功的回调函数 */
success?: BlurSuccessCallback
}
/** 需要基础库: `2.28.0`
*
* 人体检测配置。用法详情[指南文档](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/visionkit/body.html)。 */
interface BodyTrack {
/** 需要基础库: `2.28.0`
*
* 人体检测模式
*
* 可选值:
* - 1: 通过摄像头实时检测;
* - 2: 静态图片检测; */
mode: 1 | 2
}
interface BoundingClientRectCallbackResult {
/** 节点的下边界坐标 */
bottom: number
/** 节点的 dataset */
dataset: IAnyObject
/** 节点的高度 */
height: number
/** 节点的 ID */
id: string
/** 节点的左边界坐标 */
left: number
/** 节点的右边界坐标 */
right: number
/** 节点的上边界坐标 */
top: number
/** 节点的宽度 */
width: number
}
/** 目标边界 */
interface BoundingClientRectResult {
/** 下边界 */
bottom: number
/** 高度 */
height: number
/** 左边界 */
left: number
/** 右边界 */
right: number
/** 上边界 */
top: number
/** 宽度 */
width: number
}
/** 音频源节点,通过 [WebAudioContext.createBufferSource](https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/WebAudioContext.createBufferSource.html)方法获得。
*
* **示例代码**
*
* ```js
const source = audioCtx.createBufferSource()
source.buffer = AudioBuffer
source.connect(audioCtx.destination)
source.start()
``` */
interface BufferSourceNode {
/** [AudioBuffer](https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/AudioBuffer.html)
*
* 是一个 AudioBuffer, 它定义了要播放的音频,当设置它的值为 0 时,它会定义一个静默的单通道。(可读可写) */
buffer: AudioBuffer
/** 定义音频是否循环播放(可读可写) */
loop?: boolean
/** 定义音频循环播放时,结束播放的位置。单位是秒,默认值是0(可读可写) */
loopEnd?: number
/** 定义音频循环播放时,开始播放的位置。单位是秒,默认值是0(可读可写) */
loopStart?: number
/** 定义音频播放结束事件回调函数(可读可写) */
onended?: (...args: any[]) => any
/** [AudioParam](https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/AudioParam.html)
*
* 定义音频的播放倍速,数值越大速度越快,默认速度1.0,有效范围为 0 < playbackRate <= 2.0(可读可写) */
playbackRate?: AudioParam
/** [BufferSourceNode.connect(AudioNode|[AudioParam](https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/AudioParam.html) destination)](https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/BufferSourceNode.connect.html)
*
* 在插件中使用:不支持
*
* 连接到一个指定目标。这个指定的目标可能是另一个 AudioNode(从而将音频数据引导到下一个指定节点)或一个AudioParam, 以便上一个节点的输出数据随着时间流逝能自动地对下一个参数值进行改变 */
connect(
/** 要建立连接的目标节点 */
destination: AudioNode | AudioParam
): void
/** [BufferSourceNode.disconnect()](https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/BufferSourceNode.disconnect.html)
*
* 在插件中使用:不支持
*
* 与已连接的目标节点断开连接 */
disconnect(): void
/** [BufferSourceNode.start(number when, number offset, number duration)](https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/BufferSourceNode.start.html)
*
* 在插件中使用:不支持
*
* 音频源开始播放 */
start(
/** 延迟播放的时间,单位是秒。与 AudioContext 使用相同的时间坐标系统。如果 when 小于 AudioContext.currentTime, 或者是 0,声音立即被播放。 默认值是 0 */
when?: number,
/** 音频开始播放的位置,单位是秒。默认值是 0 */
offset?: number,
/** 音频播放的持续时间,单位是秒。如果这个参数没有被指定,声音播放到自然结束或者使用stop() 方法结束。使用这个参数的功能与调用 start(when, offset) 和调用 stop(when+duration)效果完全相同 */
duration?: number
): void
/** [BufferSourceNode.stop(number when)](https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/BufferSourceNode.stop.html)
*
* 在插件中使用:不支持
*
* 停止播放 */
stop(
/** 延迟停止播放的时间,单位是秒。与 AudioContext 使用相同的时间坐标系统。省略此参数、指定值 0 或传递负值会使声音立即停止播放。 */
when?: number
): void
}
/** 需要基础库: `2.24.0`
*
* 缓存管理器。全局只有唯一实例,一旦被创建出来即表示接入缓存管理器。其有以下几个能力:
*
* 1. 在网络通畅时,符合一定规则的用户网络请求(目前只包括普通 wx.request 请求)会被缓存。
* 2. 在网络通畅时,某些 wx api 调用会被缓存。
* 3. 进入弱网/离线状态时,会提供事件给用户,用户可以决定是否使用缓存返回。
* 4. 提供进入和退出弱网/离线状态的事件。
*
* > 1. 缓存管理器中涉及的网络请求如无特指,均指普通的 wx.request 异步请求,参数和返回值中均不考虑涉及 ArrayBuffer 或 TypedArray 的情形。
* > 2. 缓存管理器中的缓存不会占用 storage 空间,但是有大小限制,请勿在非必要的请求上使用缓存。 */
interface CacheManager {
/** 全局缓存有效时间 */
maxAge: number
/** 当前缓存模式
*
* 可选值:
* - 'weakNetwork': 默认值,弱网/离线使用缓存返回;
* - 'always': 总是使用缓存返回;
* - 'none': 不开启,后续可手动开启/停止使用缓存返回; */
mode: 'weakNetwork' | 'always' | 'none'
/** 全局 origin */
origin: string
/** 当前缓存管理器状态
*
* 可选值:
* - 0: 不使用缓存返回;
* - 1: 使用缓存返回;
* - 2: 未知; */
state: 0 | 1 | 2
/** [Array.<string> CacheManager.addRules(Array.<(string|RegExp|Record.<string, any>)> rules)](https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.addRules.html)
*
* 需要基础库: `2.24.0`
*
* 在插件中使用:不支持
*
* 批量添加规则,规则写法可参考 [CacheManager.addRule](https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.addRule.html)。 */
addRules(
/** 规则列表 */
rules: Array<string | RegExp | Record<string, any>>
): string[]
/** [CacheManager.clearCaches()](https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.clearCaches.html)
*
* 需要基础库: `2.24.0`
*
* 在插件中使用:不支持
*
* 清空所有缓存。 */
clearCaches(): void
/** [CacheManager.clearRules()](https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.clearRules.html)
*
* 需要基础库: `2.24.0`
*
* 在插件中使用:不支持
*
* 清空所有规则,同时会删除对应规则下所有缓存。 */
clearRules(): void
/** [CacheManager.deleteCache(string id)](https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.deleteCache.html)
*
* 需要基础库: `2.24.0`
*
* 在插件中使用:不支持
*
* 删除缓存。 */
deleteCache(
/** 缓存 id */
id: string
): void
/** [CacheManager.deleteCaches(Array.<string> ids)](https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.deleteCaches.html)
*
* 需要基础库: `2.24.0`
*
* 在插件中使用:不支持
*
* 批量删除缓存。 */
deleteCaches(
/** 缓存 id 列表 */
ids: string[]
): void
/** [CacheManager.deleteRule(string id)](https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.deleteRule.html)
*
* 需要基础库: `2.24.0`
*
* 在插件中使用:不支持
*
* 删除规则,同时会删除对应规则下所有缓存。 */
deleteRule(
/** 规则 id */
id: string
): void
/** [CacheManager.deleteRules(Array.<string> ids)](https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.deleteRules.html)
*
* 需要基础库: `2.24.0`
*
* 在插件中使用:不支持
*
* 批量删除规则,同时会删除对应规则下所有缓存。 */
deleteRules(
/** 规则 id 列表 */
ids: string[]
): void
/** [CacheManager.off(string eventName, function handler)](https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.off.html)
*
* 需要基础库: `2.24.0`
*
* 在插件中使用:不支持
*
* 取消事件监听。 */
off(
/** 事件名 */
eventName: string,
/** 事件句柄 */
handler: (...args: any[]) => any
): void
/** [CacheManager.on(string eventName, function handler)](https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.on.html)
*
* 需要基础库: `2.24.0`
*
* 在插件中使用:不支持
*
* 监听事件。
*
* ****
*
* 这里 request 事件会提供 request 事件对象,用于做后续的处理;在 request 事件中需要返回一个 promise,用来生成 wx.request 请求的返回内容。
*
* #### 示例代码
*
* ```js
async function handler(evt) {
// evt.url - 请求 url
// evt.data - 请求参数
// evt.method - 请求方法
// evt.request - 原始 request 方法,返回一个 promise
// if (evt.url === '/xxx') {
// // 如果有些请求仍然希望走到网络,则可以如下处理
// const res = await evt.request()
// // res 即为网络请求返回
// }
return new Promsie((resolve, reject) => {
// do sth
if (data) {
// 这里 resolve 的 data 就会作为 wx.request 的 success 回调结果返回
resolve(data)
} else {
// 这里 reject 的错误信息就会作为 wx.request 的 fail 回调结果返回
reject('no data')
}
})
}
cacheManager.on('request', handler)
``` */
on(
/** 事件名
*
* 参数 eventName 可选值:
* - 'request': 发生 wx.request 请求,只在缓存管理器开启阶段会触发;
* - 'enterWeakNetwork': 进入弱网/离线状态;
* - 'exitWeakNetwork': 离开弱网/离线状态; */
eventName: 'request' | 'enterWeakNetwork' | 'exitWeakNetwork',
/** 事件句柄 */
handler: (...args: any[]) => any
): void
/** [CacheManager.start()](https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.start.html)
*
* 需要基础库: `2.24.0`
*
* 在插件中使用:不支持
*
* 开启缓存,仅在 mode 为 none 时生效,调用后缓存管理器的 state 会置为 1。 */
start(): void
/** [CacheManager.stop()](https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.stop.html)
*
* 需要基础库: `2.24.0`
*
* 在插件中使用:不支持
*
* 关闭缓存,仅在 mode 为 none 时生效,调用后缓存管理器的 state 会置为 0。 */
stop(): void
/** [Object CacheManager.match(Object evt)](https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.match.html)
*
* 需要基础库: `2.24.0`
*
* 在插件中使用:不支持
*
* 匹配命中的缓存规则,一般需要和 request 事件搭配使用。
*
* **示例代码**
*
* ```js
function handler(evt) {
const cache = cacheManager.match(evt)
// 若有重复监听,则取第一个 handler 返回的 promise
return new Promise((resolve, reject) => {
if (cache.data) {
resolve(cache.data)
} else {
reject('no cache')
}
})
}
cacheManager.on('request', handler)
``` */
match(
/** request 事件对象 */
evt: IAnyObject
): MatchCache
/** [string CacheManager.addRule(string|RegExp|Record.<string, any> rule)](https://developers.weixin.qq.com/miniprogram/dev/api/storage/cachemanager/CacheManager.addRule.html)
*
* 需要基础库: `2.24.0`
*
* 在插件中使用:不支持
*
* 添加规则。
*
* **规则说明**
*
* 支持的规则写法有字符串、正则和对象三种:
*
* ### 字符串写法
*
* 1. `addRule('/abc')`:纯 uri 串。
* 2. `addRule('GET /abc'):带方法的 uri 串,除了匹配 uri 外,还会匹配请求方法。如例子中必须是 GET 方法请求才会被匹配。
* 3. `addRule('/abc/:id'):带可变部分的 uri 串,id 可以是任意符合标准的字符串,表示这一段可以动态变化。比如 `/abc/123` 和 `/abc/321` 都会被匹配,而 `/abc/123/xxx` 因为多了一段,就不会被匹配。
* 4. `addRule('/abc?aa'):带 query 参数的 uri 串,包含 aa 参数,值可以为任意值。比如 `/abc?aa=haha` 会被匹配,但是 `/abc` 就不会被匹配,因为缺少规则中声明的 aa 参数;不过如果请求是 `/abc?aa=haha&bb=123`,虽然多带了 bb 参数,但是因为包含了 aa 参数,所以也可以被匹配。
* 5. `addRule('/abc?dd=haha'):带 query 参数的 uri 串,包含 dd 参数且值为 haha。比如 `/abc?dd=haha` 和 `/abc?dd=haha&bb=123` 会被匹配,而 `/abc?dd=123` 就不会被匹配,因为规则要求了 dd 参数的值。
*
* > 以上写法中的 uri 串如果只有 path 部分,则会取全局 origin 进行补全。比如全局 origin 是 `https://weixin.qq.com`,而规则是 `/abc`,则会补全为 `https://weixin.qq.com/abc`。因此在前面例子中 `addRule('/abc')` 和 `