@tarojs/taro-h5 3.4.0-beta.0 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/ad/index.js +4 -0
- package/dist/api/ai/facial.js +5 -0
- package/dist/api/ai/index.js +2 -0
- package/dist/api/ai/visual.js +3 -0
- package/dist/api/alipay/index.js +3 -0
- package/dist/api/base/crypto.js +3 -0
- package/dist/api/base/debug.js +4 -0
- package/dist/api/base/index.js +17 -0
- package/dist/api/base/performance.js +4 -0
- package/dist/api/base/system/index.js +2 -0
- package/dist/api/base/system/info.js +57 -0
- package/dist/api/base/system/network.js +63 -0
- package/dist/api/base/update.js +4 -0
- package/dist/api/base/weapp/app-event.js +18 -0
- package/dist/api/base/weapp/life-cycle.js +4 -0
- package/dist/api/canvas/CanvasContext.js +191 -0
- package/dist/api/canvas/canvasGetImageData.js +25 -0
- package/dist/api/canvas/canvasPutImageData.js +22 -0
- package/dist/api/canvas/canvasToTempFilePath.js +22 -0
- package/dist/api/canvas/createCanvasContext.js +16 -0
- package/dist/api/canvas/index.js +8 -0
- package/dist/api/cloud/index.js +17 -0
- package/dist/api/data-analysis/index.js +5 -0
- package/dist/api/device/accelerometer.js +83 -0
- package/dist/api/device/accessibility.js +3 -0
- package/dist/api/device/battery.js +4 -0
- package/dist/api/device/bluetooth-ble.js +18 -0
- package/dist/api/device/bluetooth-peripheral.js +5 -0
- package/dist/api/device/bluetooth.js +15 -0
- package/dist/api/device/calendar.js +4 -0
- package/dist/api/device/clipboard.js +65 -0
- package/dist/api/device/compass.js +64 -0
- package/dist/api/device/contact.js +4 -0
- package/dist/api/device/crypto.js +3 -0
- package/dist/api/device/gyroscope.js +6 -0
- package/dist/api/device/iBeacon.js +9 -0
- package/dist/api/device/index.js +22 -0
- package/dist/api/device/keyboard.js +6 -0
- package/dist/api/device/memory.js +4 -0
- package/dist/api/device/motion.js +81 -0
- package/dist/api/device/nfc.js +9 -0
- package/dist/api/device/phone.js +24 -0
- package/dist/api/device/scan.js +6 -0
- package/dist/api/device/screen.js +8 -0
- package/dist/api/device/vibrate.js +35 -0
- package/dist/api/device/wifi.js +12 -0
- package/dist/api/ext/index.js +4 -0
- package/dist/api/files/index.js +10 -0
- package/dist/api/framework/index.js +7 -0
- package/dist/api/index.js +24 -0
- package/dist/api/location/chooseLocation.js +93 -0
- package/dist/api/location/index.js +13 -0
- package/dist/api/location/style.css +79 -0
- package/dist/api/media/audio/index.js +88 -0
- package/dist/api/media/background-audio.js +11 -0
- package/dist/api/media/camera.js +3 -0
- package/dist/api/media/editor.js +18 -0
- package/dist/api/media/image/chooseImage.js +74 -0
- package/dist/api/media/image/getImageInfo.js +31 -0
- package/dist/api/media/image/index.js +9 -0
- package/dist/api/media/image/previewImage.js +67 -0
- package/dist/api/media/index.js +13 -0
- package/dist/api/media/live.js +4 -0
- package/dist/api/media/map.js +3 -0
- package/dist/api/media/media-recorder.js +3 -0
- package/dist/api/media/recorder.js +5 -0
- package/dist/api/media/video/index.js +74 -0
- package/dist/api/media/video-decoder.js +3 -0
- package/dist/api/media/video-processing.js +3 -0
- package/dist/api/media/voip.js +16 -0
- package/dist/api/navigate/index.js +6 -0
- package/dist/api/network/download.js +124 -0
- package/dist/api/network/index.js +7 -0
- package/dist/api/network/mdns.js +12 -0
- package/dist/api/network/request/index.js +125 -0
- package/dist/api/network/tcp.js +3 -0
- package/dist/api/network/udp.js +3 -0
- package/dist/api/network/upload.js +151 -0
- package/dist/api/network/utils.js +65 -0
- package/dist/api/network/websocket/index.js +70 -0
- package/dist/api/network/websocket/socketTask.js +63 -0
- package/dist/api/open-api/account.js +3 -0
- package/dist/api/open-api/address.js +3 -0
- package/dist/api/open-api/authorize.js +4 -0
- package/dist/api/open-api/card.js +4 -0
- package/dist/api/open-api/channels-live.js +8 -0
- package/dist/api/open-api/customer-service.js +3 -0
- package/dist/api/open-api/facial.js +6 -0
- package/dist/api/open-api/favorites.js +4 -0
- package/dist/api/open-api/group.js +3 -0
- package/dist/api/open-api/index.js +18 -0
- package/dist/api/open-api/invoice.js +4 -0
- package/dist/api/open-api/license-plate.js +3 -0
- package/dist/api/open-api/login.js +5 -0
- package/dist/api/open-api/red-package.js +3 -0
- package/dist/api/open-api/settings.js +4 -0
- package/dist/api/open-api/soter.js +5 -0
- package/dist/api/open-api/subscribe-message.js +3 -0
- package/dist/api/open-api/user-info.js +4 -0
- package/dist/api/open-api/werun.js +4 -0
- package/dist/api/payment/index.js +4 -0
- package/dist/api/route/index.js +3 -0
- package/dist/api/share/index.js +12 -0
- package/dist/api/storage/background-fetch.js +6 -0
- package/dist/api/storage/index.js +157 -0
- package/dist/api/swan/index.js +26 -0
- package/dist/api/taro.js +47 -0
- package/dist/api/ui/animation/index.js +284 -0
- package/dist/api/ui/background.js +4 -0
- package/dist/api/ui/custom-component.js +3 -0
- package/dist/api/ui/fonts.js +3 -0
- package/dist/api/ui/index.js +12 -0
- package/dist/api/ui/interaction/actionSheet.js +188 -0
- package/dist/api/ui/interaction/index.js +268 -0
- package/dist/api/ui/interaction/modal.js +207 -0
- package/dist/api/ui/interaction/toast.js +195 -0
- package/dist/api/ui/menu.js +3 -0
- package/dist/api/ui/navigation-bar/index.js +42 -0
- package/dist/api/ui/pull-down-refresh.js +26 -0
- package/dist/api/ui/scroll/index.js +83 -0
- package/dist/api/ui/sticky.js +3 -0
- package/dist/api/ui/tab-bar.js +282 -0
- package/dist/api/ui/window.js +31 -0
- package/dist/api/utils/handler.js +80 -0
- package/dist/api/utils/index.js +148 -0
- package/dist/api/worker/index.js +3 -0
- package/dist/api/wxml/index.js +6 -0
- package/dist/api/wxml/nodesRef.js +42 -0
- package/dist/api/wxml/selectorQuery.js +201 -0
- package/dist/index.cjs.js +7852 -11638
- package/dist/index.js +4 -0
- package/dist/taroApis.js +1 -1
- package/dist/types/type.js +2 -0
- package/package.json +14 -16
- package/src/api/ad/index.ts +5 -0
- package/src/api/ai/facial.ts +6 -0
- package/src/api/ai/index.ts +2 -0
- package/src/api/ai/visual.ts +4 -0
- package/src/api/alipay/index.ts +4 -0
- package/src/api/base/crypto.ts +4 -0
- package/src/api/base/debug.ts +5 -0
- package/src/api/base/index.ts +23 -0
- package/src/api/base/performance.ts +5 -0
- package/src/api/base/system/index.ts +2 -0
- package/src/api/base/system/info.ts +64 -0
- package/src/api/base/system/network.ts +70 -0
- package/src/api/base/update.ts +5 -0
- package/src/api/base/weapp/app-event.ts +19 -0
- package/src/api/base/weapp/life-cycle.ts +5 -0
- package/src/api/canvas/CanvasContext.ts +233 -0
- package/src/api/canvas/canvasGetImageData.ts +27 -0
- package/src/api/canvas/canvasPutImageData.ts +24 -0
- package/src/api/canvas/canvasToTempFilePath.ts +24 -0
- package/src/api/canvas/createCanvasContext.ts +18 -0
- package/src/api/canvas/index.ts +10 -0
- package/src/api/cloud/index.ts +27 -0
- package/src/api/data-analysis/index.ts +6 -0
- package/src/api/device/accelerometer.ts +87 -0
- package/src/api/device/accessibility.ts +4 -0
- package/src/api/device/battery.ts +5 -0
- package/src/api/device/bluetooth-ble.ts +19 -0
- package/src/api/device/bluetooth-peripheral.ts +6 -0
- package/src/api/device/bluetooth.ts +16 -0
- package/src/api/device/calendar.ts +5 -0
- package/src/api/device/clipboard.ts +67 -0
- package/src/api/device/compass.ts +67 -0
- package/src/api/device/contact.ts +5 -0
- package/src/api/device/crypto.ts +4 -0
- package/src/api/device/gyroscope.ts +7 -0
- package/src/api/device/iBeacon.ts +10 -0
- package/src/api/device/index.ts +22 -0
- package/src/api/device/keyboard.ts +7 -0
- package/src/api/device/memory.ts +5 -0
- package/src/api/device/motion.ts +85 -0
- package/src/api/device/nfc.ts +10 -0
- package/src/api/device/phone.ts +30 -0
- package/src/api/device/scan.ts +7 -0
- package/src/api/device/screen.ts +9 -0
- package/src/api/device/vibrate.ts +36 -0
- package/src/api/device/wifi.ts +13 -0
- package/src/api/ext/index.ts +5 -0
- package/src/api/files/index.ts +11 -0
- package/src/api/framework/index.ts +10 -0
- package/src/api/index.ts +25 -0
- package/src/api/location/chooseLocation.ts +106 -0
- package/src/api/location/index.ts +19 -0
- package/src/api/location/style.css +8 -8
- package/src/api/media/audio/index.ts +105 -0
- package/src/api/media/background-audio.ts +12 -0
- package/src/api/media/camera.ts +4 -0
- package/src/api/media/editor.ts +29 -0
- package/src/api/media/image/chooseImage.ts +78 -0
- package/src/api/media/image/getImageInfo.ts +35 -0
- package/src/api/media/image/index.ts +13 -0
- package/src/api/media/image/previewImage.ts +80 -0
- package/src/api/media/index.ts +13 -0
- package/src/api/media/live.ts +5 -0
- package/src/api/media/map.ts +4 -0
- package/src/api/media/media-recorder.ts +4 -0
- package/src/api/media/recorder.ts +6 -0
- package/src/api/media/video/index.ts +82 -0
- package/src/api/media/video-decoder.ts +4 -0
- package/src/api/media/video-processing.ts +4 -0
- package/src/api/media/voip.ts +17 -0
- package/src/api/navigate/index.ts +7 -0
- package/src/api/{fileTransfer/downloadFile.js → network/download.ts} +16 -27
- package/src/api/network/index.ts +7 -0
- package/src/api/network/mdns.ts +13 -0
- package/src/api/{request/index.js → network/request/index.ts} +9 -6
- package/src/api/network/tcp.ts +4 -0
- package/src/api/network/udp.ts +4 -0
- package/src/api/{fileTransfer/uploadFile.js → network/upload.ts} +28 -32
- package/src/api/{fileTransfer/utils.js → network/utils.ts} +0 -0
- package/src/api/network/websocket/index.ts +88 -0
- package/src/api/{webSocket/socketTask.js → network/websocket/socketTask.ts} +17 -7
- package/src/api/open-api/account.ts +4 -0
- package/src/api/open-api/address.ts +4 -0
- package/src/api/open-api/authorize.ts +5 -0
- package/src/api/open-api/card.ts +5 -0
- package/src/api/open-api/channels-live.ts +9 -0
- package/src/api/open-api/customer-service.ts +4 -0
- package/src/api/open-api/facial.ts +7 -0
- package/src/api/open-api/favorites.ts +5 -0
- package/src/api/open-api/group.ts +4 -0
- package/src/api/open-api/index.ts +18 -0
- package/src/api/open-api/invoice.ts +5 -0
- package/src/api/open-api/license-plate.ts +4 -0
- package/src/api/open-api/login.ts +6 -0
- package/src/api/open-api/red-package.ts +4 -0
- package/src/api/open-api/settings.ts +5 -0
- package/src/api/open-api/soter.ts +6 -0
- package/src/api/open-api/subscribe-message.ts +4 -0
- package/src/api/open-api/user-info.ts +5 -0
- package/src/api/open-api/werun.ts +5 -0
- package/src/api/payment/index.ts +5 -0
- package/src/api/route/index.ts +10 -0
- package/src/api/share/index.ts +13 -0
- package/src/api/storage/background-fetch.ts +7 -0
- package/src/api/storage/index.ts +181 -0
- package/src/api/swan/index.ts +31 -0
- package/src/{taro/index.js → api/taro.ts} +89 -104
- package/src/api/{createAnimation/index.js → ui/animation/index.ts} +52 -41
- package/src/api/ui/background.ts +5 -0
- package/src/api/ui/custom-component.ts +4 -0
- package/src/api/ui/fonts.ts +4 -0
- package/src/api/ui/index.ts +12 -0
- package/src/api/ui/interaction/actionSheet.ts +212 -0
- package/src/api/{interactive/index.js → ui/interaction/index.ts} +95 -77
- package/src/api/ui/interaction/modal.ts +237 -0
- package/src/api/{interactive/toast.js → ui/interaction/toast.ts} +35 -33
- package/src/api/ui/menu.ts +4 -0
- package/src/api/ui/navigation-bar/index.ts +52 -0
- package/src/api/ui/pull-down-refresh.ts +27 -0
- package/src/api/ui/scroll/index.ts +85 -0
- package/src/api/ui/sticky.ts +4 -0
- package/src/api/ui/tab-bar.ts +326 -0
- package/src/api/ui/window.ts +37 -0
- package/src/api/utils/handler.ts +105 -0
- package/src/api/utils/{index.js → index.ts} +36 -115
- package/src/api/worker/index.ts +4 -0
- package/src/api/wxml/index.ts +9 -0
- package/src/api/wxml/nodesRef.ts +56 -0
- package/src/api/wxml/selectorQuery.ts +219 -0
- package/src/index.ts +6 -0
- package/src/types/api.d.ts +4 -0
- package/src/types/define.d.ts +2 -0
- package/{types → src/types}/index.d.ts +0 -0
- package/{types → src/types}/type.ts +1 -1
- package/src/api/accelerometer/index.js +0 -105
- package/src/api/audio/index.js +0 -137
- package/src/api/canvas/canvasGetImageData.js +0 -44
- package/src/api/canvas/canvasPutImageData.js +0 -45
- package/src/api/canvas/canvasToTempFilePath.js +0 -49
- package/src/api/canvas/createCanvasContext.js +0 -340
- package/src/api/canvas/index.js +0 -4
- package/src/api/clipboard/index.js +0 -113
- package/src/api/compass/index.js +0 -99
- package/src/api/createSelectorQuery/index.js +0 -193
- package/src/api/deviceMotion/index.js +0 -105
- package/src/api/fileTransfer/index.js +0 -2
- package/src/api/image/chooseImage.js +0 -87
- package/src/api/image/getImageInfo.js +0 -74
- package/src/api/image/index.js +0 -7
- package/src/api/image/previewImage.js +0 -94
- package/src/api/index.js +0 -29
- package/src/api/interactive/actionSheet.js +0 -214
- package/src/api/interactive/modal.js +0 -256
- package/src/api/location/chooseLocation.js +0 -143
- package/src/api/location/index.js +0 -5
- package/src/api/navigationBar/index.js +0 -57
- package/src/api/open/index.js +0 -5
- package/src/api/others/index.js +0 -43
- package/src/api/pullDownRefresh/index.js +0 -51
- package/src/api/scroll/index.js +0 -99
- package/src/api/storage/index.js +0 -211
- package/src/api/system/index.js +0 -9
- package/src/api/system/info.js +0 -36
- package/src/api/system/network.js +0 -68
- package/src/api/tabBar/index.js +0 -402
- package/src/api/unsupportedApi/index.js +0 -278
- package/src/api/vibrate/index.js +0 -49
- package/src/api/video/index.js +0 -87
- package/src/api/webSocket/index.js +0 -103
- package/src/api/window/index.js +0 -38
- package/src/index.cjs.js +0 -11
- package/src/index.js +0 -6
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import Taro from '@tarojs/api'
|
|
2
|
+
import { findDOM } from '../utils'
|
|
3
|
+
import { MethodHandler } from '../utils/handler'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 把当前画布指定区域的内容导出生成指定大小的图片。在 draw() 回调里调用该方法才能保证图片导出成功。
|
|
7
|
+
* @todo 暂未支持尺寸相关功能
|
|
8
|
+
*/
|
|
9
|
+
export const canvasToTempFilePath: typeof Taro.canvasToTempFilePath = ({ canvasId, fileType, quality, success, fail, complete }, inst) => {
|
|
10
|
+
const handle = new MethodHandler({ name: 'canvasToTempFilePath', success, fail, complete })
|
|
11
|
+
const el = findDOM(inst) as HTMLElement
|
|
12
|
+
const canvas = el?.querySelector(`canvas[canvas-id="${canvasId}"]`) as HTMLCanvasElement
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
const dataURL = canvas?.toDataURL(`image/${fileType || 'png'}`, quality)
|
|
16
|
+
return handle.success({
|
|
17
|
+
tempFilePath: dataURL
|
|
18
|
+
})
|
|
19
|
+
} catch (e) {
|
|
20
|
+
return handle.fail({
|
|
21
|
+
errMsg: e.message
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import Taro from '@tarojs/api'
|
|
2
|
+
import { findDOM } from '../utils'
|
|
3
|
+
import { CanvasContext } from './CanvasContext'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 创建 canvas 的绘图上下文 CanvasContext 对象
|
|
7
|
+
*/
|
|
8
|
+
export const createCanvasContext: typeof Taro.createCanvasContext = (canvasId, inst) => {
|
|
9
|
+
const el = findDOM(inst) as HTMLElement
|
|
10
|
+
const canvas = el?.querySelector(`canvas[canvas-id="${canvasId}"]`) as HTMLCanvasElement
|
|
11
|
+
const ctx = canvas?.getContext('2d') as CanvasRenderingContext2D
|
|
12
|
+
const context = new CanvasContext(canvas, ctx)
|
|
13
|
+
if (!ctx) return context
|
|
14
|
+
context.canvas = canvas
|
|
15
|
+
context.ctx = ctx
|
|
16
|
+
|
|
17
|
+
return context
|
|
18
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils'
|
|
2
|
+
|
|
3
|
+
// 画布
|
|
4
|
+
export const createOffscreenCanvas = temporarilyNotSupport('createOffscreenCanvas')
|
|
5
|
+
export * from './createCanvasContext'
|
|
6
|
+
export * from './canvasToTempFilePath'
|
|
7
|
+
export * from './canvasPutImageData'
|
|
8
|
+
export * from './canvasGetImageData'
|
|
9
|
+
|
|
10
|
+
export const drawCanvas = temporarilyNotSupport('drawCanvas')
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import Taro from '@tarojs/api'
|
|
2
|
+
import { temporarilyNotSupport } from '../utils'
|
|
3
|
+
|
|
4
|
+
export class cloud implements Taro.cloud {
|
|
5
|
+
Cloud: new (options: Taro.cloud.IOptions) => Taro.Cloud
|
|
6
|
+
|
|
7
|
+
init = temporarilyNotSupport('cloud.init')
|
|
8
|
+
|
|
9
|
+
CloudID = temporarilyNotSupport('cloud.CloudID')
|
|
10
|
+
|
|
11
|
+
callFunction = temporarilyNotSupport('cloud.callFunction')
|
|
12
|
+
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
uploadFile = temporarilyNotSupport('cloud.uploadFile')
|
|
15
|
+
|
|
16
|
+
// @ts-ignore
|
|
17
|
+
downloadFile = temporarilyNotSupport('cloud.downloadFile')
|
|
18
|
+
|
|
19
|
+
getTempFileURL = temporarilyNotSupport('cloud.getTempFileURL')
|
|
20
|
+
|
|
21
|
+
deleteFile = temporarilyNotSupport('cloud.deleteFile')
|
|
22
|
+
|
|
23
|
+
// @ts-ignore
|
|
24
|
+
database = temporarilyNotSupport('cloud.database')
|
|
25
|
+
|
|
26
|
+
callContainer = temporarilyNotSupport('cloud.callContainer')
|
|
27
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils'
|
|
2
|
+
|
|
3
|
+
export const reportMonitor = temporarilyNotSupport('reportMonitor')
|
|
4
|
+
export const reportAnalytics = temporarilyNotSupport('reportAnalytics')
|
|
5
|
+
export const reportEvent = temporarilyNotSupport('reportEvent')
|
|
6
|
+
export const getExptInfoSync = temporarilyNotSupport('getExptInfoSync')
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import Taro from '@tarojs/api'
|
|
2
|
+
import { CallbackManager, MethodHandler } from '../utils/handler'
|
|
3
|
+
|
|
4
|
+
const callbackManager = new CallbackManager()
|
|
5
|
+
let devicemotionListener
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 停止监听加速度数据。
|
|
9
|
+
*/
|
|
10
|
+
export const stopAccelerometer: typeof Taro.stopAccelerometer = ({ success, fail, complete } = {}) => {
|
|
11
|
+
const res: Partial<TaroGeneral.CallbackResult> = {}
|
|
12
|
+
const handle = new MethodHandler({ name: 'stopAccelerometer', success, fail, complete })
|
|
13
|
+
try {
|
|
14
|
+
window.removeEventListener('devicemotion', devicemotionListener, true)
|
|
15
|
+
return handle.success(res)
|
|
16
|
+
} catch (e) {
|
|
17
|
+
res.errMsg = e.message
|
|
18
|
+
return handle.fail(res)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const INTERVAL_MAP = {
|
|
23
|
+
game: {
|
|
24
|
+
interval: 20,
|
|
25
|
+
frequency: 50
|
|
26
|
+
},
|
|
27
|
+
ui: {
|
|
28
|
+
interval: 60,
|
|
29
|
+
frequency: 16.67
|
|
30
|
+
},
|
|
31
|
+
normal: {
|
|
32
|
+
interval: 200,
|
|
33
|
+
frequency: 5
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const getDevicemotionListener = interval => {
|
|
38
|
+
let lock
|
|
39
|
+
let timer
|
|
40
|
+
return evt => {
|
|
41
|
+
if (lock) return
|
|
42
|
+
lock = true
|
|
43
|
+
timer && clearTimeout(timer)
|
|
44
|
+
callbackManager.trigger({
|
|
45
|
+
x: evt.acceleration.x || 0,
|
|
46
|
+
y: evt.acceleration.y || 0,
|
|
47
|
+
z: evt.acceleration.z || 0
|
|
48
|
+
})
|
|
49
|
+
timer = setTimeout(() => { lock = false }, interval)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 开始监听加速度数据。
|
|
55
|
+
*/
|
|
56
|
+
export const startAccelerometer: typeof Taro.startAccelerometer = ({ interval = 'normal', success, fail, complete } = {}) => {
|
|
57
|
+
const handle = new MethodHandler({ name: 'startAccelerometer', success, fail, complete })
|
|
58
|
+
try {
|
|
59
|
+
if (window.DeviceMotionEvent) {
|
|
60
|
+
const intervalObj = INTERVAL_MAP[interval]
|
|
61
|
+
if (devicemotionListener) {
|
|
62
|
+
stopAccelerometer()
|
|
63
|
+
}
|
|
64
|
+
devicemotionListener = getDevicemotionListener(intervalObj.interval)
|
|
65
|
+
window.addEventListener('devicemotion', devicemotionListener, true)
|
|
66
|
+
} else {
|
|
67
|
+
throw new Error('accelerometer is not supported')
|
|
68
|
+
}
|
|
69
|
+
return handle.success()
|
|
70
|
+
} catch (e) {
|
|
71
|
+
return handle.fail({ errMsg: e.message })
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 监听加速度数据事件。频率根据 Taro.startAccelerometer() 的 interval 参数。可使用 Taro.stopAccelerometer() 停止监听。
|
|
77
|
+
*/
|
|
78
|
+
export const onAccelerometerChange: typeof Taro.onAccelerometerChange = callback => {
|
|
79
|
+
callbackManager.add(callback)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 取消监听加速度数据事件,参数为空,则取消所有的事件监听
|
|
84
|
+
*/
|
|
85
|
+
export const offAccelerometerChange: typeof Taro.offAccelerometerChange = callback => {
|
|
86
|
+
callbackManager.remove(callback)
|
|
87
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils'
|
|
2
|
+
|
|
3
|
+
// 蓝牙-低功耗中心设备
|
|
4
|
+
export const writeBLECharacteristicValue = temporarilyNotSupport('writeBLECharacteristicValue')
|
|
5
|
+
export const setBLEMTU = temporarilyNotSupport('setBLEMTU')
|
|
6
|
+
export const readBLECharacteristicValue = temporarilyNotSupport('readBLECharacteristicValue')
|
|
7
|
+
export const onBLEMTUChange = temporarilyNotSupport('onBLEMTUChange')
|
|
8
|
+
export const onBLEConnectionStateChange = temporarilyNotSupport('onBLEConnectionStateChange')
|
|
9
|
+
export const onBLECharacteristicValueChange = temporarilyNotSupport('onBLECharacteristicValueChange')
|
|
10
|
+
export const offBLEMTUChange = temporarilyNotSupport('offBLEMTUChange')
|
|
11
|
+
export const offBLEConnectionStateChange = temporarilyNotSupport('offBLEConnectionStateChange')
|
|
12
|
+
export const offBLECharacteristicValueChange = temporarilyNotSupport('offBLECharacteristicValueChange')
|
|
13
|
+
export const notifyBLECharacteristicValueChange = temporarilyNotSupport('notifyBLECharacteristicValueChange')
|
|
14
|
+
export const getBLEMTU = temporarilyNotSupport('getBLEMTU')
|
|
15
|
+
export const getBLEDeviceServices = temporarilyNotSupport('getBLEDeviceServices')
|
|
16
|
+
export const getBLEDeviceRSSI = temporarilyNotSupport('getBLEDeviceRSSI')
|
|
17
|
+
export const getBLEDeviceCharacteristics = temporarilyNotSupport('getBLEDeviceCharacteristics')
|
|
18
|
+
export const createBLEConnection = temporarilyNotSupport('createBLEConnection')
|
|
19
|
+
export const closeBLEConnection = temporarilyNotSupport('closeBLEConnection')
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils'
|
|
2
|
+
|
|
3
|
+
// 蓝牙-低功耗外围设备
|
|
4
|
+
export const onBLEPeripheralConnectionStateChanged = temporarilyNotSupport('onBLEPeripheralConnectionStateChanged')
|
|
5
|
+
export const offBLEPeripheralConnectionStateChanged = temporarilyNotSupport('offBLEPeripheralConnectionStateChanged')
|
|
6
|
+
export const createBLEPeripheralServer = temporarilyNotSupport('createBLEPeripheralServer')
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils'
|
|
2
|
+
|
|
3
|
+
// 蓝牙-通用
|
|
4
|
+
export const stopBluetoothDevicesDiscovery = temporarilyNotSupport('stopBluetoothDevicesDiscovery')
|
|
5
|
+
export const startBluetoothDevicesDiscovery = temporarilyNotSupport('startBluetoothDevicesDiscovery')
|
|
6
|
+
export const openBluetoothAdapter = temporarilyNotSupport('openBluetoothAdapter')
|
|
7
|
+
export const onBluetoothDeviceFound = temporarilyNotSupport('onBluetoothDeviceFound')
|
|
8
|
+
export const onBluetoothAdapterStateChange = temporarilyNotSupport('onBluetoothAdapterStateChange')
|
|
9
|
+
export const offBluetoothDeviceFound = temporarilyNotSupport('offBluetoothDeviceFound')
|
|
10
|
+
export const offBluetoothAdapterStateChange = temporarilyNotSupport('offBluetoothAdapterStateChange')
|
|
11
|
+
export const makeBluetoothPair = temporarilyNotSupport('makeBluetoothPair')
|
|
12
|
+
export const isBluetoothDevicePaired = temporarilyNotSupport('isBluetoothDevicePaired')
|
|
13
|
+
export const getConnectedBluetoothDevices = temporarilyNotSupport('getConnectedBluetoothDevices')
|
|
14
|
+
export const getBluetoothDevices = temporarilyNotSupport('getBluetoothDevices')
|
|
15
|
+
export const getBluetoothAdapterState = temporarilyNotSupport('getBluetoothAdapterState')
|
|
16
|
+
export const closeBluetoothAdapter = temporarilyNotSupport('closeBluetoothAdapter')
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 剪贴板部分的api参考了Chameleon项目的实现:
|
|
3
|
+
*
|
|
4
|
+
* setClipboardData: https://github.com/chameleon-team/chameleon-api/tree/master/src/interfaces/setClipBoardData
|
|
5
|
+
* getClipboardData: https://github.com/chameleon-team/chameleon-api/tree/master/src/interfaces/getClipBoardData
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import Taro from '@tarojs/api'
|
|
9
|
+
import { setStorage, setStorageSync, getStorageSync } from '../storage/index'
|
|
10
|
+
import { MethodHandler } from '../utils/handler'
|
|
11
|
+
|
|
12
|
+
const CLIPBOARD_STORAGE_NAME = 'taro_clipboard'
|
|
13
|
+
|
|
14
|
+
document.addEventListener('copy', () => {
|
|
15
|
+
setStorage({
|
|
16
|
+
key: CLIPBOARD_STORAGE_NAME,
|
|
17
|
+
data: window.getSelection()?.toString()
|
|
18
|
+
}).catch(e => {
|
|
19
|
+
console.error(e)
|
|
20
|
+
})
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 设置系统剪贴板的内容
|
|
25
|
+
*/
|
|
26
|
+
export const setClipboardData: typeof Taro.setClipboardData = async ({ data, success, fail, complete }) => {
|
|
27
|
+
const handle = new MethodHandler({ name: 'setClipboardData', success, fail, complete })
|
|
28
|
+
try {
|
|
29
|
+
setStorageSync(CLIPBOARD_STORAGE_NAME, data)
|
|
30
|
+
/**
|
|
31
|
+
* 已于 iPhone 6s Plus iOS 13.1.3 上的 Safari 测试通过
|
|
32
|
+
* iOS < 10 的系统可能无法使用编程方式访问剪贴板,参考:
|
|
33
|
+
* https://stackoverflow.com/questions/34045777/copy-to-clipboard-using-javascript-in-ios/34046084
|
|
34
|
+
*/
|
|
35
|
+
if (typeof document.execCommand === 'function') {
|
|
36
|
+
const textarea = document.createElement('textarea')
|
|
37
|
+
textarea.readOnly = true
|
|
38
|
+
textarea.value = data
|
|
39
|
+
textarea.style.position = 'absolute'
|
|
40
|
+
textarea.style.width = '100px'
|
|
41
|
+
textarea.style.left = '-10000px'
|
|
42
|
+
document.body.appendChild(textarea)
|
|
43
|
+
textarea.select()
|
|
44
|
+
textarea.setSelectionRange(0, textarea.value.length)
|
|
45
|
+
document.execCommand('copy')
|
|
46
|
+
document.body.removeChild(textarea)
|
|
47
|
+
} else {
|
|
48
|
+
throw new Error('Unsupported Function: \'document.execCommand\'.')
|
|
49
|
+
}
|
|
50
|
+
return handle.success()
|
|
51
|
+
} catch (e) {
|
|
52
|
+
return handle.fail({ errMsg: e.message })
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* 获取系统剪贴板的内容
|
|
58
|
+
*/
|
|
59
|
+
export const getClipboardData: typeof Taro.getClipboardData = async ({ success, fail, complete } = {}) => {
|
|
60
|
+
const handle = new MethodHandler<Taro.getClipboardData.SuccessCallbackOption>({ name: 'getClipboardData', success, fail, complete })
|
|
61
|
+
try {
|
|
62
|
+
const data: string = getStorageSync(CLIPBOARD_STORAGE_NAME)
|
|
63
|
+
return handle.success({ data })
|
|
64
|
+
} catch (e) {
|
|
65
|
+
return handle.fail({ errMsg: e.message })
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import Taro from '@tarojs/api'
|
|
2
|
+
import { CallbackManager, MethodHandler } from '../utils/handler'
|
|
3
|
+
|
|
4
|
+
const callbackManager = new CallbackManager()
|
|
5
|
+
let compassListener
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 停止监听罗盘数据
|
|
9
|
+
*/
|
|
10
|
+
export const stopCompass: typeof Taro.stopCompass = ({ success, fail, complete } = {}) => {
|
|
11
|
+
const handle = new MethodHandler({ name: 'stopCompass', success, fail, complete })
|
|
12
|
+
try {
|
|
13
|
+
window.removeEventListener('deviceorientation', compassListener, true)
|
|
14
|
+
return handle.success()
|
|
15
|
+
} catch (e) {
|
|
16
|
+
return handle.fail({ errMsg: e.message })
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const getDeviceOrientationListener = interval => {
|
|
21
|
+
let lock
|
|
22
|
+
let timer
|
|
23
|
+
return evt => {
|
|
24
|
+
if (lock) return
|
|
25
|
+
lock = true
|
|
26
|
+
timer && clearTimeout(timer)
|
|
27
|
+
callbackManager.trigger({
|
|
28
|
+
direction: 360 - evt.alpha
|
|
29
|
+
})
|
|
30
|
+
timer = setTimeout(() => { lock = false }, interval)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 开始监听罗盘数据
|
|
36
|
+
*/
|
|
37
|
+
export const startCompass: typeof Taro.startCompass = ({ success, fail, complete } = {}) => {
|
|
38
|
+
const handle = new MethodHandler({ name: 'startCompass', success, fail, complete })
|
|
39
|
+
try {
|
|
40
|
+
if (window.DeviceOrientationEvent) {
|
|
41
|
+
if (compassListener) {
|
|
42
|
+
stopCompass()
|
|
43
|
+
}
|
|
44
|
+
compassListener = getDeviceOrientationListener(200)
|
|
45
|
+
window.addEventListener('deviceorientation', compassListener, true)
|
|
46
|
+
} else {
|
|
47
|
+
throw new Error('compass is not supported')
|
|
48
|
+
}
|
|
49
|
+
return handle.success()
|
|
50
|
+
} catch (e) {
|
|
51
|
+
return handle.fail({ errMsg: e.message })
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* 监听罗盘数据变化事件。频率:5 次/秒,接口调用后会自动开始监听,可使用 wx.stopCompass 停止监听。
|
|
57
|
+
*/
|
|
58
|
+
export const onCompassChange: typeof Taro.onCompassChange = callback => {
|
|
59
|
+
callbackManager.add(callback)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 取消监听罗盘数据变化事件,参数为空,则取消所有的事件监听。
|
|
64
|
+
*/
|
|
65
|
+
export const offCompassChange: typeof Taro.offCompassChange = callback => {
|
|
66
|
+
callbackManager.remove(callback)
|
|
67
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils'
|
|
2
|
+
|
|
3
|
+
// 陀螺仪
|
|
4
|
+
export const stopGyroscope = temporarilyNotSupport('stopGyroscope')
|
|
5
|
+
export const startGyroscope = temporarilyNotSupport('startGyroscope')
|
|
6
|
+
export const onGyroscopeChange = temporarilyNotSupport('onGyroscopeChange')
|
|
7
|
+
export const offGyroscopeChange = temporarilyNotSupport('offGyroscopeChange')
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils'
|
|
2
|
+
|
|
3
|
+
// 蓝牙-信标(Beacon)
|
|
4
|
+
export const stopBeaconDiscovery = temporarilyNotSupport('stopBeaconDiscovery')
|
|
5
|
+
export const startBeaconDiscovery = temporarilyNotSupport('startBeaconDiscovery')
|
|
6
|
+
export const onBeaconUpdate = temporarilyNotSupport('onBeaconUpdate')
|
|
7
|
+
export const onBeaconServiceChange = temporarilyNotSupport('onBeaconServiceChange')
|
|
8
|
+
export const offBeaconUpdate = temporarilyNotSupport('offBeaconUpdate')
|
|
9
|
+
export const offBeaconServiceChange = temporarilyNotSupport('offBeaconServiceChange')
|
|
10
|
+
export const getBeacons = temporarilyNotSupport('getBeacons')
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export * from './accelerometer'
|
|
2
|
+
export * from './accessibility'
|
|
3
|
+
export * from './battery'
|
|
4
|
+
export * from './bluetooth'
|
|
5
|
+
export * from './bluetooth-ble'
|
|
6
|
+
export * from './bluetooth-peripheral'
|
|
7
|
+
export * from './calendar'
|
|
8
|
+
export * from './clipboard'
|
|
9
|
+
export * from './compass'
|
|
10
|
+
export * from './contact'
|
|
11
|
+
export * from './crypto'
|
|
12
|
+
export * from './gyroscope'
|
|
13
|
+
export * from './iBeacon'
|
|
14
|
+
export * from './keyboard'
|
|
15
|
+
export * from './memory'
|
|
16
|
+
export * from './motion'
|
|
17
|
+
export * from './nfc'
|
|
18
|
+
export * from './phone'
|
|
19
|
+
export * from './scan'
|
|
20
|
+
export * from './screen'
|
|
21
|
+
export * from './vibrate'
|
|
22
|
+
export * from './wifi'
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils'
|
|
2
|
+
|
|
3
|
+
// 键盘
|
|
4
|
+
export const onKeyboardHeightChange = temporarilyNotSupport('onKeyboardHeightChange')
|
|
5
|
+
export const offKeyboardHeightChange = temporarilyNotSupport('offKeyboardHeightChange')
|
|
6
|
+
export const hideKeyboard = temporarilyNotSupport('hideKeyboard')
|
|
7
|
+
export const getSelectedTextRange = temporarilyNotSupport('getSelectedTextRange')
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import Taro from '@tarojs/api'
|
|
2
|
+
import { CallbackManager, MethodHandler } from '../utils/handler'
|
|
3
|
+
|
|
4
|
+
const callbackManager = new CallbackManager()
|
|
5
|
+
let deviceMotionListener
|
|
6
|
+
|
|
7
|
+
const INTERVAL_MAP = {
|
|
8
|
+
game: {
|
|
9
|
+
interval: 20,
|
|
10
|
+
frequency: 50
|
|
11
|
+
},
|
|
12
|
+
ui: {
|
|
13
|
+
interval: 60,
|
|
14
|
+
frequency: 16.67
|
|
15
|
+
},
|
|
16
|
+
normal: {
|
|
17
|
+
interval: 200,
|
|
18
|
+
frequency: 5
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 停止监听设备方向的变化。
|
|
24
|
+
*/
|
|
25
|
+
export const stopDeviceMotionListening: typeof Taro.stopDeviceMotionListening = ({ success, fail, complete } = {}) => {
|
|
26
|
+
const handle = new MethodHandler({ name: 'stopDeviceMotionListening', success, fail, complete })
|
|
27
|
+
try {
|
|
28
|
+
window.removeEventListener('deviceorientation', deviceMotionListener, true)
|
|
29
|
+
return handle.success()
|
|
30
|
+
} catch (e) {
|
|
31
|
+
return handle.fail({ errMsg: e.message })
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const getDeviceOrientationListener = interval => {
|
|
36
|
+
let lock
|
|
37
|
+
let timer
|
|
38
|
+
return evt => {
|
|
39
|
+
if (lock) return
|
|
40
|
+
lock = true
|
|
41
|
+
timer && clearTimeout(timer)
|
|
42
|
+
callbackManager.trigger({
|
|
43
|
+
alpha: evt.alpha,
|
|
44
|
+
beta: evt.beta,
|
|
45
|
+
gamma: evt.gamma
|
|
46
|
+
})
|
|
47
|
+
timer = setTimeout(() => { lock = false }, interval)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* 开始监听设备方向的变化。
|
|
53
|
+
*/
|
|
54
|
+
export const startDeviceMotionListening: typeof Taro.startDeviceMotionListening = ({ interval = 'normal', success, fail, complete } = {}) => {
|
|
55
|
+
const handle = new MethodHandler({ name: 'startDeviceMotionListening', success, fail, complete })
|
|
56
|
+
try {
|
|
57
|
+
const intervalObj = INTERVAL_MAP[interval]
|
|
58
|
+
if (window.DeviceOrientationEvent) {
|
|
59
|
+
if (deviceMotionListener) {
|
|
60
|
+
stopDeviceMotionListening()
|
|
61
|
+
}
|
|
62
|
+
deviceMotionListener = getDeviceOrientationListener(intervalObj.interval)
|
|
63
|
+
window.addEventListener('deviceorientation', deviceMotionListener, true)
|
|
64
|
+
} else {
|
|
65
|
+
throw new Error('deviceMotion is not supported')
|
|
66
|
+
}
|
|
67
|
+
return handle.success()
|
|
68
|
+
} catch (e) {
|
|
69
|
+
return handle.fail({ errMsg: e.message })
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 监听设备方向变化事件。
|
|
75
|
+
*/
|
|
76
|
+
export const onDeviceMotionChange: typeof Taro.onDeviceMotionChange = callback => {
|
|
77
|
+
callbackManager.add(callback)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* 取消监听设备方向变化事件,参数为空,则取消所有的事件监听。
|
|
82
|
+
*/
|
|
83
|
+
export const offDeviceMotionChange: typeof Taro.offDeviceMotionChange = callback => {
|
|
84
|
+
callbackManager.remove(callback)
|
|
85
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils'
|
|
2
|
+
|
|
3
|
+
// NFC
|
|
4
|
+
export const stopHCE = temporarilyNotSupport('stopHCE')
|
|
5
|
+
export const startHCE = temporarilyNotSupport('startHCE')
|
|
6
|
+
export const sendHCEMessage = temporarilyNotSupport('sendHCEMessage')
|
|
7
|
+
export const onHCEMessage = temporarilyNotSupport('onHCEMessage')
|
|
8
|
+
export const offHCEMessage = temporarilyNotSupport('offHCEMessage')
|
|
9
|
+
export const getNFCAdapter = temporarilyNotSupport('getNFCAdapter')
|
|
10
|
+
export const getHCEState = temporarilyNotSupport('getHCEState')
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import Taro from '@tarojs/api'
|
|
2
|
+
import { shouldBeObject, getParameterError } from '../utils'
|
|
3
|
+
import { MethodHandler } from '../utils/handler'
|
|
4
|
+
|
|
5
|
+
export const makePhoneCall: typeof Taro.makePhoneCall = (options) => {
|
|
6
|
+
// options must be an Object
|
|
7
|
+
const isObject = shouldBeObject(options)
|
|
8
|
+
if (!isObject.flag) {
|
|
9
|
+
const res = { errMsg: `makePhoneCall:fail ${isObject.msg}` }
|
|
10
|
+
console.error(res.errMsg)
|
|
11
|
+
return Promise.reject(res)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const { phoneNumber, success, fail, complete } = options
|
|
15
|
+
const handle = new MethodHandler({ name: 'makePhoneCall', success, fail, complete })
|
|
16
|
+
|
|
17
|
+
if (typeof phoneNumber !== 'string') {
|
|
18
|
+
return handle.fail({
|
|
19
|
+
errMsg: getParameterError({
|
|
20
|
+
para: 'phoneNumber',
|
|
21
|
+
correct: 'String',
|
|
22
|
+
wrong: phoneNumber
|
|
23
|
+
})
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
window.location.href = `tel:${phoneNumber}`
|
|
28
|
+
|
|
29
|
+
return handle.success()
|
|
30
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils'
|
|
2
|
+
|
|
3
|
+
// 屏幕
|
|
4
|
+
export const setVisualEffectOnCapture = temporarilyNotSupport('setVisualEffectOnCapture')
|
|
5
|
+
export const setScreenBrightness = temporarilyNotSupport('setScreenBrightness')
|
|
6
|
+
export const setKeepScreenOn = temporarilyNotSupport('setKeepScreenOn')
|
|
7
|
+
export const onUserCaptureScreen = temporarilyNotSupport('onUserCaptureScreen')
|
|
8
|
+
export const offUserCaptureScreen = temporarilyNotSupport('offUserCaptureScreen')
|
|
9
|
+
export const getScreenBrightness = temporarilyNotSupport('getScreenBrightness')
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import Taro from '@tarojs/api'
|
|
2
|
+
import { MethodHandler } from '../utils/handler'
|
|
3
|
+
|
|
4
|
+
const vibrator = function vibrator (mm) {
|
|
5
|
+
try {
|
|
6
|
+
return window.navigator.vibrate(mm)
|
|
7
|
+
} catch (e) {
|
|
8
|
+
console.warn('当前浏览器不支持vibrate')
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 使手机发生较短时间的振动(15 ms)。仅在 iPhone 7 / 7 Plus 以上及 Android 机型生效
|
|
14
|
+
*/
|
|
15
|
+
export const vibrateShort: typeof Taro.vibrateShort = ({ success, fail, complete } = {}) => {
|
|
16
|
+
const handle = new MethodHandler({ name: 'vibrateShort', success, fail, complete })
|
|
17
|
+
if (vibrator) {
|
|
18
|
+
vibrator(15)
|
|
19
|
+
return handle.success()
|
|
20
|
+
} else {
|
|
21
|
+
return handle.fail()
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 使手机发生较长时间的振动(400 ms)
|
|
27
|
+
*/
|
|
28
|
+
export const vibrateLong: typeof Taro.vibrateLong = ({ success, fail, complete } = {}) => {
|
|
29
|
+
const handle = new MethodHandler({ name: 'vibrateLong', success, fail, complete })
|
|
30
|
+
if (vibrator) {
|
|
31
|
+
vibrator(400)
|
|
32
|
+
return handle.success()
|
|
33
|
+
} else {
|
|
34
|
+
return handle.fail()
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils'
|
|
2
|
+
|
|
3
|
+
// Wi-Fi
|
|
4
|
+
export const stopWifi = temporarilyNotSupport('stopWifi')
|
|
5
|
+
export const startWifi = temporarilyNotSupport('startWifi')
|
|
6
|
+
export const setWifiList = temporarilyNotSupport('setWifiList')
|
|
7
|
+
export const onWifiConnected = temporarilyNotSupport('onWifiConnected')
|
|
8
|
+
export const onGetWifiList = temporarilyNotSupport('onGetWifiList')
|
|
9
|
+
export const offWifiConnected = temporarilyNotSupport('offWifiConnected')
|
|
10
|
+
export const offGetWifiList = temporarilyNotSupport('offGetWifiList')
|
|
11
|
+
export const getWifiList = temporarilyNotSupport('getWifiList')
|
|
12
|
+
export const getConnectedWifi = temporarilyNotSupport('getConnectedWifi')
|
|
13
|
+
export const connectWifi = temporarilyNotSupport('connectWifi')
|