@tarojs/taro-h5 3.4.0-beta.2 → 3.4.2
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 +5 -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.js +187 -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 +12 -0
- package/dist/api/cloud/index.js +21 -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 +21 -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 +23 -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/network.js +78 -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 +13 -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/EditorContext.js +19 -0
- package/dist/api/media/audio/InnerAudioContext.js +84 -0
- package/dist/api/media/audio/index.js +15 -0
- package/dist/api/media/background-audio/BackgroundAudioManager.js +86 -0
- package/dist/api/media/background-audio/index.js +15 -0
- package/dist/api/media/camera.js +3 -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 +12 -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 +146 -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 +288 -0
- package/dist/api/ui/background.js +4 -0
- package/dist/api/ui/custom-component.js +3 -0
- package/dist/api/ui/fonts.js +51 -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 +172 -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 +5028 -6988
- package/dist/index.js +4 -10767
- package/dist/taroApis.js +1 -1
- package/dist/types/type.js +2 -0
- package/package.json +11 -13
- package/src/api/ai/visual.ts +3 -0
- package/src/api/base/system.ts +207 -0
- package/src/api/canvas/CanvasContext.ts +42 -39
- package/src/api/canvas/createCanvasContext.ts +2 -2
- package/src/api/canvas/index.ts +10 -2
- package/src/api/cloud/index.ts +4 -0
- package/src/api/device/battery.ts +18 -1
- package/src/api/device/index.ts +1 -0
- package/src/api/{base/system → device}/network.ts +35 -15
- package/src/api/device/wifi.ts +1 -0
- package/src/api/location/chooseLocation.ts +2 -2
- package/src/api/media/{editor.ts → EditorContext.ts} +2 -0
- package/src/api/media/audio/InnerAudioContext.ts +98 -0
- package/src/api/media/audio/index.ts +1 -86
- package/src/api/media/background-audio/BackgroundAudioManager.ts +103 -0
- package/src/api/media/{background-audio.ts → background-audio/index.ts} +7 -2
- package/src/api/media/image/previewImage.ts +4 -25
- package/src/api/media/index.ts +0 -1
- package/src/api/network/download.ts +5 -5
- package/src/api/network/upload.ts +7 -13
- package/src/api/network/websocket/index.ts +1 -1
- package/src/api/ui/animation/index.ts +11 -12
- package/src/api/ui/fonts.ts +61 -2
- package/src/api/ui/interaction/index.ts +12 -10
- package/src/api/ui/navigation-bar/index.ts +2 -2
- package/src/api/ui/scroll/index.ts +3 -3
- package/src/api/utils/handler.ts +4 -4
- package/src/api/utils/index.ts +34 -13
- package/src/api/wxml/nodesRef.ts +10 -3
- package/src/api/wxml/selectorQuery.ts +68 -23
- package/src/index.ts +2 -2
- package/src/api/base/system/index.ts +0 -2
- package/src/api/base/system/info.ts +0 -64
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { CallbackManager, MethodHandler } from '../utils/handler';
|
|
2
|
+
const callbackManager = new CallbackManager();
|
|
3
|
+
let devicemotionListener;
|
|
4
|
+
/**
|
|
5
|
+
* 停止监听加速度数据。
|
|
6
|
+
*/
|
|
7
|
+
export const stopAccelerometer = ({ success, fail, complete } = {}) => {
|
|
8
|
+
const res = {};
|
|
9
|
+
const handle = new MethodHandler({ name: 'stopAccelerometer', success, fail, complete });
|
|
10
|
+
try {
|
|
11
|
+
window.removeEventListener('devicemotion', devicemotionListener, true);
|
|
12
|
+
return handle.success(res);
|
|
13
|
+
}
|
|
14
|
+
catch (e) {
|
|
15
|
+
res.errMsg = e.message;
|
|
16
|
+
return handle.fail(res);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
const INTERVAL_MAP = {
|
|
20
|
+
game: {
|
|
21
|
+
interval: 20,
|
|
22
|
+
frequency: 50
|
|
23
|
+
},
|
|
24
|
+
ui: {
|
|
25
|
+
interval: 60,
|
|
26
|
+
frequency: 16.67
|
|
27
|
+
},
|
|
28
|
+
normal: {
|
|
29
|
+
interval: 200,
|
|
30
|
+
frequency: 5
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const getDevicemotionListener = interval => {
|
|
34
|
+
let lock;
|
|
35
|
+
let timer;
|
|
36
|
+
return evt => {
|
|
37
|
+
if (lock)
|
|
38
|
+
return;
|
|
39
|
+
lock = true;
|
|
40
|
+
timer && clearTimeout(timer);
|
|
41
|
+
callbackManager.trigger({
|
|
42
|
+
x: evt.acceleration.x || 0,
|
|
43
|
+
y: evt.acceleration.y || 0,
|
|
44
|
+
z: evt.acceleration.z || 0
|
|
45
|
+
});
|
|
46
|
+
timer = setTimeout(() => { lock = false; }, interval);
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* 开始监听加速度数据。
|
|
51
|
+
*/
|
|
52
|
+
export const startAccelerometer = ({ interval = 'normal', success, fail, complete } = {}) => {
|
|
53
|
+
const handle = new MethodHandler({ name: 'startAccelerometer', success, fail, complete });
|
|
54
|
+
try {
|
|
55
|
+
if (window.DeviceMotionEvent) {
|
|
56
|
+
const intervalObj = INTERVAL_MAP[interval];
|
|
57
|
+
if (devicemotionListener) {
|
|
58
|
+
stopAccelerometer();
|
|
59
|
+
}
|
|
60
|
+
devicemotionListener = getDevicemotionListener(intervalObj.interval);
|
|
61
|
+
window.addEventListener('devicemotion', devicemotionListener, true);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
throw new Error('accelerometer is not supported');
|
|
65
|
+
}
|
|
66
|
+
return handle.success();
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
return handle.fail({ errMsg: e.message });
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* 监听加速度数据事件。频率根据 Taro.startAccelerometer() 的 interval 参数。可使用 Taro.stopAccelerometer() 停止监听。
|
|
74
|
+
*/
|
|
75
|
+
export const onAccelerometerChange = callback => {
|
|
76
|
+
callbackManager.add(callback);
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* 取消监听加速度数据事件,参数为空,则取消所有的事件监听
|
|
80
|
+
*/
|
|
81
|
+
export const offAccelerometerChange = callback => {
|
|
82
|
+
callbackManager.remove(callback);
|
|
83
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils';
|
|
2
|
+
import { MethodHandler } from '../utils/handler';
|
|
3
|
+
// 电量
|
|
4
|
+
export const getBatteryInfoSync = temporarilyNotSupport('getBatteryInfoSync');
|
|
5
|
+
export const getBatteryInfo = async ({ success, fail, complete } = {}) => {
|
|
6
|
+
var _a;
|
|
7
|
+
const handle = new MethodHandler({ name: 'getBatteryInfo', success, fail, complete });
|
|
8
|
+
try {
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
const battery = await ((_a = navigator.getBattery) === null || _a === void 0 ? void 0 : _a.call(navigator));
|
|
11
|
+
return handle.success({
|
|
12
|
+
isCharging: battery.charging,
|
|
13
|
+
level: Number(battery.level || 0) * 100
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
return handle.fail({
|
|
18
|
+
errMsg: (error === null || error === void 0 ? void 0 : error.message) || error
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils';
|
|
2
|
+
// 蓝牙-低功耗中心设备
|
|
3
|
+
export const writeBLECharacteristicValue = temporarilyNotSupport('writeBLECharacteristicValue');
|
|
4
|
+
export const setBLEMTU = temporarilyNotSupport('setBLEMTU');
|
|
5
|
+
export const readBLECharacteristicValue = temporarilyNotSupport('readBLECharacteristicValue');
|
|
6
|
+
export const onBLEMTUChange = temporarilyNotSupport('onBLEMTUChange');
|
|
7
|
+
export const onBLEConnectionStateChange = temporarilyNotSupport('onBLEConnectionStateChange');
|
|
8
|
+
export const onBLECharacteristicValueChange = temporarilyNotSupport('onBLECharacteristicValueChange');
|
|
9
|
+
export const offBLEMTUChange = temporarilyNotSupport('offBLEMTUChange');
|
|
10
|
+
export const offBLEConnectionStateChange = temporarilyNotSupport('offBLEConnectionStateChange');
|
|
11
|
+
export const offBLECharacteristicValueChange = temporarilyNotSupport('offBLECharacteristicValueChange');
|
|
12
|
+
export const notifyBLECharacteristicValueChange = temporarilyNotSupport('notifyBLECharacteristicValueChange');
|
|
13
|
+
export const getBLEMTU = temporarilyNotSupport('getBLEMTU');
|
|
14
|
+
export const getBLEDeviceServices = temporarilyNotSupport('getBLEDeviceServices');
|
|
15
|
+
export const getBLEDeviceRSSI = temporarilyNotSupport('getBLEDeviceRSSI');
|
|
16
|
+
export const getBLEDeviceCharacteristics = temporarilyNotSupport('getBLEDeviceCharacteristics');
|
|
17
|
+
export const createBLEConnection = temporarilyNotSupport('createBLEConnection');
|
|
18
|
+
export const closeBLEConnection = temporarilyNotSupport('closeBLEConnection');
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils';
|
|
2
|
+
// 蓝牙-低功耗外围设备
|
|
3
|
+
export const onBLEPeripheralConnectionStateChanged = temporarilyNotSupport('onBLEPeripheralConnectionStateChanged');
|
|
4
|
+
export const offBLEPeripheralConnectionStateChanged = temporarilyNotSupport('offBLEPeripheralConnectionStateChanged');
|
|
5
|
+
export const createBLEPeripheralServer = temporarilyNotSupport('createBLEPeripheralServer');
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils';
|
|
2
|
+
// 蓝牙-通用
|
|
3
|
+
export const stopBluetoothDevicesDiscovery = temporarilyNotSupport('stopBluetoothDevicesDiscovery');
|
|
4
|
+
export const startBluetoothDevicesDiscovery = temporarilyNotSupport('startBluetoothDevicesDiscovery');
|
|
5
|
+
export const openBluetoothAdapter = temporarilyNotSupport('openBluetoothAdapter');
|
|
6
|
+
export const onBluetoothDeviceFound = temporarilyNotSupport('onBluetoothDeviceFound');
|
|
7
|
+
export const onBluetoothAdapterStateChange = temporarilyNotSupport('onBluetoothAdapterStateChange');
|
|
8
|
+
export const offBluetoothDeviceFound = temporarilyNotSupport('offBluetoothDeviceFound');
|
|
9
|
+
export const offBluetoothAdapterStateChange = temporarilyNotSupport('offBluetoothAdapterStateChange');
|
|
10
|
+
export const makeBluetoothPair = temporarilyNotSupport('makeBluetoothPair');
|
|
11
|
+
export const isBluetoothDevicePaired = temporarilyNotSupport('isBluetoothDevicePaired');
|
|
12
|
+
export const getConnectedBluetoothDevices = temporarilyNotSupport('getConnectedBluetoothDevices');
|
|
13
|
+
export const getBluetoothDevices = temporarilyNotSupport('getBluetoothDevices');
|
|
14
|
+
export const getBluetoothAdapterState = temporarilyNotSupport('getBluetoothAdapterState');
|
|
15
|
+
export const closeBluetoothAdapter = temporarilyNotSupport('closeBluetoothAdapter');
|
|
@@ -0,0 +1,65 @@
|
|
|
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
|
+
import { setStorage, setStorageSync, getStorageSync } from '../storage/index';
|
|
8
|
+
import { MethodHandler } from '../utils/handler';
|
|
9
|
+
const CLIPBOARD_STORAGE_NAME = 'taro_clipboard';
|
|
10
|
+
document.addEventListener('copy', () => {
|
|
11
|
+
var _a;
|
|
12
|
+
setStorage({
|
|
13
|
+
key: CLIPBOARD_STORAGE_NAME,
|
|
14
|
+
data: (_a = window.getSelection()) === null || _a === void 0 ? void 0 : _a.toString()
|
|
15
|
+
}).catch(e => {
|
|
16
|
+
console.error(e);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
/**
|
|
20
|
+
* 设置系统剪贴板的内容
|
|
21
|
+
*/
|
|
22
|
+
export const setClipboardData = async ({ data, success, fail, complete }) => {
|
|
23
|
+
const handle = new MethodHandler({ name: 'setClipboardData', success, fail, complete });
|
|
24
|
+
try {
|
|
25
|
+
setStorageSync(CLIPBOARD_STORAGE_NAME, data);
|
|
26
|
+
/**
|
|
27
|
+
* 已于 iPhone 6s Plus iOS 13.1.3 上的 Safari 测试通过
|
|
28
|
+
* iOS < 10 的系统可能无法使用编程方式访问剪贴板,参考:
|
|
29
|
+
* https://stackoverflow.com/questions/34045777/copy-to-clipboard-using-javascript-in-ios/34046084
|
|
30
|
+
*/
|
|
31
|
+
if (typeof document.execCommand === 'function') {
|
|
32
|
+
const textarea = document.createElement('textarea');
|
|
33
|
+
textarea.readOnly = true;
|
|
34
|
+
textarea.value = data;
|
|
35
|
+
textarea.style.position = 'absolute';
|
|
36
|
+
textarea.style.width = '100px';
|
|
37
|
+
textarea.style.left = '-10000px';
|
|
38
|
+
document.body.appendChild(textarea);
|
|
39
|
+
textarea.select();
|
|
40
|
+
textarea.setSelectionRange(0, textarea.value.length);
|
|
41
|
+
document.execCommand('copy');
|
|
42
|
+
document.body.removeChild(textarea);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
throw new Error('Unsupported Function: \'document.execCommand\'.');
|
|
46
|
+
}
|
|
47
|
+
return handle.success();
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
return handle.fail({ errMsg: e.message });
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* 获取系统剪贴板的内容
|
|
55
|
+
*/
|
|
56
|
+
export const getClipboardData = async ({ success, fail, complete } = {}) => {
|
|
57
|
+
const handle = new MethodHandler({ name: 'getClipboardData', success, fail, complete });
|
|
58
|
+
try {
|
|
59
|
+
const data = getStorageSync(CLIPBOARD_STORAGE_NAME);
|
|
60
|
+
return handle.success({ data });
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
return handle.fail({ errMsg: e.message });
|
|
64
|
+
}
|
|
65
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { CallbackManager, MethodHandler } from '../utils/handler';
|
|
2
|
+
const callbackManager = new CallbackManager();
|
|
3
|
+
let compassListener;
|
|
4
|
+
/**
|
|
5
|
+
* 停止监听罗盘数据
|
|
6
|
+
*/
|
|
7
|
+
export const stopCompass = ({ success, fail, complete } = {}) => {
|
|
8
|
+
const handle = new MethodHandler({ name: 'stopCompass', success, fail, complete });
|
|
9
|
+
try {
|
|
10
|
+
window.removeEventListener('deviceorientation', compassListener, true);
|
|
11
|
+
return handle.success();
|
|
12
|
+
}
|
|
13
|
+
catch (e) {
|
|
14
|
+
return handle.fail({ errMsg: e.message });
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const getDeviceOrientationListener = interval => {
|
|
18
|
+
let lock;
|
|
19
|
+
let timer;
|
|
20
|
+
return evt => {
|
|
21
|
+
if (lock)
|
|
22
|
+
return;
|
|
23
|
+
lock = true;
|
|
24
|
+
timer && clearTimeout(timer);
|
|
25
|
+
callbackManager.trigger({
|
|
26
|
+
direction: 360 - evt.alpha
|
|
27
|
+
});
|
|
28
|
+
timer = setTimeout(() => { lock = false; }, interval);
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* 开始监听罗盘数据
|
|
33
|
+
*/
|
|
34
|
+
export const startCompass = ({ success, fail, complete } = {}) => {
|
|
35
|
+
const handle = new MethodHandler({ name: 'startCompass', success, fail, complete });
|
|
36
|
+
try {
|
|
37
|
+
if (window.DeviceOrientationEvent) {
|
|
38
|
+
if (compassListener) {
|
|
39
|
+
stopCompass();
|
|
40
|
+
}
|
|
41
|
+
compassListener = getDeviceOrientationListener(200);
|
|
42
|
+
window.addEventListener('deviceorientation', compassListener, true);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
throw new Error('compass is not supported');
|
|
46
|
+
}
|
|
47
|
+
return handle.success();
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
return handle.fail({ errMsg: e.message });
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* 监听罗盘数据变化事件。频率:5 次/秒,接口调用后会自动开始监听,可使用 wx.stopCompass 停止监听。
|
|
55
|
+
*/
|
|
56
|
+
export const onCompassChange = callback => {
|
|
57
|
+
callbackManager.add(callback);
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* 取消监听罗盘数据变化事件,参数为空,则取消所有的事件监听。
|
|
61
|
+
*/
|
|
62
|
+
export const offCompassChange = callback => {
|
|
63
|
+
callbackManager.remove(callback);
|
|
64
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils';
|
|
2
|
+
// 陀螺仪
|
|
3
|
+
export const stopGyroscope = temporarilyNotSupport('stopGyroscope');
|
|
4
|
+
export const startGyroscope = temporarilyNotSupport('startGyroscope');
|
|
5
|
+
export const onGyroscopeChange = temporarilyNotSupport('onGyroscopeChange');
|
|
6
|
+
export const offGyroscopeChange = temporarilyNotSupport('offGyroscopeChange');
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils';
|
|
2
|
+
// 蓝牙-信标(Beacon)
|
|
3
|
+
export const stopBeaconDiscovery = temporarilyNotSupport('stopBeaconDiscovery');
|
|
4
|
+
export const startBeaconDiscovery = temporarilyNotSupport('startBeaconDiscovery');
|
|
5
|
+
export const onBeaconUpdate = temporarilyNotSupport('onBeaconUpdate');
|
|
6
|
+
export const onBeaconServiceChange = temporarilyNotSupport('onBeaconServiceChange');
|
|
7
|
+
export const offBeaconUpdate = temporarilyNotSupport('offBeaconUpdate');
|
|
8
|
+
export const offBeaconServiceChange = temporarilyNotSupport('offBeaconServiceChange');
|
|
9
|
+
export const getBeacons = temporarilyNotSupport('getBeacons');
|
|
@@ -0,0 +1,23 @@
|
|
|
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 './network';
|
|
18
|
+
export * from './nfc';
|
|
19
|
+
export * from './phone';
|
|
20
|
+
export * from './scan';
|
|
21
|
+
export * from './screen';
|
|
22
|
+
export * from './vibrate';
|
|
23
|
+
export * from './wifi';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils';
|
|
2
|
+
// 键盘
|
|
3
|
+
export const onKeyboardHeightChange = temporarilyNotSupport('onKeyboardHeightChange');
|
|
4
|
+
export const offKeyboardHeightChange = temporarilyNotSupport('offKeyboardHeightChange');
|
|
5
|
+
export const hideKeyboard = temporarilyNotSupport('hideKeyboard');
|
|
6
|
+
export const getSelectedTextRange = temporarilyNotSupport('getSelectedTextRange');
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { CallbackManager, MethodHandler } from '../utils/handler';
|
|
2
|
+
const callbackManager = new CallbackManager();
|
|
3
|
+
let deviceMotionListener;
|
|
4
|
+
const INTERVAL_MAP = {
|
|
5
|
+
game: {
|
|
6
|
+
interval: 20,
|
|
7
|
+
frequency: 50
|
|
8
|
+
},
|
|
9
|
+
ui: {
|
|
10
|
+
interval: 60,
|
|
11
|
+
frequency: 16.67
|
|
12
|
+
},
|
|
13
|
+
normal: {
|
|
14
|
+
interval: 200,
|
|
15
|
+
frequency: 5
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* 停止监听设备方向的变化。
|
|
20
|
+
*/
|
|
21
|
+
export const stopDeviceMotionListening = ({ success, fail, complete } = {}) => {
|
|
22
|
+
const handle = new MethodHandler({ name: 'stopDeviceMotionListening', success, fail, complete });
|
|
23
|
+
try {
|
|
24
|
+
window.removeEventListener('deviceorientation', deviceMotionListener, true);
|
|
25
|
+
return handle.success();
|
|
26
|
+
}
|
|
27
|
+
catch (e) {
|
|
28
|
+
return handle.fail({ errMsg: e.message });
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const getDeviceOrientationListener = interval => {
|
|
32
|
+
let lock;
|
|
33
|
+
let timer;
|
|
34
|
+
return evt => {
|
|
35
|
+
if (lock)
|
|
36
|
+
return;
|
|
37
|
+
lock = true;
|
|
38
|
+
timer && clearTimeout(timer);
|
|
39
|
+
callbackManager.trigger({
|
|
40
|
+
alpha: evt.alpha,
|
|
41
|
+
beta: evt.beta,
|
|
42
|
+
gamma: evt.gamma
|
|
43
|
+
});
|
|
44
|
+
timer = setTimeout(() => { lock = false; }, interval);
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* 开始监听设备方向的变化。
|
|
49
|
+
*/
|
|
50
|
+
export const startDeviceMotionListening = ({ interval = 'normal', success, fail, complete } = {}) => {
|
|
51
|
+
const handle = new MethodHandler({ name: 'startDeviceMotionListening', success, fail, complete });
|
|
52
|
+
try {
|
|
53
|
+
const intervalObj = INTERVAL_MAP[interval];
|
|
54
|
+
if (window.DeviceOrientationEvent) {
|
|
55
|
+
if (deviceMotionListener) {
|
|
56
|
+
stopDeviceMotionListening();
|
|
57
|
+
}
|
|
58
|
+
deviceMotionListener = getDeviceOrientationListener(intervalObj.interval);
|
|
59
|
+
window.addEventListener('deviceorientation', deviceMotionListener, true);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
throw new Error('deviceMotion is not supported');
|
|
63
|
+
}
|
|
64
|
+
return handle.success();
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
return handle.fail({ errMsg: e.message });
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* 监听设备方向变化事件。
|
|
72
|
+
*/
|
|
73
|
+
export const onDeviceMotionChange = callback => {
|
|
74
|
+
callbackManager.add(callback);
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* 取消监听设备方向变化事件,参数为空,则取消所有的事件监听。
|
|
78
|
+
*/
|
|
79
|
+
export const offDeviceMotionChange = callback => {
|
|
80
|
+
callbackManager.remove(callback);
|
|
81
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { CallbackManager, MethodHandler } from '../utils/handler';
|
|
2
|
+
import { temporarilyNotSupport } from '../utils';
|
|
3
|
+
function getConnection() {
|
|
4
|
+
// @ts-ignore
|
|
5
|
+
return navigator.connection || navigator.mozConnection || navigator.webkitConnection || navigator.msConnection;
|
|
6
|
+
}
|
|
7
|
+
export const getNetworkType = (options = {}) => {
|
|
8
|
+
const connection = getConnection();
|
|
9
|
+
const { success, fail, complete } = options;
|
|
10
|
+
const handle = new MethodHandler({ name: 'getNetworkType', success, fail, complete });
|
|
11
|
+
let networkType = 'unknown';
|
|
12
|
+
// 浏览器不支持获取网络状态
|
|
13
|
+
if (!connection) {
|
|
14
|
+
return handle.success({ networkType });
|
|
15
|
+
}
|
|
16
|
+
// Supports only the navigator.connection.type value which doesn't match the latest spec.
|
|
17
|
+
// https://www.davidbcalhoun.com/2010/using-navigator-connection-android/
|
|
18
|
+
if (!isNaN(Number(connection.type))) {
|
|
19
|
+
switch (connection.type) {
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
case connection.WIFI:
|
|
22
|
+
networkType = 'wifi';
|
|
23
|
+
break;
|
|
24
|
+
// @ts-ignore
|
|
25
|
+
case connection.CELL_3G:
|
|
26
|
+
networkType = '3g';
|
|
27
|
+
break;
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
case connection.CELL_2G:
|
|
30
|
+
networkType = '2g';
|
|
31
|
+
break;
|
|
32
|
+
default:
|
|
33
|
+
// ETHERNET, UNKNOWN
|
|
34
|
+
networkType = 'unknown';
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else if (connection.type) {
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
networkType = connection.type; // Only supports the type value.
|
|
40
|
+
// @ts-ignore
|
|
41
|
+
}
|
|
42
|
+
else if (connection.effectiveType) {
|
|
43
|
+
// @ts-ignore
|
|
44
|
+
networkType = connection.effectiveType;
|
|
45
|
+
}
|
|
46
|
+
return handle.success({ networkType });
|
|
47
|
+
};
|
|
48
|
+
const networkStatusManager = new CallbackManager();
|
|
49
|
+
const networkStatusListener = async () => {
|
|
50
|
+
const { networkType } = await getNetworkType();
|
|
51
|
+
const isConnected = networkType !== 'none';
|
|
52
|
+
const obj = { isConnected, networkType };
|
|
53
|
+
networkStatusManager.trigger(obj);
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* 在最近的八次网络请求中, 出现下列三个现象之一则判定弱网。
|
|
57
|
+
* - 出现三次以上连接超时
|
|
58
|
+
* - 出现三次 rtt 超过 400
|
|
59
|
+
* - 出现三次以上的丢包
|
|
60
|
+
* > 弱网事件通知规则是: 弱网状态变化时立即通知, 状态不变时 30s 内最多通知一次。
|
|
61
|
+
*/
|
|
62
|
+
export const onNetworkWeakChange = temporarilyNotSupport('onNetworkWeakChange');
|
|
63
|
+
export const onNetworkStatusChange = callback => {
|
|
64
|
+
networkStatusManager.add(callback);
|
|
65
|
+
const connection = getConnection();
|
|
66
|
+
if (connection && networkStatusManager.count() === 1) {
|
|
67
|
+
connection.addEventListener('change', networkStatusListener);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
export const offNetworkWeakChange = temporarilyNotSupport('offNetworkStatusChange');
|
|
71
|
+
export const offNetworkStatusChange = callback => {
|
|
72
|
+
networkStatusManager.remove(callback);
|
|
73
|
+
const connection = getConnection();
|
|
74
|
+
if (connection && networkStatusManager.count() === 0) {
|
|
75
|
+
connection.removeEventListener('change', networkStatusListener);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
export const getLocalIPAddress = temporarilyNotSupport('getLocalIPAddress');
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils';
|
|
2
|
+
// NFC
|
|
3
|
+
export const stopHCE = temporarilyNotSupport('stopHCE');
|
|
4
|
+
export const startHCE = temporarilyNotSupport('startHCE');
|
|
5
|
+
export const sendHCEMessage = temporarilyNotSupport('sendHCEMessage');
|
|
6
|
+
export const onHCEMessage = temporarilyNotSupport('onHCEMessage');
|
|
7
|
+
export const offHCEMessage = temporarilyNotSupport('offHCEMessage');
|
|
8
|
+
export const getNFCAdapter = temporarilyNotSupport('getNFCAdapter');
|
|
9
|
+
export const getHCEState = temporarilyNotSupport('getHCEState');
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { shouldBeObject, getParameterError } from '../utils';
|
|
2
|
+
import { MethodHandler } from '../utils/handler';
|
|
3
|
+
export const makePhoneCall = (options) => {
|
|
4
|
+
// options must be an Object
|
|
5
|
+
const isObject = shouldBeObject(options);
|
|
6
|
+
if (!isObject.flag) {
|
|
7
|
+
const res = { errMsg: `makePhoneCall:fail ${isObject.msg}` };
|
|
8
|
+
console.error(res.errMsg);
|
|
9
|
+
return Promise.reject(res);
|
|
10
|
+
}
|
|
11
|
+
const { phoneNumber, success, fail, complete } = options;
|
|
12
|
+
const handle = new MethodHandler({ name: 'makePhoneCall', success, fail, complete });
|
|
13
|
+
if (typeof phoneNumber !== 'string') {
|
|
14
|
+
return handle.fail({
|
|
15
|
+
errMsg: getParameterError({
|
|
16
|
+
para: 'phoneNumber',
|
|
17
|
+
correct: 'String',
|
|
18
|
+
wrong: phoneNumber
|
|
19
|
+
})
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
window.location.href = `tel:${phoneNumber}`;
|
|
23
|
+
return handle.success();
|
|
24
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils';
|
|
2
|
+
// 屏幕
|
|
3
|
+
export const setVisualEffectOnCapture = temporarilyNotSupport('setVisualEffectOnCapture');
|
|
4
|
+
export const setScreenBrightness = temporarilyNotSupport('setScreenBrightness');
|
|
5
|
+
export const setKeepScreenOn = temporarilyNotSupport('setKeepScreenOn');
|
|
6
|
+
export const onUserCaptureScreen = temporarilyNotSupport('onUserCaptureScreen');
|
|
7
|
+
export const offUserCaptureScreen = temporarilyNotSupport('offUserCaptureScreen');
|
|
8
|
+
export const getScreenBrightness = temporarilyNotSupport('getScreenBrightness');
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { MethodHandler } from '../utils/handler';
|
|
2
|
+
const vibrator = function vibrator(mm) {
|
|
3
|
+
try {
|
|
4
|
+
return window.navigator.vibrate(mm);
|
|
5
|
+
}
|
|
6
|
+
catch (e) {
|
|
7
|
+
console.warn('当前浏览器不支持vibrate');
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* 使手机发生较短时间的振动(15 ms)。仅在 iPhone 7 / 7 Plus 以上及 Android 机型生效
|
|
12
|
+
*/
|
|
13
|
+
export const vibrateShort = ({ success, fail, complete } = {}) => {
|
|
14
|
+
const handle = new MethodHandler({ name: 'vibrateShort', success, fail, complete });
|
|
15
|
+
if (vibrator) {
|
|
16
|
+
vibrator(15);
|
|
17
|
+
return handle.success();
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
return handle.fail();
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* 使手机发生较长时间的振动(400 ms)
|
|
25
|
+
*/
|
|
26
|
+
export const vibrateLong = ({ success, fail, complete } = {}) => {
|
|
27
|
+
const handle = new MethodHandler({ name: 'vibrateLong', success, fail, complete });
|
|
28
|
+
if (vibrator) {
|
|
29
|
+
vibrator(400);
|
|
30
|
+
return handle.success();
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
return handle.fail();
|
|
34
|
+
}
|
|
35
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils';
|
|
2
|
+
// Wi-Fi
|
|
3
|
+
export const stopWifi = temporarilyNotSupport('stopWifi');
|
|
4
|
+
export const startWifi = temporarilyNotSupport('startWifi');
|
|
5
|
+
export const setWifiList = temporarilyNotSupport('setWifiList');
|
|
6
|
+
export const onWifiConnectedWithPartialInfo = temporarilyNotSupport('onWifiConnectedWithPartialInfo');
|
|
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');
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { temporarilyNotSupport } from '../utils';
|
|
2
|
+
// 文件
|
|
3
|
+
export const saveFileToDisk = temporarilyNotSupport('saveFileToDisk');
|
|
4
|
+
export const saveFile = temporarilyNotSupport('saveFile');
|
|
5
|
+
export const removeSavedFile = temporarilyNotSupport('removeSavedFile');
|
|
6
|
+
export const openDocument = temporarilyNotSupport('openDocument');
|
|
7
|
+
export const getSavedFileList = temporarilyNotSupport('getSavedFileList');
|
|
8
|
+
export const getSavedFileInfo = temporarilyNotSupport('getSavedFileInfo');
|
|
9
|
+
export const getFileSystemManager = temporarilyNotSupport('getFileSystemManager');
|
|
10
|
+
export const getFileInfo = temporarilyNotSupport('getFileInfo');
|