Created
May 8, 2020 04:59
-
-
Save jhd124/b6e9e64bf1ccd994b9628eebe27f4412 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @fileoverview 包装小程序api接口, | |
* 用途: | |
* 使项目代码中不包含wx, 便于移植到其他平台 | |
* 异步方法包装成promise | |
* 添加一些逻辑 | |
* | |
* 所有必填参数单独作为参数列出,可选参数放在一个options对象里,例如: | |
* wx.showToast(options), options.title是一定要有的, 所以包装后的函数为 | |
* function(title, options){ | |
* return asyncPromisify(wx.showToast, {title, ...options}) | |
* } | |
* | |
* @author hjing | |
* @see https://developers.weixin.qq.com/miniprogram/dev/api/ | |
*/ | |
import { assert, validateEnumType } from "./util"; | |
import { IS_TEST, getConfig, getCurrentEnv } from "src/config"; | |
// FIXME: ezhou | |
!IS_TEST && wx.cloud.init({ env: getConfig("wx_cloud_env", getCurrentEnv()) }); | |
const AuthenticationScope = { | |
USER_INFO: "scope.userInfo", | |
USER_LOCATION: "scope.userLocation", | |
ADDRESS: "scope.address", | |
INVOICE_TITLE: "scope.invoiceTitle", | |
INVOICE: "scope.invoice", | |
WERUN: "scope.werun", | |
RECORD: "scope.record", | |
WRITE_PHOTOS_ALBUM: "scope.writePhotosAlbum", | |
CAMERA: "scope.camera", | |
}; | |
const AuthorizationConfig = { | |
[AuthenticationScope.USER_INFO]: { | |
title: "", | |
content: "", | |
}, | |
[AuthenticationScope.USER_LOCATION]: { | |
title: "授权当前位置", | |
content: "需要获取您的地理位置,请确认授权,否则功能将无法使用", | |
}, | |
[AuthenticationScope.ADDRESS]: { | |
title: "", | |
content: "", | |
}, | |
[AuthenticationScope.INVOICE_TITLE]: { | |
title: "", | |
content: "", | |
}, | |
[AuthenticationScope.INVOICE]: { | |
title: "", | |
content: "", | |
}, | |
[AuthenticationScope.WERUN]: { | |
title: "", | |
content: "", | |
}, | |
[AuthenticationScope.RECORD]: { | |
title: "", | |
content: "", | |
}, | |
[AuthenticationScope.WRITE_PHOTOS_ALBUM]: { | |
title: "", | |
content: "", | |
}, | |
[AuthenticationScope.CAMERA]: { | |
title: "", | |
content: "", | |
}, | |
}; | |
function _asyncApiPromisify(func, otherParams) { | |
return new Promise(function (resolve, reject) { | |
func({ | |
...otherParams, | |
success: resolve, | |
fail: reject, | |
}); | |
}); | |
} | |
let _systemInfo; // 首次加载后缓存 | |
const _defaultSystemInfo = { // 默认的SystemInfo 防止某些意外情况导致无法获取到SystemInfo | |
brand: "", | |
model: "", | |
pixelRatio: 2, | |
windowWidth: 414, | |
windowHeight: 800, | |
screenHeight: 800, | |
screenWidth: 414, | |
statusBarHeight: 44, | |
platform: null, | |
version: null, | |
system: null, | |
SDKVersion: "2.3.0", // 我们设置的线上最低基础库版本 | |
benchmarkLevel: -1, | |
language: "en", | |
fontSizeSetting: 16, | |
safeArea: { | |
right: 414, | |
bottom: 896, | |
left: 0, | |
top: 44, | |
width: 414, | |
height: 852, | |
}, | |
}; | |
/** | |
* @param {object} options 选项 | |
* @param {boolean} options.noCache 是否不从缓存获取 | |
* tabBar页面和非tabBar页面取得的窗口高度是不一样的,若要获取windowHeight,不应使用缓存 | |
*/ | |
function getSystemInfo(options) { | |
const { noCache } = options || {}; | |
return new Promise(resolve => { | |
if (_systemInfo === void 0 || noCache) { | |
wx.getSystemInfo({ | |
success: systemInfo => { | |
_systemInfo = systemInfo; | |
resolve(systemInfo); | |
}, | |
fail: () => { | |
resolve(_defaultSystemInfo); | |
}, | |
}); | |
} else { | |
resolve(_systemInfo); | |
} | |
}); | |
} | |
/** | |
* @param {object} options 选项 | |
* @param {boolean} options.noCache 是否不从缓存获取 | |
* tabBar页面和非tabBar页面取得的窗口高度是不一样的,若要获取windowHeight,不应使用缓存 | |
*/ | |
function getSystemInfoSync(options) { | |
const { noCache } = options || {}; | |
if (_systemInfo === void 0 || noCache) { | |
try { | |
_systemInfo = wx.getSystemInfoSync(); // ANCHOR cost ~=5 ms on iPhone6s | |
} catch (error) { | |
return _defaultSystemInfo; | |
} | |
} | |
return _systemInfo; | |
} | |
// route | |
function switchTab(url) { | |
assert(url, "Missing url"); | |
return _asyncApiPromisify(wx.switchTab, { | |
url, | |
}); | |
} | |
function reLaunch(url) { | |
assert(url, "Missing url"); | |
return _asyncApiPromisify(wx.reLaunch, { | |
url, | |
}); | |
} | |
function redirectTo(url) { | |
assert(url, "Missing url"); | |
return _asyncApiPromisify(wx.redirectTo, { | |
url, | |
}); | |
} | |
/** | |
* @see https://developers.weixin.qq.com/miniprogram/dev/api/route/wx.navigateTo.html | |
* @param {object} [options] | |
* @param {object} [options.events] 页面间通信接口,用于监听被打开页面发送到当前页面的数据。基础库 2.7.3 开始支持。 | |
*/ | |
function navigateTo(url, options) { | |
assert(url, "Missing url"); | |
return _asyncApiPromisify(wx.navigateTo, { | |
url, | |
...options, | |
}); | |
} | |
function navigateBack(options) { | |
return _asyncApiPromisify(wx.navigateBack, { | |
...options, | |
}); | |
} | |
// interaction | |
const ToastIconType = { | |
NONE: "none", | |
SUCCESS: "success", | |
LOADING: "loading", | |
}; | |
/** | |
* @param {string} title 提示的内容 | |
* @param {object} [options] | |
* @param {string} [options.icon="none"] 图标 | |
* @param {string} [options.image] 自定义图标的本地路径,image 的优先级高于 icon | |
* @param {number} [options.duration=1500] 提示的延迟时间 | |
* @param {boolean=false} [options.mask=false] 是否显示透明蒙层,防止触摸穿透 | |
*/ | |
function showToast(title, options) { | |
assert(title, "Missing title"); | |
return _asyncApiPromisify(wx.showToast, { | |
title, | |
icon: ToastIconType.NONE, | |
...options, | |
}); | |
} | |
/** | |
* @param {object} [options] | |
* @param {string} [options.title] 提示的标题 | |
* @param {string} [options.content] 提示的内容 | |
* @param {boolean} [options.showCancel=true] 是否显示取消按钮 | |
* @param {string} [options.cancelText] 取消按钮的文字,最多 4 个字符 | |
* @param {string} [options.cancelColor] 取消按钮的文字颜色,必须是 16 进制格式的颜色字符串 | |
* @param {string} [options.confirmText] 确认按钮的文字,最多 4 个字符 | |
* @param {string} [options.confirmColor] 确认按钮的文字颜色,必须是 16 进制格式的颜色字符串 | |
* @param {string} [options.success] 点击button的callback | |
*/ | |
function showModal(options) { | |
return wx.showModal(options); | |
} | |
/** | |
* @param {string} title 提示的内容 | |
* @param {boolean=false} [options.mask=false] 是否显示透明蒙层,防止触摸穿透 | |
*/ | |
function showLoading(title, options) { | |
// assert(title, "Missing title"); | |
return _asyncApiPromisify(wx.showLoading, { | |
title, | |
...options, | |
}); | |
} | |
/** | |
* @param {array} itemList 按钮的文字数组,数组长度最大为 6 | |
* @param {boolean=false} [options.itemColor=#000000] 按钮的文字颜色 | |
*/ | |
function showActionSheet(itemList, options) { | |
assert(itemList, "Missing itemList"); | |
return _asyncApiPromisify(wx.showActionSheet, { | |
itemList, | |
...options, | |
}); | |
} | |
function hideToast() { | |
return _asyncApiPromisify(wx.hideToast); | |
} | |
function hideLoading() { | |
return _asyncApiPromisify(wx.hideLoading); | |
} | |
// nav bar | |
function showNavigationBarLoading() { | |
return _asyncApiPromisify(wx.showNavigationBarLoading); | |
} | |
function setNavigationBarTitle(title) { | |
assert(title, "Missing title"); | |
return _asyncApiPromisify(wx.setNavigationBarTitle, { | |
title, | |
}); | |
} | |
/** | |
* @param {string} frontColor 前景颜色值,包括按钮、标题、状态栏的颜色,仅支持 #ffffff 和 #000000 | |
* @param {string} backgroundColor 背景颜色值,有效值为十六进制颜色 | |
* @param {object} [animation] 动画效果 | |
* @see https://developers.weixin.qq.com/miniprogram/dev/api/ui/navigation-bar/wx.setNavigationBarColor.html | |
*/ | |
function setNavigationBarColor(frontColor, backgroundColor, options) { | |
assert(frontColor, "Missing frontColor"); | |
assert(backgroundColor, "Missing frontColor"); | |
return _asyncApiPromisify(wx.setNavigationBarColor, { | |
frontColor, | |
backgroundColor, | |
...options, | |
}); | |
} | |
function hideNavigationBarLoading() { | |
return _asyncApiPromisify(wx.hideNavigationBarLoading); | |
} | |
/** | |
* 基础库 2.8.3 开始支持,低版本需做兼容处理 | |
*/ | |
function hideHomeButton() { | |
return _asyncApiPromisify(wx.hideHomeButton); | |
} | |
const BackgroundTextStyleType = { | |
DARK: "dark", | |
LIGHT: "light", | |
}; | |
/** | |
* @param {string} textStyle 下拉背景字体、loading 图的样式。仅支持dark和light | |
*/ | |
function setBackgroundTextStyle(textStyle) { | |
assert(textStyle, "Missing textStyle"); | |
validateEnumType(textStyle, BackgroundTextStyleType); | |
return _asyncApiPromisify(wx.setBackgroundTextStyle, { | |
textStyle, | |
}); | |
} | |
/** | |
* @param {object} [options] | |
* @param {string} [options.backgroundColor] 窗口的背景色,必须为十六进制颜色值 | |
* @param {string} [options.backgroundColorTop] 顶部窗口的背景色,必须为十六进制颜色值,仅 iOS 支持 | |
* @param {string} [options.backgroundColorBottom] 底部窗口的背景色,必须为十六进制颜色值,仅 iOS 支持 | |
*/ | |
function setBackgroundColor(options) { | |
return _asyncApiPromisify(wx.setBackgroundColor, options); | |
} | |
function showTabBarRedDot(index) { | |
return _asyncApiPromisify(wx.showTabBarRedDot, { | |
index, | |
}); | |
} | |
/** | |
* @param {boolean} [animation = false] 是否需要动画效果 | |
*/ | |
function showTabBar(animation) { | |
return _asyncApiPromisify(wx.showTabBar, { | |
animation, | |
}); | |
} | |
/** | |
* @param {boolean} [animation = false] 是否需要动画效果 | |
*/ | |
function hideTabBar(animation) { | |
return _asyncApiPromisify(wx.hideTabBar, { | |
animation, | |
}); | |
} | |
/** | |
* @param {object} [options] | |
* @param {string} [options.color] tab 上的文字默认颜色,HexColor | |
* @param {string} [options.selectedColor] tab 上的文字选中时的颜色,HexColor | |
* @param {string} [options.backgroundColor] tab 的背景色,HexColor | |
* @param {string} [options.borderStyle] tabBar上边框的颜色, 仅支持 black/white | |
*/ | |
function setTabBarStyle(options) { | |
return _asyncApiPromisify(wx.setTabBarStyle, options); | |
} | |
/** | |
* @param {number} index tabBar 的哪一项,从左边算起 | |
* @param {string} [options.text] tab 上的按钮文字 | |
* @param {string} [options.iconPath] 图片路径,icon 大小限制为 40kb,建议尺寸为 81px * 81px,当 postion 为 top 时,此参数无效 | |
* @param {string} [options.selectedIconPath] 选中时的图片路径,icon 大小限制为 40kb,建议尺寸为 81px * 81px ,当 postion 为 top 时,此参数无效 | |
*/ | |
function setTabBarItem(index, options) { | |
assert(index, "Missing index"); | |
return _asyncApiPromisify(wx.setTabBarItem, { | |
index, | |
...options, | |
}); | |
} | |
function setTabBarBadge(index, text) { | |
assert(index, "Missing index"); | |
assert(text, "Missing text"); | |
return _asyncApiPromisify(wx.setTabBarBadge, { | |
index, | |
text, | |
}); | |
} | |
function removeTabBarBadge(index) { | |
assert(index, "Missing index"); | |
return _asyncApiPromisify(wx.removeTabBarBadge, { | |
index, | |
}); | |
} | |
function hideTabBarRedDot(index) { | |
assert(index, "Missing index"); | |
return _asyncApiPromisify(wx.hideTabBarRedDot, { | |
index, | |
}); | |
} | |
/** | |
* @param {string} family 定义的字体名称 | |
* @param {string} source 字体资源的地址。建议格式为 TTF 和 WOFF,WOFF2 在低版本的iOS上会不兼容。 | |
* @param {object} [options] | |
* @param {object} [options.desc] 可选的字体描述符 | |
* @see https://developers.weixin.qq.com/miniprogram/dev/api/ui/font/wx.loadFontFace.html | |
*/ | |
function loadFontFace(family, source, options) { | |
assert(family, "Missing family"); | |
assert(source, "Missing source"); | |
return _asyncApiPromisify(wx.loadFontFace, { | |
family, | |
source, | |
...options, | |
}); | |
} | |
function stopPullDownRefresh() { | |
return _asyncApiPromisify(wx.stopPullDownRefresh); | |
} | |
function startPullDownRefresh() { | |
return _asyncApiPromisify(wx.startPullDownRefresh); | |
} | |
/** | |
* 将页面滚动到目标位置,支持选择器和滚动距离两种方式定位 | |
* @param {object} [options] | |
* @param {number} [options.scrollTop] 滚动到页面的目标位置,单位 px | |
* @param {number} [options.duration] 滚动动画的时长,单位 ms | |
* @param {string} [options.selector] 选择器 | |
* @see https://developers.weixin.qq.com/miniprogram/dev/api/ui/scroll/wx.pageScrollTo.html | |
*/ | |
function pageScrollTo(options) { | |
return _asyncApiPromisify(wx.pageScrollTo, options); | |
} | |
function setTopBarText(title) { | |
assert(title, "Missing title"); | |
return _asyncApiPromisify(wx.setTopBarText, { | |
title, | |
}); | |
} | |
/** | |
* 基础库 2.8.2 开始支持,低版本需做兼容处理 | |
* 在input、textarea等focus拉起键盘之后,手动调用此接口收起键盘 | |
*/ | |
function hideKeyboard() { | |
return _asyncApiPromisify(wx.hideKeyboard); | |
} | |
function getSelectedTextRange() { | |
return _asyncApiPromisify(wx.getSelectedTextRange); | |
} | |
const RequestResponseType = { | |
TEXT: "text", | |
ARRAY_BUFFER: "arrayBuffer", | |
}; | |
/** | |
* 发起 HTTPS 网络请求。使用前请注意阅读相关说明。 | |
* @see https://developers.weixin.qq.com/miniprogram/dev/api/network/request/wx.request.html | |
* @param {string} url 开发者服务器接口地址 | |
* @param {object} [options] | |
* @param {string/object/array/buffer} [options.data] 请求的参数 | |
* @param {object} [options.header] 设置请求的 header,header 中不能设置 Referer。 content-type 默认为 application/json | |
* @param {string} [options.method=GET] HTTP 请求方法 | |
* @param {string} [options.dataType=json] 返回的数据格式 | |
* @param {string} [options.responseType=text] 响应的数据类型 | |
* @return {UploadTask} | |
*/ | |
function request(url, options) { | |
assert(url, "Missing url"); | |
const { | |
method = "GET", | |
body, | |
header, | |
responseType = "text", | |
dataType = "json", | |
} = options || {}; | |
return _asyncApiPromisify(wx.request, { | |
url, | |
method, | |
data: body, | |
header, | |
responseType, | |
dataType, | |
}); | |
} | |
/** | |
* 下载文件资源到本地。客户端直接发起一个 HTTPS GET 请求,返回文件的本地临时路径 (本地路径),单次下载允许的最大文件为 50MB。使用前请注意阅读相关说明。 | |
* 注意:请在服务端响应的 header 中指定合理的 Content-Type 字段,以保证客户端正确处理文件类型。 | |
* @see https://developers.weixin.qq.com/miniprogram/dev/api/network/download/wx.downloadFile.html | |
* @param {object} [options] | |
* @param {object} [options.header] HTTP 请求的 Header,Header 中不能设置 Referer | |
* @param {string} [options.filePath] 指定文件下载后存储的路径 (本地路径) | |
* @return {DownloadTask} DownloadTask | |
*/ | |
export function downloadFile(url, options) { | |
assert(url, "Missing url"); | |
return _asyncApiPromisify(wx.downloadFile, { | |
url, | |
...options, | |
}); | |
} | |
/** | |
* 将本地资源上传到服务器。客户端发起一个 HTTPS POST 请求,其中 content-type 为 multipart/form-data。使用前请注意阅读相关说明。 | |
* @see https://developers.weixin.qq.com/miniprogram/dev/api/network/upload/wx.uploadFile.html | |
* @param {string} filePath 要上传文件资源的路径 (网络路径) | |
* @param {string} name 文件对应的 key,开发者在服务端可以通过这个 key 获取文件的二进制内容 | |
* @param {object} [options] | |
* @param {object} [options.header] HTTP 请求 Header,Header 中不能设置 Referer | |
* @param {object} [options.formData] HTTP 请求中其他额外的 form data | |
* @return {UploadTask} UploadTask | |
*/ | |
function uploadFile(url, filePath, name, options) { | |
assert(url, "Missing url"); | |
assert(filePath, "Missing filePath"); | |
assert(name, "Missing name"); | |
return _asyncApiPromisify(wx.uploadFile, { | |
url, filePath, name, ...options, | |
}); | |
} | |
// socket | |
function sendSocketMessage(data) { | |
return _asyncApiPromisify(wx.sendSocketMessage, { | |
data, | |
}); | |
} | |
/** | |
* 创建一个 WebSocket 连接。使用前请注意阅读相关说明。 | |
* @see https://developers.weixin.qq.com/miniprogram/dev/api/network/websocket/wx.connectSocket.html | |
* @param {string} url | |
* @param {object} [options] | |
* @param {header} [options.header] | |
* @param {array} [options.protocols] 子协议数组 | |
* @param {boolean} [options.tcpNoDelay=false] 建立 TCP 连接的时候的 TCP_NODELAY 设置 | |
* @param {boolean} [options.perMessageDeflate=false] 是否开启压缩扩展 | |
*/ | |
function connectSocket(url, options) { | |
assert(url, "Missing url"); | |
return _asyncApiPromisify(wx.connectSocket, { | |
url, | |
options, | |
}); | |
} | |
/** | |
* | |
* @param {object} [options] | |
* @param {number} [options.code=1000] 一个数字值表示关闭连接的状态号,表示连接被关闭的原因。1000(表示正常关闭连接) | |
* @param {string} [options.reason] 一个可读的字符串,表示连接被关闭的原因。这个字符串必须是不长于 123 字节的 UTF-8 文本(不是字符)。 | |
*/ | |
function closeSocket(options) { | |
return _asyncApiPromisify(wx.closeSocket, options); | |
} | |
// storage | |
/** | |
* 将数据存储在本地缓存中指定的 key 中。会覆盖掉原来该 key 对应的内容。除非用户主动删除或因存储空间原因被系统清理,否则数据都一直可用。单个 key 允许存储的最大数据长度为 1MB,所有数据存储上限为 10MB。 | |
* @param {string} key 本地缓存中指定的 key | |
* @param {any} data 需要存储的内容。只支持原生类型、Date、及能够通过JSON.stringify序列化的对象。 | |
*/ | |
function setStorage(key, data) { | |
assert(key, "Missing key"); | |
return _asyncApiPromisify(wx.setStorage, { | |
key, | |
data, | |
}); | |
} | |
function removeStorage(key) { | |
assert(key, "Missing key"); | |
return _asyncApiPromisify(wx.removeStorage, { | |
key, | |
}); | |
} | |
function getStorageInfo() { | |
return _asyncApiPromisify(wx.getStorageInfo); | |
} | |
function getStorage(key) { | |
assert(key, "Missing key"); | |
return _asyncApiPromisify(wx.getStorage, { key }) | |
.then(res => { | |
if (res) { | |
return res.data; | |
} | |
return; | |
}); | |
} | |
function getStorageSync(key) { | |
assert(key, "Missing key"); | |
return wx.getStorageSync(key); | |
} | |
function clearStorage() { | |
return _asyncApiPromisify(wx.clearStorage); | |
} | |
// 周期性更新 基础库 2.8.0 开始支持,低版本需做兼容处理 | |
function setBackgroundFetchToken(token) { | |
assert(token, "Missing token"); | |
return _asyncApiPromisify(wx.setBackgroundFetchToken, { | |
token, | |
}); | |
} | |
function onBackgroundFetchData() { | |
return _asyncApiPromisify(wx.onBackgroundFetchData); | |
} | |
function getBackgroundFetchToken() { | |
return _asyncApiPromisify(wx.getBackgroundFetchToken); | |
} | |
function getBackgroundFetchData(fetchType) { | |
assert(fetchType, "Missing fetchType"); | |
return _asyncApiPromisify(wx.getBackgroundFetchData, { | |
fetchType, | |
}); | |
} | |
/** | |
* 保存图片到系统相册。 | |
* @param {string} filePath 图片文件路径,可以是临时文件路径或永久文件路径 (本地路径) ,不支持网络路径 | |
* @param {function} [toSettingFunc] 跳转到指定setting页面 | |
*/ | |
function saveImageToPhotosAlbum(filePath, toSettingFunc) { | |
assert(filePath, "Missing filePath"); | |
return _asyncApiPromisify(wx.saveImageToPhotosAlbum, { | |
filePath, | |
}) | |
.then(() => { | |
showToast("保存成功", { icon: "success" }); | |
}) | |
.catch(e => { | |
const { errMsg } = e; | |
if (errMsg && errMsg.includes("auth deny")) { | |
showModal({ | |
title: "需要相册授权", | |
content: "请前往\"设置\"开启授权", | |
}).then(({ confirm }) => { | |
if (confirm) { | |
if (toSettingFunc) { | |
toSettingFunc(); | |
} else { | |
openSetting(); | |
} | |
} | |
}); | |
} else { | |
throw e; | |
} | |
}); | |
} | |
/** | |
* 在新页面中全屏预览图片。预览的过程中用户可以进行保存图片、发送给朋友等操作。 | |
* @param {array} urls 需要预览的图片链接列表。2.2.3 起支持云文件ID。 | |
* @param {object} [options] | |
* @param {string} [options.current] 当前显示图片的链接 | |
*/ | |
function previewImage(urls, options) { | |
assert(urls.length, "Missing urls"); | |
return _asyncApiPromisify(wx.previewImage, { | |
urls, | |
...options, | |
}); | |
} | |
function getImageInfo(src) { | |
assert(src, "Missing src"); | |
return _asyncApiPromisify(wx.getImageInfo, { | |
src, | |
}); | |
} | |
/** | |
* 压缩图片接口,可选压缩质量 | |
* @param {string} src 图片路径,图片的路径,支持本地路径、代码包路径 | |
* @param {object} [options] | |
* @param {number} [options.quality=80] 压缩质量,范围0~100,数值越小,质量越低,压缩率越高(仅对jpg有效)。 | |
*/ | |
function compressImage(src, options) { | |
assert(src, "Missing src"); | |
return _asyncApiPromisify(wx.compressImage, { | |
src, | |
...options, | |
}); | |
} | |
/** | |
* 从客户端会话选择文件。 | |
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/image/wx.chooseMessageFile.html | |
* @param {number} count 最多可以选择的文件个数,可以 0~100 | |
* @param {object} [options] | |
* @param {string} [options.type=all] 所选的文件的类型 | |
* @param {array} [options.extension] 根据文件拓展名过滤,仅 type==file 时有效。每一项都不能是空字符串。默认不过滤。 | |
*/ | |
function chooseMessageFile(count, options) { | |
return _asyncApiPromisify(wx.chooseMessageFile, { | |
count, | |
...options, | |
}); | |
} | |
/** | |
* 从相册选择图片 | |
* @see https://developers.weixin.qq.com/miniprogram/dev/api/media/image/wx.chooseImage.html | |
* @param {number} [count=9] 最多可以选择的文件个数 | |
* @param {object} [options] | |
* @param {array} [options.sizeType] 所选的图片的尺寸 | |
* @param {array} [options.sourceType] 选择图片的来源 | |
*/ | |
function chooseImage(options) { | |
return _asyncApiPromisify(wx.chooseImage, options); | |
} | |
// video | |
/** | |
* 保存视频到系统相册。支持mp4视频格式. | |
* @param {string} filePath 视频文件路径,可以是临时文件路径也可以是永久文件路径 (本地路径) | |
* @param {function} [toSettingFunc] 跳转到指定setting页面 | |
*/ | |
function saveVideoToPhotosAlbum(filePath, toSettingFunc) { | |
assert(filePath, "Missing filePath"); | |
return _asyncApiPromisify(wx.saveVideoToPhotosAlbum, { | |
filePath, | |
}) | |
.then(() => { | |
showToast("保存成功", { icon: "success" }); | |
}) | |
.cache(e => { | |
const { errMsg } = e; | |
if (errMsg.includes("auth deny")) { | |
showModal({ | |
title: "需要相册授权", | |
content: "请前往\"设置\"开启授权", | |
}).then(({ confirm }) => { | |
if (confirm) { | |
if (toSettingFunc) { | |
toSettingFunc(); | |
} else { | |
openSetting(); | |
} | |
} | |
}); | |
} | |
}); | |
} | |
/** | |
*拍摄视频或从手机相册中选视频。 | |
* @param {object} [options] | |
* @param {array} [options.sourceType=['album', 'camera']] 视频选择的来源 | |
* @param {number} [options.count] 视频选择的数量 | |
* @param {boolean} [options.compressed=true] 是否压缩所选择的视频文件 | |
* @param {number} [options.maxDuration=60] 拍摄视频最长拍摄时间,单位秒 | |
* @param {string} [options.camera='back'] 默认拉起的是前置或者后置摄像头。部分 Android 手机下由于系统 ROM 不支持无法生效 | |
*/ | |
function chooseVideo(options) { | |
return _asyncApiPromisify(wx.chooseVideo, options); | |
} | |
/** | |
* 设置 InnerAudioContext 的播放选项。设置之后对当前小程序全局生效。 | |
* @param {object} [options] | |
* @param {boolean} [options.mixWithOther=true] 是否与其他音频混播,设置为 true 之后,不会终止其他应用或微信内的音乐 | |
* @param {boolean} [options.obeyMuteSwitch=true] 仅在 iOS 生效)是否遵循静音开关,设置为 false 之后,即使是在静音模式下,也能播放声音 | |
*/ | |
function setInnerAudioOption(options) { | |
return _asyncApiPromisify(wx.setInnerAudioOption, options); | |
} | |
function getAvailableAudioSources() { | |
return _asyncApiPromisify(wx.getAvailableAudioSources); | |
} | |
// location | |
/** | |
* 基础库 2.8.0 开始支持,低版本需做兼容处理。 | |
* 关闭监听实时位置变化,前后台都停止消息接收 | |
*/ | |
function stopLocationUpdate() { | |
return _asyncApiPromisify(wx.stopLocationUpdate); | |
} | |
/** | |
* 基础库 2.8.0 开始支持,低版本需做兼容处理 | |
* 开启小程序进入前后台时均接收位置消息,需引导用户开启授权。授权以后,小程序在运行中或进入后台均可接受位置消息变化。 | |
*/ | |
function startLocationUpdateBackground(toSettingFunc) { | |
return _asyncApiPromisify(wx.startLocationUpdateBackground) | |
.catch(e => { | |
const { errMsg } = e; | |
if (errMsg && errMsg.includes("auth deny")) { | |
showModal({ | |
title: "需要授权位置", | |
content: "请前往\"设置\"开启授权", | |
}).then(({ confirm }) => { | |
if (confirm) { | |
if (toSettingFunc) { | |
toSettingFunc(); | |
} else { | |
openSetting(); | |
} | |
} | |
}); | |
} else { | |
throw e; | |
} | |
}); | |
} | |
function startLocationUpdate(toSettingFunc) { | |
return _asyncApiPromisify(wx.startLocationUpdate) | |
.catch(e => { | |
const { errMsg } = e; | |
if (errMsg && errMsg.includes("auth deny")) { | |
showModal({ | |
title: "需要授权位置", | |
content: "请前往\"设置\"开启授权", | |
}).then(({ confirm }) => { | |
if (confirm) { | |
if (toSettingFunc) { | |
toSettingFunc(); | |
} else { | |
openSetting(); | |
} | |
} | |
}); | |
} else { | |
throw e; | |
} | |
}); | |
} | |
/** | |
* @param {number} latitude 纬度,范围为-90~90,负数表示南纬。使用 gcj02 国测局坐标系 | |
* @param {number} longitude 经度,范围为-180~180,负数表示西经。使用 gcj02 国测局坐标系 | |
* @param {object} [options] | |
* @param {number} [options.scale=18] 缩放比例,范围5~18 | |
* @param {string} [options.name] 位置名 | |
* @param {string} [options.address] 地址的详细说明 | |
*/ | |
function openLocation(latitude, longitude, options) { | |
assert(latitude >= -90 && latitude <= 90, `Invalid latitude: ${latitude}`); | |
assert(longitude >= -180 && longitude <= 180, `Invalid longitude: ${longitude}`); | |
return _asyncApiPromisify(wx.openLocation, { | |
latitude, | |
longitude, | |
...options, | |
}); | |
} | |
/** | |
* 获取当前的地理位置、速度。当用户离开小程序后,此接口无法调用。开启高精度定位,接口耗时会增加,可指定 highAccuracyExpireTime 作为超时时间。 | |
* @param {object} [options] | |
* @param {string} [options.type="wgs84"] wgs84 返回 gps 坐标,gcj02 返回可用于 wx.openLocation 的坐标 | |
* @param {string} [options.altitude=false] 传入 true 会返回高度信息,由于获取高度需要较高精确度,会减慢接口返回速度 | |
* @param {boolean} [options.isHighAccuracy=false] 开启高精度定位 | |
* @param {number} [options.highAccuracyExpireTime] 高精度定位超时时间(ms),指定时间内返回最高精度,该值3000ms以上高精度定位才有效果 | |
*/ | |
function getLocation(options) { | |
return _asyncApiPromisify(wx.getLocation, { | |
...options, | |
}); | |
} | |
/** | |
* 选择地址 | |
* @param {String} latitude | |
* @param {String} longitude | |
*/ | |
function chooseLocation(latitude, longitude) { | |
return new Promise((resolve, reject) => { | |
wx.chooseLocation({ | |
latitude, | |
longitude, | |
success: resolve, | |
fail: e => { | |
const { errMsg } = e; | |
if (errMsg && errMsg.includes("cancel")) { | |
resolve(); | |
} else { | |
reject(e); | |
} | |
}, | |
}); | |
}); | |
} | |
/** | |
* 基础库 1.2.0 开始支持,低版本需做兼容处理。 | |
* @param {object} [options] | |
* @param {boolean} [options.withShareTicket=false] 是否使用带 shareTicket 的转发详情 | |
* @param {boolean} [options.isUpdatableMessage=false] 是否是动态消息,详见动态消息 | |
* @param {string} [options.activityId] 动态消息的 activityId。通过 updatableMessage.createActivityId 接口获取 | |
* @param {object} [options.templateInfo] 动态消息的模板信息 | |
*/ | |
function updateShareMenu(options) { | |
return _asyncApiPromisify(wx.updateShareMenu, options); | |
} | |
function showShareMenu(withShareTicket) { | |
return _asyncApiPromisify(wx.showShareMenu, { | |
withShareTicket, | |
}); | |
} | |
function hideShareMenu() { | |
return _asyncApiPromisify(wx.hideShareMenu); | |
} | |
/** | |
* 获取转发详细信息 | |
* @param {string} shareTicket | |
* @param {object} [options] | |
* @param {number} [options.timeout] 超时时间,单位 ms | |
*/ | |
function getShareInfo(shareTicket, options) { | |
assert(shareTicket, "Missing shareTicket"); | |
return _asyncApiPromisify(wx.getShareInfo, { | |
shareTicket, | |
...options, | |
}); | |
} | |
/** | |
* 把当前画布指定区域的内容导出生成指定大小的图片。在 draw() 回调里调用该方法才能保证图片导出成功。 | |
* @param {object} [options] | |
* @param {number} [options.x=0] 指定的画布区域的左上角横坐标 | |
* @param {number} [options.y=0] 指定的画布区域的左上角纵坐标 | |
* @param {number} [options.width=canvas宽度-x] 指定的画布区域的宽度 | |
* @param {number} [options.height=canvas高度-y] 指定的画布区域的高度 | |
* @param {number} [options.destWidth=width*屏幕像素密度] 输出的图片的宽度 | |
* @param {number} [options.destHeight=height*屏幕像素密度] 输出的图片的高度 | |
* @param {string} [options.canvasId] 画布标识,传入 canvas 组件的 canvas-id | |
* @param {string} [options.canvas] 画布标识,传入 canvas 组件实例 (canvas type="2d" 时使用该属性) | |
* @param {string} [options.fileType=png] 目标文件的类型 | |
* @param {number} [options.quality] 图片的质量,目前仅对 jpg 有效。取值范围为 (0, 1],不在范围内时当作 1.0 处理。 | |
*/ | |
function canvasToTempFilePath(options) { | |
return _asyncApiPromisify(wx.canvasToTempFilePath, options); | |
} | |
/** | |
* 将像素数据绘制到画布。在自定义组件下,第二个参数传入自定义组件实例 this,以操作组件内 <canvas> 组件 | |
* @param {object} options | |
* @param {string} options.canvasId 画布标识,传入 canvas 组件的 canvas-id 属性。 | |
* @param {Uint8ClampedArray} options.data 图像像素点数据,一维数组,每四项表示一个像素点的 rgba | |
* @param {number} options.x 源图像数据在目标画布中的位置偏移量(x 轴方向的偏移量) | |
* @param {number} options.y 源图像数据在目标画布中的位置偏移量(y 轴方向的偏移量) | |
* @param {number} options.width 源图像数据矩形区域的宽度 | |
* @param {number} options.height 源图像数据矩形区域的高度 | |
*/ | |
function canvasPutImageData(options) { | |
return _asyncApiPromisify(wx.canvasPutImageData, options); | |
} | |
/** | |
* 获取 canvas 区域隐含的像素数据。 | |
* @param {object} options | |
* @param {string} options.canvasId 画布标识,传入 canvas 组件的 canvas-id 属性。 | |
* @param {number} options.x 将要被提取的图像数据矩形区域的左上角横坐标 | |
* @param {number} options.y 将要被提取的图像数据矩形区域的左上角纵坐标 | |
* @param {number} options.width 将要被提取的图像数据矩形区域的宽度 | |
* @param {number} options.height 将要被提取的图像数据矩形区域的高度 | |
*/ | |
function canvasGetImageData(options) { | |
return _asyncApiPromisify(wx.canvasGetImageData, options); | |
} | |
function saveFile(tempFilePath) { | |
assert(tempFilePath, "Missing tempFilePath"); | |
return _asyncApiPromisify(wx.saveFile, { | |
tempFilePath, | |
}); | |
} | |
function removeSavedFile(filePath) { | |
assert(filePath, "Missing filePath"); | |
return _asyncApiPromisify(wx.removeSavedFile, { | |
filePath, | |
}); | |
} | |
/** | |
* | |
* @param {string} filePath 文件路径 | |
* @param {object} [options] | |
* @param {string} [options.fileType] 文件类型,指定文件类型打开文件 | |
*/ | |
function openDocument(filePath, options) { | |
assert(filePath, "Missing filePath"); | |
return _asyncApiPromisify(wx.openDocument, { | |
filePath, | |
...options, | |
}); | |
} | |
function getSavedFileList() { | |
return _asyncApiPromisify(wx.getSavedFileList); | |
} | |
function getSavedFileInfo(filePath) { | |
assert(filePath, "Missing filePath"); | |
return _asyncApiPromisify(wx.getSavedFileInfo, { | |
filePath, | |
}); | |
} | |
/** | |
* | |
* @param {string} filePath | |
* @param {object} [options] | |
* @param {string} [options.digestAlgorithm=md5] 计算文件摘要的算法 | |
*/ | |
function getFileInfo(filePath, options) { | |
assert(filePath, "Missing filePath"); | |
return _asyncApiPromisify(wx.getFileInfo, { | |
filePath, | |
...options, | |
}); | |
} | |
/** | |
* | |
* @param {object} [options] | |
* @param {number} [options.timeout] 超时时间,单位ms | |
*/ | |
function login(options) { | |
return _asyncApiPromisify(wx.login, options); | |
} | |
function checkSession() { | |
return _asyncApiPromisify(wx.checkSession); | |
} | |
/** | |
* 打开另一个小程序 | |
* @param {string} appId 要打开的小程序的appId | |
* @param {object} [options] | |
* @param {string} [options.path] 打开的页面路径,如果为空则打开首页。 | |
* @param {object} [options.extraData] 需要传递给目标小程序的数据,目标小程序可在 App.onLaunch,App.onShow 中获取到这份数据 | |
* @param {string} [options.envVersion=release] 要打开的小程序版本。仅在当前小程序为开发版或体验版时此参数有效。如果当前小程序是正式版,则打开的小程序必定是正式版。 | |
*/ | |
function navigateToMiniProgram(appId, options) { | |
assert(appId, "Missing appId"); | |
return _asyncApiPromisify(wx.navigateToMiniProgram, { | |
appId, | |
...options, | |
}); | |
} | |
/** | |
* 返回到上一个小程序。只有在当前小程序是被其他小程序打开时可以调用成功 | |
* @param {object} options | |
* @param {object} extraData 需要返回给上一个小程序的数据,上一个小程序可在 App.onShow 中获取到这份数据 | |
*注意:微信客户端 iOS 6.5.9,Android 6.5.10 及以上版本支持 | |
*/ | |
function navigateBackMiniProgram(options) { | |
return _asyncApiPromisify(wx.navigateBackMiniProgram, options); | |
} | |
/** | |
* 发起微信支付。了解更多信息,请查看微信支付接口文档 | |
* @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/payment/wx.requestPayment.html | |
* @param {object} options | |
* @param {string} options.timeStamp 时间戳,从 1970 年 1 月 1 日 00:00:00 至今的秒数,即当前的时间 | |
* @param {string} options.nonceStr 随机字符串,长度为32个字符以下 | |
* @param {string} options.package 统一下单接口返回的 prepay_id 参数值,提交格式如:prepay_id=*** | |
* @param {string} options.paySign 签名,具体签名方案参见 小程序支付接口文档 | |
* @param {string} [options.signType=md5] 签名算法 | |
*/ | |
function requestPayment(options) { | |
return _asyncApiPromisify(wx.requestPayment, options); | |
} | |
function chooseAddress() { | |
return _asyncApiPromisify(wx.chooseAddress); | |
} | |
/** | |
* @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/subscribe-message/wx.requestSubscribeMessage.html | |
* @param {array} tmplIds 需要订阅的消息模板的id的集合,一次调用最多可订阅3条消息 | |
*/ | |
function requestSubscribeMessage(tmplIds, options) { | |
assert(tmplIds.length, "Missing tmplIds"); | |
return _asyncApiPromisify(wx.requestSubscribeMessage, { | |
tmplIds, | |
...options, | |
}); | |
} | |
function setClipboardData(data) { | |
return _asyncApiPromisify(wx.setClipboardData, { | |
data, | |
}); | |
} | |
function getClipboardData() { | |
return _asyncApiPromisify(wx.getClipboardData); | |
} | |
function getScreenBrightness() { | |
return _asyncApiPromisify(wx.getScreenBrightness); | |
} | |
function setKeepScreenOn(keepScreenOn) { | |
return _asyncApiPromisify(wx.setKeepScreenOn, { | |
keepScreenOn, | |
}); | |
} | |
function setScreenBrightness(value) { | |
return _asyncApiPromisify(wx.setScreenBrightness, { | |
value, | |
}); | |
} | |
function makePhoneCall(phoneNumber) { | |
assert(phoneNumber.length, "Missing phoneNumber"); | |
return _asyncApiPromisify(wx.makePhoneCall, { | |
phoneNumber, | |
}); | |
} | |
function vibrateShort() { | |
return _asyncApiPromisify(wx.vibrateShort); | |
} | |
function vibrateLong() { | |
return _asyncApiPromisify(wx.vibrateLong); | |
} | |
/** | |
* 调起客户端扫码界面进行扫码 | |
* @param {object} [options] | |
* @param {boolean} [options.onlyFromCamera] 是否只能从相机扫码,不允许从相册选择图片 | |
* @param {array} [options.scanType] 扫码类型 | |
*/ | |
function scanCode(options) { | |
return _asyncApiPromisify(wx.scanCode, options); | |
} | |
function getNetworkType() { | |
return _asyncApiPromisify(wx.getNetworkType); | |
} | |
function openSetting(options) { | |
return wx.openSetting(options); | |
} | |
function getSetting(options) { | |
return _asyncApiPromisify(wx.getSetting, options); | |
} | |
function authorize(options) { | |
assert(options, "Missing scope"); | |
return _asyncApiPromisify(wx.authorize, options); | |
} | |
function authorizeModal(authorizeScope) { | |
assert(authorizeScope, "Missing authorizeScope"); | |
const { title, content } = AuthorizationConfig[authorizeScope] || {}; | |
return new Promise((resolve, reject) => { | |
showModal({ | |
title, | |
content, | |
success: res => { | |
if (res.confirm) { | |
openSetting({ | |
success: data => { | |
if (data.authSetting[authorizeScope] === false) { | |
showToast({ | |
title: "授权失败", | |
icon: "none", | |
duration: 500, | |
}); | |
reject(data); | |
} else { | |
showToast({ | |
title: "授权成功", | |
icon: "none", | |
duration: 500, | |
}); | |
resolve(true); | |
} | |
}, | |
fail: reject, | |
}); | |
} | |
}, | |
fail: reject, | |
}); | |
}); | |
} | |
function getAuthorize(authorizeScope) { | |
assert(authorizeScope, "Missing authorizeScope"); | |
return new Promise((resolve, reject) => { | |
if (!AuthorizationConfig[authorizeScope]) { | |
reject(`找不到该权限${authorizeScope}`); | |
} | |
getSetting() | |
.then(res => { | |
if (!res.authSetting[authorizeScope]) { | |
authorize(authorizeScope) | |
.then(resolve) | |
.catch(err => { | |
if (!res.authSetting[authorizeScope] === undefined && /auth/.test(err.errMsg)) { | |
authorizeModal(authorizeScope).then(resolve).catch(reject); | |
} else { | |
reject(err); | |
} | |
}); | |
} else { | |
resolve(true); | |
} | |
}) | |
.catch(reject); | |
}); | |
} | |
async function getWxContext() { | |
return new Promise((resolve, reject) => { | |
wx.cloud.callFunction({ | |
name: "getWxContext", | |
}).then(res => { | |
resolve(res); | |
}).catch(err => { | |
reject(`get openId from wx.cloud error, ${JSON.stringify(err)}`); | |
}); | |
}); | |
} | |
// window.mp = mp 选择是否设为全局变量 | |
export const mp = { | |
// system | |
getSystemInfoSync, | |
getUpdateManager: wx.getUpdateManager, | |
getLaunchOptionsSync: wx.getLaunchOptionsSync, | |
// lifecycle | |
onPageNotFound: wx.onPageNotFound, | |
onError: wx.onError, | |
onAudioInterruptionEnd: wx.onAudioInterruptionEnd, | |
onAudioInterruptionBegin: wx.onAudioInterruptionBegin, | |
onAppShow: wx.onAppShow, | |
onAppHide: wx.onAppHide, | |
offPageNotFound: wx.offPageNotFound, | |
offError: wx.offError, | |
offAudioInterruptionEnd: wx.offAudioInterruptionEnd, | |
offAudioInterruptionBegin: wx.offAudioInterruptionBegin, | |
offAppShow: wx.offAppShow, | |
offAppHide: wx.offAppHide, | |
// debug | |
setEnableDebug: wx.setEnableDebug, | |
getRealtimeLogManager: wx.getRealtimeLogManager, | |
getLogManager: wx.getLogManager, | |
/* | |
* animation | |
* https://developers.weixin.qq.com/miniprogram/dev/api/ui/animation/wx.createAnimation.html | |
*/ | |
createAnimation: wx.createAnimation, | |
getMenuButtonBoundingClientRect: wx.getMenuButtonBoundingClientRect, | |
onWindowResize: wx.onWindowResize, // 2.3.0开始支持 | |
offWindowResize: wx.offWindowResize, | |
onKeyboardHeightChange: wx.onKeyboardHeightChange, // 基础库 2.7.0 开始支持 | |
// socket | |
onSocketOpen: wx.onSocketOpen, | |
onSocketMessage: wx.onSocketMessage, | |
onSocketError: wx.onSocketError, | |
onSocketClose: wx.onSocketClose, | |
// storage | |
setStorageSync: wx.setStorageSync, | |
removeStorageSync: wx.removeStorageSync, | |
getStorageSync, | |
getStorageInfoSync: wx.getStorageInfoSync, | |
clearStorageSync: wx.clearStorageSync, | |
createMapContext: wx.createMapContext, | |
createVideoContext: wx.createVideoContext, | |
// https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/AudioContext.html | |
createInnerAudioContext: wx.createInnerAudioContext, | |
// https://developers.weixin.qq.com/miniprogram/dev/api/media/background-audio/BackgroundAudioManager.html | |
getBackgroundAudioManager: wx.getBackgroundAudioManager, | |
// https://developers.weixin.qq.com/miniprogram/dev/api/media/recorder/wx.getRecorderManager.html | |
getRecorderManager: wx.getRecorderManager, | |
// https://developers.weixin.qq.com/miniprogram/dev/api/media/camera/wx.createCameraContext.html | |
createCameraContext: wx.createCameraContext, | |
// https://developers.weixin.qq.com/miniprogram/dev/api/media/video-processing/wx.createMediaContainer.html | |
createMediaContainer: wx.createMediaContainer, | |
// https://developers.weixin.qq.com/miniprogram/dev/api/location/wx.onLocationChange.html | |
onLocationChange: wx.onLocationChange, | |
offLocationChange: wx.offLocationChange, | |
createOffscreenCanvas: wx.createOffscreenCanvas, | |
createCanvasContext: wx.createCanvasContext, | |
getFileSystemManager: wx.getFileSystemManager, | |
getAccountInfoSync: wx.getAccountInfoSync, | |
onNetworkStatusChange: wx.onNetworkStatusChange, | |
offNetworkStatusChange: wx.offNetworkStatusChange, | |
onUserCaptureScreen: wx.onUserCaptureScreen, | |
offUserCaptureScreen: wx.offUserCaptureScreen, | |
onMemoryWarning: wx.onMemoryWarning, | |
offMemoryWarning: wx.offMemoryWarning, | |
createWorker: wx.createWorker, | |
createSelectorQuery: wx.createSelectorQuery, | |
createIntersectionObserver: wx.createIntersectionObserver, | |
getSystemInfo, | |
switchTab, | |
reLaunch, | |
redirectTo, | |
navigateTo, | |
navigateBack, | |
showLoading, | |
showToast, | |
showModal, | |
showActionSheet, | |
hideToast, | |
hideLoading, | |
showNavigationBarLoading, | |
setNavigationBarTitle, | |
setNavigationBarColor, | |
hideNavigationBarLoading, | |
hideHomeButton, | |
setBackgroundTextStyle, | |
setBackgroundColor, | |
showTabBarRedDot, | |
showTabBar, | |
hideTabBar, | |
setTabBarStyle, | |
setTabBarItem, | |
setTabBarBadge, | |
removeTabBarBadge, | |
hideTabBarRedDot, | |
loadFontFace, | |
stopPullDownRefresh, | |
startPullDownRefresh, | |
pageScrollTo, | |
setTopBarText, | |
hideKeyboard, | |
getSelectedTextRange, | |
request, | |
downloadFile, | |
uploadFile, | |
sendSocketMessage, | |
connectSocket, | |
closeSocket, | |
setStorage, | |
removeStorage, | |
getStorageInfo, | |
getStorage, | |
clearStorage, | |
setBackgroundFetchToken, | |
onBackgroundFetchData, | |
getBackgroundFetchToken, | |
getBackgroundFetchData, | |
saveImageToPhotosAlbum, | |
previewImage, | |
getImageInfo, | |
compressImage, | |
chooseMessageFile, | |
chooseImage, | |
saveVideoToPhotosAlbum, | |
chooseVideo, | |
setInnerAudioOption, | |
getAvailableAudioSources, | |
stopLocationUpdate, | |
startLocationUpdateBackground, | |
startLocationUpdate, | |
openLocation, | |
getLocation, | |
chooseLocation, | |
updateShareMenu, | |
showShareMenu, | |
hideShareMenu, | |
getShareInfo, | |
canvasToTempFilePath, | |
canvasPutImageData, | |
canvasGetImageData, | |
saveFile, | |
removeSavedFile, | |
openDocument, | |
getSavedFileList, | |
getSavedFileInfo, | |
getFileInfo, | |
login, | |
checkSession, | |
navigateToMiniProgram, | |
navigateBackMiniProgram, | |
requestPayment, | |
chooseAddress, | |
requestSubscribeMessage, | |
setClipboardData, | |
getClipboardData, | |
getScreenBrightness, | |
setKeepScreenOn, | |
setScreenBrightness, | |
makePhoneCall, | |
vibrateShort, | |
vibrateLong, | |
scanCode, | |
getNetworkType, | |
openSetting, | |
getSetting, | |
authorize, | |
authorizeModal, | |
getAuthorize, | |
// enum | |
ToastIconType, | |
BackgroundTextStyleType, | |
RequestResponseType, | |
AuthenticationScope, | |
getWxContext, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment