@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
package/dist/taroApis.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports = new Set(["
|
|
1
|
+
module.exports = new Set(["addCard","addFileToFavorites","addInterceptor","addPhoneCalendar","addPhoneContact","addPhoneRepeatCalendar","addVideoToFavorites","advancedGeneralIdentify","animalClassify","arrayBufferToBase64","authPrivateMessage","authorize","authorizeForMiniProgram","base64ToArrayBuffer","canIUse","canvasGetImageData","canvasPutImageData","canvasToTempFilePath","carClassify","checkIsOpenAccessibility","checkIsSoterEnrolledInDevice","checkIsSupportFacialRecognition","checkIsSupportSoterAuthentication","checkSession","chooseAddress","chooseContact","chooseImage","chooseInvoice","chooseInvoiceTitle","chooseLicensePlate","chooseLocation","chooseMedia","chooseMessageFile","choosePoi","chooseVideo","clearStorage","clearStorageSync","closeBLEConnection","closeBluetoothAdapter","closeSocket","cloud","compressImage","compressVideo","connectSocket","connectWifi","createAnimation","createAudioContext","createBLEConnection","createBLEPeripheralServer","createBufferURL","createCameraContext","createCanvasContext","createInnerAudioContext","createIntersectionObserver","createInterstitialAd","createLivePlayerContext","createLivePusherContext","createMapContext","createMediaAudioPlayer","createMediaContainer","createMediaRecorder","createOffscreenCanvas","createRewardedVideoAd","createSelectorQuery","createTCPSocket","createUDPSocket","createVKSession","createVideoContext","createVideoDecoder","createWebAudioContext","createWorker","disableAlertBeforeUnload","dishClassify","downloadFile","enableAlertBeforeUnload","exitMiniProgram","exitVoIPChat","faceDetect","faceVerifyForPay","getAccountInfoSync","getApp","getAppAuthorizeSetting","getAppBaseInfo","getAvailableAudioSources","getBLEDeviceCharacteristics","getBLEDeviceRSSI","getBLEDeviceServices","getBLEMTU","getBackgroundAudioManager","getBackgroundAudioPlayerState","getBackgroundFetchData","getBackgroundFetchToken","getBatteryInfo","getBatteryInfoSync","getBeacons","getBluetoothAdapterState","getBluetoothDevices","getChannelsLiveInfo","getChannelsLiveNoticeInfo","getClipboardData","getConnectedBluetoothDevices","getConnectedWifi","getCurrentInstance","getCurrentPages","getDeviceInfo","getEnterOptionsSync","getExptInfoSync","getExtConfig","getExtConfigSync","getFileInfo","getFileSystemManager","getGroupEnterInfo","getHCEState","getImageInfo","getLaunchOptionsSync","getLocalIPAddress","getLocation","getLogManager","getMenuButtonBoundingClientRect","getNFCAdapter","getNetworkType","getOpenUserInfo","getPerformance","getRandomValues","getRealtimeLogManager","getRecorderManager","getSavedFileInfo","getSavedFileList","getScreenBrightness","getSelectedTextRange","getSetting","getShareInfo","getStorage","getStorageInfo","getStorageInfoSync","getStorageSync","getSwanId","getSystemInfo","getSystemInfoAsync","getSystemInfoSync","getSystemSetting","getUpdateManager","getUserCryptoManager","getUserInfo","getUserProfile","getVideoInfo","getWeRunData","getWifiList","getWindowInfo","hideHomeButton","hideKeyboard","hideLoading","hideNavigationBarLoading","hideShareMenu","hideTabBar","hideTabBarRedDot","hideToast","imageAudit","initFaceDetect","initTabBarApis","isBluetoothDevicePaired","isVKSupport","joinVoIPChat","loadFontFace","login","logoClassify","makeBluetoothPair","makePhoneCall","navigateBack","navigateBackMiniProgram","navigateBackSmartProgram","navigateTo","navigateToMiniProgram","navigateToSmartGameProgram","navigateToSmartProgram","nextTick","notifyBLECharacteristicValueChange","objectDetectIdentify","ocrBankCard","ocrDrivingLicense","ocrIdCard","ocrVehicleLicense","offAccelerometerChange","offAppHide","offAppShow","offAudioInterruptionBegin","offAudioInterruptionEnd","offBLECharacteristicValueChange","offBLEConnectionStateChange","offBLEMTUChange","offBLEPeripheralConnectionStateChanged","offBeaconServiceChange","offBeaconUpdate","offBluetoothAdapterStateChange","offBluetoothDeviceFound","offCompassChange","offCopyUrl","offDeviceMotionChange","offError","offGetWifiList","offGyroscopeChange","offHCEMessage","offKeyboardHeightChange","offLocalServiceDiscoveryStop","offLocalServiceFound","offLocalServiceLost","offLocalServiceResolveFail","offLocationChange","offLocationChangeError","offMemoryWarning","offNetworkStatusChange","offNetworkWeakChange","offPageNotFound","offThemeChange","offUnhandledRejection","offUserCaptureScreen","offVoIPChatInterrupted","offVoIPChatMembersChanged","offVoIPChatStateChanged","offVoIPVideoMembersChanged","offWifiConnected","offWindowResize","onAccelerometerChange","onAppHide","onAppShow","onAudioInterruptionBegin","onAudioInterruptionEnd","onBLECharacteristicValueChange","onBLEConnectionStateChange","onBLEMTUChange","onBLEPeripheralConnectionStateChanged","onBackgroundAudioPause","onBackgroundAudioPlay","onBackgroundAudioStop","onBackgroundFetchData","onBeaconServiceChange","onBeaconUpdate","onBluetoothAdapterStateChange","onBluetoothDeviceFound","onCompassChange","onCopyUrl","onDeviceMotionChange","onError","onGetWifiList","onGyroscopeChange","onHCEMessage","onKeyboardHeightChange","onLocalServiceDiscoveryStop","onLocalServiceFound","onLocalServiceLost","onLocalServiceResolveFail","onLocationChange","onLocationChangeError","onMemoryWarning","onNetworkStatusChange","onNetworkWeakChange","onPageNotFound","onSocketClose","onSocketError","onSocketMessage","onSocketOpen","onThemeChange","onUnhandledRejection","onUserCaptureScreen","onVoIPChatInterrupted","onVoIPChatMembersChanged","onVoIPChatSpeakersChanged","onVoIPChatStateChanged","onVoIPVideoMembersChanged","onWifiConnected","onWifiConnectedWithPartialInfo","onWindowResize","openAppAuthorizeSetting","openBluetoothAdapter","openCard","openChannelsActivity","openChannelsEvent","openChannelsLive","openCustomerServiceChat","openDocument","openEmbeddedMiniProgram","openLocation","openSetting","openSystemBluetoothSetting","openVideoEditor","pageScrollTo","pauseBackgroundAudio","pauseVoice","plantClassify","playBackgroundAudio","playVoice","pluginLogin","preloadSubPackage","previewImage","previewMedia","reLaunch","readBLECharacteristicValue","redirectTo","removeSavedFile","removeStorage","removeStorageSync","removeTabBarBadge","reportAnalytics","reportEvent","reportMonitor","reportPerformance","request","requestOrderPayment","requestPayment","requestPolymerPayment","requestSubscribeMessage","reserveChannelsLive","revokeBufferURL","saveFile","saveFileToDisk","saveImageToPhotosAlbum","saveVideoToPhotosAlbum","scanCode","seekBackgroundAudio","sendHCEMessage","sendSocketMessage","setBLEMTU","setBackgroundColor","setBackgroundFetchToken","setBackgroundTextStyle","setClipboardData","setEnable1v1Chat","setEnableDebug","setInnerAudioOption","setKeepScreenOn","setNavigationBarColor","setNavigationBarTitle","setPageInfo","setScreenBrightness","setStorage","setStorageSync","setTabBarBadge","setTabBarItem","setTabBarStyle","setTopBarText","setVisualEffectOnCapture","setWifiList","setWindowSize","shareFileMessage","shareToWeRun","shareVideoMessage","showActionSheet","showLoading","showModal","showNavigationBarLoading","showRedPackage","showShareImageMenu","showShareMenu","showTabBar","showTabBarRedDot","showToast","startAccelerometer","startBeaconDiscovery","startBluetoothDevicesDiscovery","startCompass","startDeviceMotionListening","startFacialRecognitionVerify","startFacialRecognitionVerifyAndUploadVideo","startGyroscope","startHCE","startLocalServiceDiscovery","startLocationUpdate","startLocationUpdateBackground","startPullDownRefresh","startRecord","startSoterAuthentication","startWifi","stopAccelerometer","stopBackgroundAudio","stopBeaconDiscovery","stopBluetoothDevicesDiscovery","stopCompass","stopDeviceMotionListening","stopFaceDetect","stopGyroscope","stopHCE","stopLocalServiceDiscovery","stopLocationUpdate","stopPullDownRefresh","stopRecord","stopVoice","stopWifi","subscribeVoIPVideoMembers","switchTab","textReview","textToAudio","updateShareMenu","updateVoIPChatMuteConfig","updateWeChatApp","uploadFile","vibrateLong","vibrateShort","writeBLECharacteristicValue"])
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tarojs/taro-h5",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.2",
|
|
4
4
|
"description": "Taro h5 framework",
|
|
5
5
|
"main:h5": "dist/index.js",
|
|
6
6
|
"main": "dist/index.cjs.js",
|
|
@@ -10,17 +10,15 @@
|
|
|
10
10
|
"src",
|
|
11
11
|
"index.js"
|
|
12
12
|
],
|
|
13
|
-
"sideEffects":
|
|
14
|
-
"*.scss",
|
|
15
|
-
"*.css",
|
|
16
|
-
"./src/taro/index.js"
|
|
17
|
-
],
|
|
13
|
+
"sideEffects": false,
|
|
18
14
|
"scripts": {
|
|
19
15
|
"test": "jest",
|
|
16
|
+
"test:ci": "jest -i --coverage false",
|
|
20
17
|
"test:dev": "jest --watch",
|
|
21
18
|
"test:coverage": "jest --coverage",
|
|
22
|
-
"
|
|
23
|
-
"
|
|
19
|
+
"copy:assets": "copy src/**/*.css dist",
|
|
20
|
+
"build": "rollup -c && npm run copy:assets && tsc",
|
|
21
|
+
"dev": "tsc -w & npm run copy:assets"
|
|
24
22
|
},
|
|
25
23
|
"repository": {
|
|
26
24
|
"type": "git",
|
|
@@ -32,14 +30,14 @@
|
|
|
32
30
|
"author": "O2Team",
|
|
33
31
|
"license": "MIT",
|
|
34
32
|
"dependencies": {
|
|
35
|
-
"@tarojs/api": "3.4.
|
|
36
|
-
"@tarojs/router": "3.4.
|
|
37
|
-
"@tarojs/runtime": "3.4.
|
|
38
|
-
"@tarojs/taro": "3.4.
|
|
33
|
+
"@tarojs/api": "3.4.2",
|
|
34
|
+
"@tarojs/router": "3.4.2",
|
|
35
|
+
"@tarojs/runtime": "3.4.2",
|
|
36
|
+
"@tarojs/taro": "3.4.2",
|
|
39
37
|
"base64-js": "^1.3.0",
|
|
40
38
|
"jsonp-retry": "^1.0.3",
|
|
41
39
|
"mobile-detect": "^1.4.2",
|
|
42
40
|
"whatwg-fetch": "^3.4.0"
|
|
43
41
|
},
|
|
44
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "26b329326c6a7da652e8d712ee33df01ab8d2d0e"
|
|
45
43
|
}
|
package/src/api/ai/visual.ts
CHANGED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import Taro from '@tarojs/api'
|
|
2
|
+
import MobileDetect from 'mobile-detect'
|
|
3
|
+
|
|
4
|
+
import { temporarilyNotSupport } from '../utils'
|
|
5
|
+
import { MethodHandler } from '../utils/handler'
|
|
6
|
+
|
|
7
|
+
/** 跳转系统蓝牙设置页 */
|
|
8
|
+
export const openSystemBluetoothSetting = temporarilyNotSupport('openSystemBluetoothSetting')
|
|
9
|
+
|
|
10
|
+
/** 跳转系统微信授权管理页 */
|
|
11
|
+
export const openAppAuthorizeSetting = temporarilyNotSupport('openAppAuthorizeSetting')
|
|
12
|
+
|
|
13
|
+
/** 获取窗口信息 */
|
|
14
|
+
export const getWindowInfo: typeof Taro.getWindowInfo = () => {
|
|
15
|
+
const info: ReturnType<typeof Taro.getWindowInfo> = {
|
|
16
|
+
/** 设备像素比 */
|
|
17
|
+
pixelRatio: window.devicePixelRatio,
|
|
18
|
+
/** 屏幕宽度,单位px */
|
|
19
|
+
screenWidth: window.screen.width,
|
|
20
|
+
/** 屏幕高度,单位px */
|
|
21
|
+
screenHeight: window.screen.height,
|
|
22
|
+
/** 可使用窗口宽度,单位px */
|
|
23
|
+
windowWidth: document.documentElement.clientWidth,
|
|
24
|
+
/** 可使用窗口高度,单位px */
|
|
25
|
+
windowHeight: document.documentElement.clientHeight,
|
|
26
|
+
/** 状态栏的高度,单位px */
|
|
27
|
+
statusBarHeight: NaN,
|
|
28
|
+
/** 在竖屏正方向下的安全区域 */
|
|
29
|
+
safeArea: {
|
|
30
|
+
bottom: 0,
|
|
31
|
+
height: 0,
|
|
32
|
+
left: 0,
|
|
33
|
+
right: 0,
|
|
34
|
+
top: 0,
|
|
35
|
+
width: 0
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return info
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** 获取设备设置 */
|
|
43
|
+
export const getSystemSetting: typeof Taro.getSystemSetting = () => {
|
|
44
|
+
const isLandscape = window.screen.width >= window.screen.height
|
|
45
|
+
const info: ReturnType<typeof Taro.getSystemSetting> = {
|
|
46
|
+
/** 蓝牙的系统开关 */
|
|
47
|
+
bluetoothEnabled: false,
|
|
48
|
+
/** 地理位置的系统开关 */
|
|
49
|
+
locationEnabled: false,
|
|
50
|
+
/** Wi-Fi 的系统开关 */
|
|
51
|
+
wifiEnabled: false,
|
|
52
|
+
/** 设备方向 */
|
|
53
|
+
deviceOrientation: isLandscape ? 'landscape' : 'portrait'
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return info
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** 获取设备设置 */
|
|
60
|
+
export const getDeviceInfo: typeof Taro.getDeviceInfo = () => {
|
|
61
|
+
const md = new MobileDetect(navigator.userAgent)
|
|
62
|
+
|
|
63
|
+
const info: ReturnType<typeof Taro.getDeviceInfo> = {
|
|
64
|
+
/** 应用二进制接口类型(仅 Android 支持) */
|
|
65
|
+
abi: '',
|
|
66
|
+
/** 设备性能等级(仅Android小游戏)。取值为:-2 或 0(该设备无法运行小游戏),-1(性能未知),>=1(设备性能值,该值越高,设备性能越好,目前最高不到50) */
|
|
67
|
+
benchmarkLevel: -1,
|
|
68
|
+
/** 设备品牌 */
|
|
69
|
+
brand: md.mobile() || '',
|
|
70
|
+
/** 设备型号 */
|
|
71
|
+
model: md.mobile() || '',
|
|
72
|
+
/** 操作系统及版本 */
|
|
73
|
+
system: md.os(),
|
|
74
|
+
/** 客户端平台 */
|
|
75
|
+
platform: navigator.platform
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return info
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** 获取微信APP基础信息 */
|
|
82
|
+
export const getAppBaseInfo: typeof Taro.getAppBaseInfo = () => {
|
|
83
|
+
let isDarkMode = false
|
|
84
|
+
if (window.matchMedia?.('(prefers-color-scheme: dark)').matches) {
|
|
85
|
+
isDarkMode = true
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const info: ReturnType<typeof Taro.getAppBaseInfo> = {
|
|
89
|
+
/** 客户端基础库版本 */
|
|
90
|
+
SDKVersion: '',
|
|
91
|
+
/** 是否已打开调试。可通过右上角菜单或 [Taro.setEnableDebug](/docs/apis/base/debug/setEnableDebug) 打开调试。 */
|
|
92
|
+
enableDebug: process.env.NODE_ENV === 'development',
|
|
93
|
+
/** 当前小程序运行的宿主环境 */
|
|
94
|
+
// host: { appId: '' },
|
|
95
|
+
/** 微信设置的语言 */
|
|
96
|
+
language: navigator.language,
|
|
97
|
+
/** 微信版本号 */
|
|
98
|
+
version: '',
|
|
99
|
+
/** 系统当前主题,取值为light或dark,全局配置"darkmode":true时才能获取,否则为 undefined (不支持小游戏) */
|
|
100
|
+
theme: isDarkMode ? 'dark' : 'light'
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return info
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** 获取微信APP授权设置 */
|
|
107
|
+
export const getAppAuthorizeSetting: typeof Taro.getAppAuthorizeSetting = () => {
|
|
108
|
+
const info: ReturnType<typeof Taro.getAppAuthorizeSetting> = {
|
|
109
|
+
/** 允许微信使用相册的开关(仅 iOS 有效) */
|
|
110
|
+
albumAuthorized: 'not determined',
|
|
111
|
+
/** 允许微信使用蓝牙的开关(仅 iOS 有效) */
|
|
112
|
+
bluetoothAuthorized: 'not determined',
|
|
113
|
+
/** 允许微信使用摄像头的开关 */
|
|
114
|
+
cameraAuthorized: 'not determined',
|
|
115
|
+
/** 允许微信使用定位的开关 */
|
|
116
|
+
locationAuthorized: 'not determined',
|
|
117
|
+
/** 定位准确度。true 表示模糊定位,false 表示精确定位(仅 iOS 有效) */
|
|
118
|
+
locationReducedAccuracy: false,
|
|
119
|
+
/** 允许微信使用麦克风的开关 */
|
|
120
|
+
microphoneAuthorized: 'not determined',
|
|
121
|
+
/** 允许微信通知的开关 */
|
|
122
|
+
notificationAuthorized: 'not determined',
|
|
123
|
+
/** 允许微信通知带有提醒的开关(仅 iOS 有效) */
|
|
124
|
+
notificationAlertAuthorized: 'not determined',
|
|
125
|
+
/** 允许微信通知带有标记的开关(仅 iOS 有效) */
|
|
126
|
+
notificationBadgeAuthorized: 'not determined',
|
|
127
|
+
/** 允许微信通知带有声音的开关(仅 iOS 有效) */
|
|
128
|
+
notificationSoundAuthorized: 'not determined',
|
|
129
|
+
/** 允许微信使用日历的开关 */
|
|
130
|
+
phoneCalendarAuthorized: 'not determined'
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return info
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** 获取设备设置 */
|
|
137
|
+
export const getSystemInfoSync: typeof Taro.getSystemInfoSync = () => {
|
|
138
|
+
const windowInfo = getWindowInfo()
|
|
139
|
+
const systemSetting = getSystemSetting()
|
|
140
|
+
const deviceInfo: Taro.getDeviceInfo.Result = getDeviceInfo()
|
|
141
|
+
const appBaseInfo = getAppBaseInfo()
|
|
142
|
+
const appAuthorizeSetting = getAppAuthorizeSetting()
|
|
143
|
+
delete deviceInfo.abi
|
|
144
|
+
|
|
145
|
+
const info: ReturnType<typeof Taro.getSystemInfoSync> = {
|
|
146
|
+
...windowInfo,
|
|
147
|
+
...systemSetting,
|
|
148
|
+
...deviceInfo,
|
|
149
|
+
...appBaseInfo,
|
|
150
|
+
/** 用户字体大小(单位px)。以微信客户端「我-设置-通用-字体大小」中的设置为准 */
|
|
151
|
+
fontSizeSetting: NaN,
|
|
152
|
+
/** 允许微信使用相册的开关(仅 iOS 有效) */
|
|
153
|
+
albumAuthorized: appAuthorizeSetting.albumAuthorized === 'authorized',
|
|
154
|
+
/** 允许微信使用摄像头的开关 */
|
|
155
|
+
cameraAuthorized: appAuthorizeSetting.cameraAuthorized === 'authorized',
|
|
156
|
+
/** 允许微信使用定位的开关 */
|
|
157
|
+
locationAuthorized: appAuthorizeSetting.locationAuthorized === 'authorized',
|
|
158
|
+
/** 允许微信使用麦克风的开关 */
|
|
159
|
+
microphoneAuthorized: appAuthorizeSetting.microphoneAuthorized === 'authorized',
|
|
160
|
+
/** 允许微信通知的开关 */
|
|
161
|
+
notificationAuthorized: appAuthorizeSetting.notificationAuthorized === 'authorized',
|
|
162
|
+
/** 允许微信通知带有提醒的开关(仅 iOS 有效) */
|
|
163
|
+
notificationAlertAuthorized: appAuthorizeSetting.notificationAlertAuthorized === 'authorized',
|
|
164
|
+
/** 允许微信通知带有标记的开关(仅 iOS 有效) */
|
|
165
|
+
notificationBadgeAuthorized: appAuthorizeSetting.notificationBadgeAuthorized === 'authorized',
|
|
166
|
+
/** 允许微信通知带有声音的开关(仅 iOS 有效) */
|
|
167
|
+
notificationSoundAuthorized: appAuthorizeSetting.notificationSoundAuthorized === 'authorized',
|
|
168
|
+
/** 允许微信使用日历的开关 */
|
|
169
|
+
phoneCalendarAuthorized: appAuthorizeSetting.phoneCalendarAuthorized === 'authorized',
|
|
170
|
+
/** `true` 表示模糊定位,`false` 表示精确定位,仅 iOS 支持 */
|
|
171
|
+
locationReducedAccuracy: appAuthorizeSetting.locationReducedAccuracy,
|
|
172
|
+
/** 小程序当前运行环境 */
|
|
173
|
+
environment: ''
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return info
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** 获取系统信息 */
|
|
180
|
+
export const getSystemInfoAsync: typeof Taro.getSystemInfoAsync = async (options = {}) => {
|
|
181
|
+
const { success, fail, complete } = options
|
|
182
|
+
const handle = new MethodHandler({ name: 'getSystemInfoAsync', success, fail, complete })
|
|
183
|
+
|
|
184
|
+
try {
|
|
185
|
+
const info = await getSystemInfoSync()
|
|
186
|
+
return handle.success(info)
|
|
187
|
+
} catch (error) {
|
|
188
|
+
return handle.fail({
|
|
189
|
+
errMsg: error
|
|
190
|
+
})
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** 获取系统信息 */
|
|
195
|
+
export const getSystemInfo: typeof Taro.getSystemInfo = async (options = {}) => {
|
|
196
|
+
const { success, fail, complete } = options
|
|
197
|
+
const handle = new MethodHandler({ name: 'getSystemInfo', success, fail, complete })
|
|
198
|
+
|
|
199
|
+
try {
|
|
200
|
+
const info = await getSystemInfoSync()
|
|
201
|
+
return handle.success(info)
|
|
202
|
+
} catch (error) {
|
|
203
|
+
return handle.fail({
|
|
204
|
+
errMsg: error
|
|
205
|
+
})
|
|
206
|
+
}
|
|
207
|
+
}
|
|
@@ -5,7 +5,7 @@ interface IAction {
|
|
|
5
5
|
args: any[]
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
const TextBaseLineMap: Record<keyof Taro.CanvasContext.
|
|
8
|
+
const TextBaseLineMap: Record<keyof Taro.CanvasContext.TextBaseline, CanvasTextBaseline> = {
|
|
9
9
|
top: 'top',
|
|
10
10
|
bottom: 'bottom',
|
|
11
11
|
middle: 'middle',
|
|
@@ -16,12 +16,17 @@ export class CanvasContext implements Taro.CanvasContext {
|
|
|
16
16
|
__raw__: CanvasRenderingContext2D
|
|
17
17
|
actions: IAction[] = []
|
|
18
18
|
|
|
19
|
+
constructor (canvas, ctx) {
|
|
20
|
+
this.canvas = canvas
|
|
21
|
+
this.ctx = ctx
|
|
22
|
+
}
|
|
23
|
+
|
|
19
24
|
set ctx (e: CanvasRenderingContext2D) {
|
|
20
25
|
this.__raw__ = e
|
|
21
26
|
}
|
|
22
27
|
|
|
23
28
|
get ctx () {
|
|
24
|
-
return this.__raw__
|
|
29
|
+
return this.__raw__ || {}
|
|
25
30
|
}
|
|
26
31
|
|
|
27
32
|
canvas: HTMLCanvasElement
|
|
@@ -30,13 +35,11 @@ export class CanvasContext implements Taro.CanvasContext {
|
|
|
30
35
|
this.actions.length = 0
|
|
31
36
|
}
|
|
32
37
|
|
|
33
|
-
protected enqueueActions (func: IAction['func']) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
})
|
|
39
|
-
}
|
|
38
|
+
protected enqueueActions (func: IAction['func'], ...args) {
|
|
39
|
+
this.actions.push({
|
|
40
|
+
func,
|
|
41
|
+
args
|
|
42
|
+
})
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
set fillStyle (e) { this.enqueueActions(() => { this.ctx.fillStyle = e }) }
|
|
@@ -82,15 +85,15 @@ export class CanvasContext implements Taro.CanvasContext {
|
|
|
82
85
|
get filter () { return this.ctx.filter }
|
|
83
86
|
/** 小程序文档中不包括 ↑↑↑ */
|
|
84
87
|
|
|
85
|
-
arc
|
|
86
|
-
arcTo
|
|
87
|
-
beginPath
|
|
88
|
-
bezierCurveTo
|
|
89
|
-
clearRect
|
|
90
|
-
clip
|
|
91
|
-
closePath
|
|
88
|
+
arc (...args) { return this.enqueueActions(this.ctx.arc, ...args) }
|
|
89
|
+
arcTo (...args) { return this.enqueueActions(this.ctx.arcTo, ...args) }
|
|
90
|
+
beginPath (...args) { return this.enqueueActions(this.ctx.beginPath, ...args) }
|
|
91
|
+
bezierCurveTo (...args) { return this.enqueueActions(this.ctx.bezierCurveTo, ...args) }
|
|
92
|
+
clearRect (...args) { return this.enqueueActions(this.ctx.clearRect, ...args) }
|
|
93
|
+
clip (...args) { return this.enqueueActions(this.ctx.clip, ...args) }
|
|
94
|
+
closePath (...args) { return this.enqueueActions(this.ctx.closePath, ...args) }
|
|
92
95
|
|
|
93
|
-
createPattern (image: string, repetition: keyof Taro.CanvasContext.
|
|
96
|
+
createPattern (image: string, repetition: keyof Taro.CanvasContext.Repetition): void {
|
|
94
97
|
return this.createPattern(image, repetition)
|
|
95
98
|
}
|
|
96
99
|
|
|
@@ -139,17 +142,17 @@ export class CanvasContext implements Taro.CanvasContext {
|
|
|
139
142
|
})
|
|
140
143
|
}
|
|
141
144
|
|
|
142
|
-
fill
|
|
143
|
-
fillRect
|
|
144
|
-
fillText
|
|
145
|
-
lineTo
|
|
146
|
-
moveTo
|
|
147
|
-
quadraticCurveTo
|
|
148
|
-
rect
|
|
149
|
-
restore
|
|
150
|
-
rotate
|
|
151
|
-
save
|
|
152
|
-
scale
|
|
145
|
+
fill (...args) { return this.enqueueActions(this.ctx.fill, ...args) }
|
|
146
|
+
fillRect (...args) { return this.enqueueActions(this.ctx.fillRect, ...args) }
|
|
147
|
+
fillText (...args) { return this.enqueueActions(this.ctx.fillText, ...args) }
|
|
148
|
+
lineTo (...args) { return this.enqueueActions(this.ctx.lineTo, ...args) }
|
|
149
|
+
moveTo (...args) { return this.enqueueActions(this.ctx.moveTo, ...args) }
|
|
150
|
+
quadraticCurveTo (...args) { return this.enqueueActions(this.ctx.quadraticCurveTo, ...args) }
|
|
151
|
+
rect (...args) { return this.enqueueActions(this.ctx.rect, ...args) }
|
|
152
|
+
restore (...args) { return this.enqueueActions(this.ctx.restore, ...args) }
|
|
153
|
+
rotate (...args) { return this.enqueueActions(this.ctx.rotate, ...args) }
|
|
154
|
+
save (...args) { return this.enqueueActions(this.ctx.save, ...args) }
|
|
155
|
+
scale (...args) { return this.enqueueActions(this.ctx.scale, ...args) }
|
|
153
156
|
|
|
154
157
|
setFillStyle (color: string | CanvasGradient): void {
|
|
155
158
|
this.enqueueActions(() => { this.ctx.fillStyle = color })
|
|
@@ -163,7 +166,7 @@ export class CanvasContext implements Taro.CanvasContext {
|
|
|
163
166
|
this.globalAlpha = alpha
|
|
164
167
|
}
|
|
165
168
|
|
|
166
|
-
setLineCap (lineCap: keyof Taro.CanvasContext.
|
|
169
|
+
setLineCap (lineCap: keyof Taro.CanvasContext.LineCap): void {
|
|
167
170
|
this.lineCap = lineCap
|
|
168
171
|
}
|
|
169
172
|
|
|
@@ -174,7 +177,7 @@ export class CanvasContext implements Taro.CanvasContext {
|
|
|
174
177
|
})
|
|
175
178
|
}
|
|
176
179
|
|
|
177
|
-
setLineJoin (lineJoin: keyof Taro.CanvasContext.
|
|
180
|
+
setLineJoin (lineJoin: keyof Taro.CanvasContext.LineJoin): void {
|
|
178
181
|
this.lineJoin = lineJoin
|
|
179
182
|
}
|
|
180
183
|
|
|
@@ -199,23 +202,23 @@ export class CanvasContext implements Taro.CanvasContext {
|
|
|
199
202
|
this.enqueueActions(() => { this.ctx.strokeStyle = color })
|
|
200
203
|
}
|
|
201
204
|
|
|
202
|
-
setTextAlign (align: keyof Taro.CanvasContext.
|
|
205
|
+
setTextAlign (align: keyof Taro.CanvasContext.Align): void {
|
|
203
206
|
this.textAlign = align
|
|
204
207
|
}
|
|
205
208
|
|
|
206
|
-
setTextBaseline (textBaseline: keyof Taro.CanvasContext.
|
|
209
|
+
setTextBaseline (textBaseline: keyof Taro.CanvasContext.TextBaseline): void {
|
|
207
210
|
this.textBaseline = TextBaseLineMap[textBaseline] || 'alphabetic'
|
|
208
211
|
}
|
|
209
212
|
|
|
210
|
-
setTransform
|
|
211
|
-
stroke
|
|
212
|
-
strokeRect
|
|
213
|
-
strokeText
|
|
214
|
-
transform
|
|
215
|
-
translate
|
|
213
|
+
setTransform (...args) { return this.enqueueActions(this.ctx.setTransform, ...args) }
|
|
214
|
+
stroke (...args) { return this.enqueueActions(this.ctx.stroke, ...args) }
|
|
215
|
+
strokeRect (...args) { return this.enqueueActions(this.ctx.strokeRect, ...args) }
|
|
216
|
+
strokeText (...args) { return this.enqueueActions(this.ctx.strokeText, ...args) }
|
|
217
|
+
transform (...args) { return this.enqueueActions(this.ctx.transform, ...args) }
|
|
218
|
+
translate (...args) { return this.enqueueActions(this.ctx.translate, ...args) }
|
|
216
219
|
|
|
217
220
|
measureText (text: string): TextMetrics {
|
|
218
|
-
return this.measureText(text)
|
|
221
|
+
return this.ctx.measureText(text)
|
|
219
222
|
}
|
|
220
223
|
|
|
221
224
|
createCircularGradient (x: number, y: number, r: number): CanvasGradient {
|
|
@@ -6,10 +6,10 @@ import { CanvasContext } from './CanvasContext'
|
|
|
6
6
|
* 创建 canvas 的绘图上下文 CanvasContext 对象
|
|
7
7
|
*/
|
|
8
8
|
export const createCanvasContext: typeof Taro.createCanvasContext = (canvasId, inst) => {
|
|
9
|
-
const context = new CanvasContext()
|
|
10
9
|
const el = findDOM(inst) as HTMLElement
|
|
11
10
|
const canvas = el?.querySelector(`canvas[canvas-id="${canvasId}"]`) as HTMLCanvasElement
|
|
12
|
-
const ctx = canvas?.getContext('2d')
|
|
11
|
+
const ctx = canvas?.getContext('2d') as CanvasRenderingContext2D
|
|
12
|
+
const context = new CanvasContext(canvas, ctx)
|
|
13
13
|
if (!ctx) return context
|
|
14
14
|
context.canvas = canvas
|
|
15
15
|
context.ctx = ctx
|
package/src/api/canvas/index.ts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import { temporarilyNotSupport } from '../utils'
|
|
2
2
|
|
|
3
3
|
// 画布
|
|
4
|
+
|
|
5
|
+
/** 创建离屏 canvas 实例 */
|
|
4
6
|
export const createOffscreenCanvas = temporarilyNotSupport('createOffscreenCanvas')
|
|
7
|
+
|
|
8
|
+
/** 创建 canvas 的绘图上下文 CanvasContext 对象 */
|
|
5
9
|
export * from './createCanvasContext'
|
|
10
|
+
|
|
11
|
+
/** 把当前画布指定区域的内容导出生成指定大小的图片 */
|
|
6
12
|
export * from './canvasToTempFilePath'
|
|
13
|
+
|
|
14
|
+
/** 将像素数据绘制到画布 */
|
|
7
15
|
export * from './canvasPutImageData'
|
|
8
|
-
export * from './canvasGetImageData'
|
|
9
16
|
|
|
10
|
-
|
|
17
|
+
/** 获取 canvas 区域隐含的像素数据 */
|
|
18
|
+
export * from './canvasGetImageData'
|
package/src/api/cloud/index.ts
CHANGED
|
@@ -8,6 +8,7 @@ export class cloud implements Taro.cloud {
|
|
|
8
8
|
|
|
9
9
|
CloudID = temporarilyNotSupport('cloud.CloudID')
|
|
10
10
|
|
|
11
|
+
// @ts-ignore
|
|
11
12
|
callFunction = temporarilyNotSupport('cloud.callFunction')
|
|
12
13
|
|
|
13
14
|
// @ts-ignore
|
|
@@ -16,12 +17,15 @@ export class cloud implements Taro.cloud {
|
|
|
16
17
|
// @ts-ignore
|
|
17
18
|
downloadFile = temporarilyNotSupport('cloud.downloadFile')
|
|
18
19
|
|
|
20
|
+
// @ts-ignore
|
|
19
21
|
getTempFileURL = temporarilyNotSupport('cloud.getTempFileURL')
|
|
20
22
|
|
|
23
|
+
// @ts-ignore
|
|
21
24
|
deleteFile = temporarilyNotSupport('cloud.deleteFile')
|
|
22
25
|
|
|
23
26
|
// @ts-ignore
|
|
24
27
|
database = temporarilyNotSupport('cloud.database')
|
|
25
28
|
|
|
29
|
+
// @ts-ignore
|
|
26
30
|
callContainer = temporarilyNotSupport('cloud.callContainer')
|
|
27
31
|
}
|
|
@@ -1,5 +1,22 @@
|
|
|
1
|
+
import Taro from '@tarojs/api'
|
|
1
2
|
import { temporarilyNotSupport } from '../utils'
|
|
3
|
+
import { MethodHandler } from '../utils/handler'
|
|
2
4
|
|
|
3
5
|
// 电量
|
|
4
6
|
export const getBatteryInfoSync = temporarilyNotSupport('getBatteryInfoSync')
|
|
5
|
-
|
|
7
|
+
|
|
8
|
+
export const getBatteryInfo: typeof Taro.getBatteryInfo = async ({ success, fail, complete } = {}) => {
|
|
9
|
+
const handle = new MethodHandler({ name: 'getBatteryInfo', success, fail, complete })
|
|
10
|
+
try {
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
const battery = await navigator.getBattery?.()
|
|
13
|
+
return handle.success({
|
|
14
|
+
isCharging: battery.charging,
|
|
15
|
+
level: Number(battery.level || 0) * 100
|
|
16
|
+
})
|
|
17
|
+
} catch (error) {
|
|
18
|
+
return handle.fail({
|
|
19
|
+
errMsg: error?.message || error
|
|
20
|
+
})
|
|
21
|
+
}
|
|
22
|
+
}
|
package/src/api/device/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Taro from '@tarojs/api'
|
|
2
2
|
|
|
3
|
-
import { MethodHandler } from '
|
|
4
|
-
import { temporarilyNotSupport } from '
|
|
3
|
+
import { CallbackManager, MethodHandler } from '../utils/handler'
|
|
4
|
+
import { temporarilyNotSupport } from '../utils'
|
|
5
5
|
|
|
6
6
|
function getConnection () {
|
|
7
7
|
// @ts-ignore
|
|
@@ -13,7 +13,7 @@ export const getNetworkType: typeof Taro.getNetworkType = (options = {}) => {
|
|
|
13
13
|
const { success, fail, complete } = options
|
|
14
14
|
const handle = new MethodHandler<Taro.getNetworkType.SuccessCallbackResult>({ name: 'getNetworkType', success, fail, complete })
|
|
15
15
|
|
|
16
|
-
let networkType: keyof Taro.getNetworkType.
|
|
16
|
+
let networkType: keyof Taro.getNetworkType.NetworkType = 'unknown'
|
|
17
17
|
// 浏览器不支持获取网络状态
|
|
18
18
|
if (!connection) {
|
|
19
19
|
return handle.success({ networkType })
|
|
@@ -51,20 +51,40 @@ export const getNetworkType: typeof Taro.getNetworkType = (options = {}) => {
|
|
|
51
51
|
return handle.success({ networkType })
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
const networkStatusManager = new CallbackManager()
|
|
55
|
+
|
|
56
|
+
const networkStatusListener = async () => {
|
|
57
|
+
const { networkType } = await getNetworkType()
|
|
58
|
+
const isConnected = networkType !== 'none'
|
|
59
|
+
const obj = { isConnected, networkType }
|
|
60
|
+
networkStatusManager.trigger(obj)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 在最近的八次网络请求中, 出现下列三个现象之一则判定弱网。
|
|
65
|
+
* - 出现三次以上连接超时
|
|
66
|
+
* - 出现三次 rtt 超过 400
|
|
67
|
+
* - 出现三次以上的丢包
|
|
68
|
+
* > 弱网事件通知规则是: 弱网状态变化时立即通知, 状态不变时 30s 内最多通知一次。
|
|
69
|
+
*/
|
|
70
|
+
export const onNetworkWeakChange = temporarilyNotSupport('onNetworkWeakChange')
|
|
71
|
+
|
|
72
|
+
export const onNetworkStatusChange: typeof Taro.onNetworkStatusChange = callback => {
|
|
73
|
+
networkStatusManager.add(callback)
|
|
74
|
+
const connection = getConnection()
|
|
75
|
+
if (connection && networkStatusManager.count() === 1) {
|
|
76
|
+
connection.addEventListener('change', networkStatusListener)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export const offNetworkWeakChange = temporarilyNotSupport('offNetworkStatusChange')
|
|
81
|
+
|
|
82
|
+
export const offNetworkStatusChange: typeof Taro.offNetworkStatusChange = callback => {
|
|
83
|
+
networkStatusManager.remove(callback)
|
|
55
84
|
const connection = getConnection()
|
|
56
|
-
if (connection) {
|
|
57
|
-
connection.
|
|
58
|
-
getNetworkType()
|
|
59
|
-
.then(res => {
|
|
60
|
-
const { networkType } = res
|
|
61
|
-
const isConnected = networkType !== 'none'
|
|
62
|
-
const obj = { isConnected, networkType }
|
|
63
|
-
cb(obj)
|
|
64
|
-
})
|
|
65
|
-
})
|
|
85
|
+
if (connection && networkStatusManager.count() === 0) {
|
|
86
|
+
connection.removeEventListener('change', networkStatusListener)
|
|
66
87
|
}
|
|
67
88
|
}
|
|
68
89
|
|
|
69
|
-
export const offNetworkStatusChange = temporarilyNotSupport('offNetworkStatusChange')
|
|
70
90
|
export const getLocalIPAddress = temporarilyNotSupport('getLocalIPAddress')
|
package/src/api/device/wifi.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { temporarilyNotSupport } from '../utils'
|
|
|
4
4
|
export const stopWifi = temporarilyNotSupport('stopWifi')
|
|
5
5
|
export const startWifi = temporarilyNotSupport('startWifi')
|
|
6
6
|
export const setWifiList = temporarilyNotSupport('setWifiList')
|
|
7
|
+
export const onWifiConnectedWithPartialInfo = temporarilyNotSupport('onWifiConnectedWithPartialInfo')
|
|
7
8
|
export const onWifiConnected = temporarilyNotSupport('onWifiConnected')
|
|
8
9
|
export const onGetWifiList = temporarilyNotSupport('onGetWifiList')
|
|
9
10
|
export const offWifiConnected = temporarilyNotSupport('offWifiConnected')
|