@mpxjs/api-proxy 2.9.6 → 2.9.11-test.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/package.json +2 -2
- package/src/common/js/index.js +0 -1
- package/src/{mini → common/js}/promisify.js +4 -2
- package/src/common/js/utils.js +32 -1
- package/src/common/js/web.js +25 -15
- package/src/index.js +4 -75
- package/src/install.js +62 -0
- package/src/{web → platform}/api/action-sheet/ActionSheet.js +6 -6
- package/src/platform/api/action-sheet/index.ali.js +28 -0
- package/src/platform/api/action-sheet/index.js +9 -0
- package/src/platform/api/add-phone-contact/index.ali.js +13 -0
- package/src/platform/api/add-phone-contact/index.js +9 -0
- package/src/platform/api/animation/index.js +9 -0
- package/src/platform/api/app/index.js +24 -0
- package/src/platform/api/audio/index.js +9 -0
- package/src/platform/api/base/index.js +12 -0
- package/src/platform/api/ble-connection/index.ali.js +17 -0
- package/src/platform/api/ble-connection/index.js +15 -0
- package/src/platform/api/canvas/index.ali.js +16 -0
- package/src/platform/api/canvas/index.js +15 -0
- package/src/platform/api/check-session/index.js +9 -0
- package/src/platform/api/clipboard-data/index.ali.js +30 -0
- package/src/platform/api/clipboard-data/index.js +12 -0
- package/src/platform/api/create-intersection-observer/index.ali.js +7 -0
- package/src/platform/api/create-intersection-observer/index.js +9 -0
- package/src/platform/api/create-selector-query/index.ali.js +35 -0
- package/src/platform/api/create-selector-query/index.js +9 -0
- package/src/platform/api/device/network/index.js +15 -0
- package/src/platform/api/file/index.ali.js +35 -0
- package/src/platform/api/file/index.js +12 -0
- package/src/platform/api/get-user-info/index.ali.js +18 -0
- package/src/platform/api/get-user-info/index.js +9 -0
- package/src/platform/api/image/index.ali.js +36 -0
- package/src/platform/api/image/index.js +12 -0
- package/src/platform/api/login/index.ali.js +15 -0
- package/src/platform/api/login/index.js +9 -0
- package/src/platform/api/make-phone-call/index.ali.js +12 -0
- package/src/platform/api/make-phone-call/index.js +9 -0
- package/src/{web → platform}/api/modal/Modal.js +2 -7
- package/src/platform/api/modal/index.ali.js +32 -0
- package/src/platform/api/modal/index.js +9 -0
- package/src/platform/api/next-tick/index.ali.js +7 -0
- package/src/platform/api/next-tick/index.js +9 -0
- package/src/platform/api/next-tick/index.tt.js +7 -0
- package/src/platform/api/page-scroll-to/index.js +9 -0
- package/src/platform/api/pull-down/index.js +12 -0
- package/src/{web/api/pull-down/index.js → platform/api/pull-down/index.web.js} +14 -22
- package/src/platform/api/request/index.ali.js +26 -0
- package/src/platform/api/request/index.js +9 -0
- package/src/{web/api/request/index.js → platform/api/request/index.web.js} +2 -5
- package/src/platform/api/request-payment/index.ali.js +45 -0
- package/src/platform/api/request-payment/index.js +9 -0
- package/src/platform/api/route/index.js +21 -0
- package/src/{web/api/route/index.js → platform/api/route/index.web.js} +59 -80
- package/src/platform/api/scan-code/index.ali.js +17 -0
- package/src/platform/api/scan-code/index.js +9 -0
- package/src/platform/api/screen-brightness/index.ali.js +26 -0
- package/src/platform/api/screen-brightness/index.js +12 -0
- package/src/platform/api/set-navigation-bar/index.ali.js +25 -0
- package/src/platform/api/set-navigation-bar/index.js +12 -0
- package/src/{web/api/set-navigation-bar/index.js → platform/api/set-navigation-bar/index.web.js} +0 -1
- package/src/{web → platform}/api/socket/SocketTask.js +1 -1
- package/src/platform/api/socket/index.js +9 -0
- package/src/platform/api/storage/index.ali.js +59 -0
- package/src/platform/api/storage/index.js +36 -0
- package/src/{web/api/storage/index.js → platform/api/storage/index.web.js} +0 -10
- package/src/platform/api/system/index.ali.js +38 -0
- package/src/platform/api/system/index.js +12 -0
- package/src/{web/api/system/index.js → platform/api/system/index.web.js} +0 -1
- package/src/platform/api/tab-bar/index.js +18 -0
- package/src/{web/api/tab-bar/index.js → platform/api/tab-bar/index.web.js} +0 -8
- package/src/{web → platform}/api/toast/Toast.js +1 -3
- package/src/platform/api/toast/index.ali.js +39 -0
- package/src/platform/api/toast/index.js +18 -0
- package/src/platform/api/video/index.js +9 -0
- package/src/platform/api/window/index.js +12 -0
- package/src/platform/index.js +106 -0
- package/src/common/js/ToPromise.js +0 -25
- package/src/index.web.js +0 -24
- package/src/mini/platform/wxToAli.js +0 -667
- package/src/mini/platform/wxToQq.js +0 -20
- package/src/mini/platform/wxToTt.js +0 -9
- package/src/mini/transform.js +0 -71
- package/src/web/api/index.js +0 -68
- /package/src/{web/api/action-sheet/index.js → platform/api/action-sheet/index.web.js} +0 -0
- /package/src/{web → platform}/api/animation/animation.js +0 -0
- /package/src/{web/api/animation/index.js → platform/api/animation/index.web.js} +0 -0
- /package/src/{web/api/app/index.js → platform/api/app/index.web.js} +0 -0
- /package/src/{web/api/audio/index.js → platform/api/audio/index.web.js} +0 -0
- /package/src/{web → platform}/api/base/base64.js +0 -0
- /package/src/{web/api/base/index.js → platform/api/base/index.web.js} +0 -0
- /package/src/{web → platform}/api/create-intersection-observer/IntersectionObserver.js +0 -0
- /package/src/{web/api/create-intersection-observer/index.js → platform/api/create-intersection-observer/index.web.js} +0 -0
- /package/src/{web → platform}/api/create-selector-query/NodesRef.js +0 -0
- /package/src/{web → platform}/api/create-selector-query/SelectQuery.js +0 -0
- /package/src/{web/api/create-selector-query/index.js → platform/api/create-selector-query/index.web.js} +0 -0
- /package/src/{web → platform}/api/device/network/getNetworkType.js +0 -0
- /package/src/{web/api/device/network/index.js → platform/api/device/network/index.web.js} +0 -0
- /package/src/{web → platform}/api/device/network/onNetworkStatusChange.js +0 -0
- /package/src/{web/api/event-channel/index.js → platform/api/event-channel/index.web.js} +0 -0
- /package/src/{web/api/preview-image → platform/api/image}/Preview.js +0 -0
- /package/src/{web/api/preview-image/index.js → platform/api/image/index.web.js} +0 -0
- /package/src/{web/api/modal/index.js → platform/api/modal/index.web.js} +0 -0
- /package/src/{web/api/next-tick/index.js → platform/api/next-tick/index.web.js} +0 -0
- /package/src/{web/api/page-scroll-to/index.js → platform/api/page-scroll-to/index.web.js} +0 -0
- /package/src/{web → platform}/api/request/RequestTask.js +0 -0
- /package/src/{web/api/socket/index.js → platform/api/socket/index.web.js} +0 -0
- /package/src/{web/api/toast/index.js → platform/api/toast/index.web.js} +0 -0
- /package/src/{web/api/video/index.js → platform/api/video/index.web.js} +0 -0
- /package/src/{web/api/window/index.js → platform/api/window/index.web.js} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/api-proxy",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.11-test.0",
|
|
4
4
|
"description": "convert miniprogram API at each end",
|
|
5
5
|
"module": "src/index.js",
|
|
6
6
|
"types": "@types/index.d.ts",
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"axios": "^0.21.1"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "d244d661acb081b709fc99ca8f6add541f793877"
|
|
43
43
|
}
|
package/src/common/js/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { genFromMap, getEnvObj, noop } from '
|
|
1
|
+
import { genFromMap, getEnvObj, noop } from './utils'
|
|
2
2
|
|
|
3
3
|
const envObj = getEnvObj()
|
|
4
4
|
|
|
@@ -28,7 +28,9 @@ const blackList = [
|
|
|
28
28
|
'getMenuButtonBoundingClientRect',
|
|
29
29
|
'reportMonitor',
|
|
30
30
|
'createOffscreenCanvas',
|
|
31
|
-
'reportEvent'
|
|
31
|
+
'reportEvent',
|
|
32
|
+
'connectSocket',
|
|
33
|
+
'base64ToArrayBuffer'
|
|
32
34
|
]
|
|
33
35
|
|
|
34
36
|
function getMapFromList (list) {
|
package/src/common/js/utils.js
CHANGED
|
@@ -29,7 +29,6 @@ function changeOpts (options, updateOrRemoveOpt = {}, extraOpt = {}) {
|
|
|
29
29
|
})
|
|
30
30
|
|
|
31
31
|
opts = Object.assign({}, opts, extraOpt)
|
|
32
|
-
|
|
33
32
|
return opts
|
|
34
33
|
}
|
|
35
34
|
|
|
@@ -77,6 +76,31 @@ function getEnvObj () {
|
|
|
77
76
|
return qa
|
|
78
77
|
case 'dd':
|
|
79
78
|
return dd
|
|
79
|
+
case 'web':
|
|
80
|
+
return {}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function getEnvStr () {
|
|
85
|
+
switch (__mpx_mode__) {
|
|
86
|
+
case 'wx':
|
|
87
|
+
return 'wx'
|
|
88
|
+
case 'ali':
|
|
89
|
+
return 'ali'
|
|
90
|
+
case 'swan':
|
|
91
|
+
return 'swan'
|
|
92
|
+
case 'qq':
|
|
93
|
+
return 'qq'
|
|
94
|
+
case 'tt':
|
|
95
|
+
return 'tt'
|
|
96
|
+
case 'jd':
|
|
97
|
+
return 'jd'
|
|
98
|
+
case 'qa':
|
|
99
|
+
return 'qa'
|
|
100
|
+
case 'dd':
|
|
101
|
+
return 'dd'
|
|
102
|
+
case 'web':
|
|
103
|
+
return 'web'
|
|
80
104
|
}
|
|
81
105
|
}
|
|
82
106
|
|
|
@@ -87,6 +111,11 @@ function warn (msg) {
|
|
|
87
111
|
function error (msg) {
|
|
88
112
|
console.error && console.error(`[@mpxjs/api-proxy error]:\n ${msg}`)
|
|
89
113
|
}
|
|
114
|
+
function envError (method) {
|
|
115
|
+
return () => {
|
|
116
|
+
console.error && console.error(`[@mpxjs/api-proxy error]:\n ${__mpx_mode__}环境不支持${method}方法`)
|
|
117
|
+
}
|
|
118
|
+
}
|
|
90
119
|
|
|
91
120
|
function noop () {
|
|
92
121
|
}
|
|
@@ -108,7 +137,9 @@ export {
|
|
|
108
137
|
handleSuccess,
|
|
109
138
|
genFromMap,
|
|
110
139
|
getEnvObj,
|
|
140
|
+
getEnvStr,
|
|
111
141
|
error,
|
|
142
|
+
envError,
|
|
112
143
|
warn,
|
|
113
144
|
noop,
|
|
114
145
|
makeMap,
|
package/src/common/js/web.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { isBrowser } from './utils'
|
|
2
|
+
|
|
1
3
|
function webHandleSuccess (result, success, complete) {
|
|
2
4
|
typeof success === 'function' && success(result)
|
|
3
5
|
typeof complete === 'function' && complete(result)
|
|
@@ -33,22 +35,30 @@ function createDom (tag, attrs = {}, children = []) {
|
|
|
33
35
|
// 在H5中,直接绑定 click 可能出现延时问题,很多点击可以关闭的组件被唤出之后,有概率立马触发点击事件,导致组件被关闭。
|
|
34
36
|
// 使用该方法通过 touchstart 和 touchend 模拟 click 事件,解决延时问题。
|
|
35
37
|
function bindTap (dom, handler) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
startTime =
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
const isTouchDevice = isBrowser && document && ('ontouchstart' in document.documentElement)
|
|
39
|
+
if (isTouchDevice) {
|
|
40
|
+
let startTime = 0; let x = 0; let y = 0
|
|
41
|
+
const touchStart = (e) => {
|
|
42
|
+
startTime = Date.now()
|
|
43
|
+
x = e.touches[0].pageX
|
|
44
|
+
y = e.touches[0].pageY
|
|
45
|
+
}
|
|
46
|
+
const touchEnd = (e) => {
|
|
47
|
+
if (Date.now() - startTime < 300 && Math.abs(e.changedTouches[0].pageX - x) < 10 && Math.abs(e.changedTouches[0].pageY - y) < 10) {
|
|
48
|
+
handler(e)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
dom.addEventListener('touchstart', touchStart)
|
|
52
|
+
dom.addEventListener('touchend', touchEnd)
|
|
53
|
+
return () => {
|
|
54
|
+
dom.removeEventListener('touchstart', touchStart)
|
|
55
|
+
dom.removeEventListener('touchend', touchEnd)
|
|
56
|
+
}
|
|
57
|
+
} else {
|
|
58
|
+
dom.addEventListener('click', handler)
|
|
59
|
+
return () => {
|
|
60
|
+
dom.removeEventListener('click', handler)
|
|
45
61
|
}
|
|
46
|
-
}
|
|
47
|
-
dom.addEventListener('touchstart', touchStart)
|
|
48
|
-
dom.addEventListener('touchend', touchEnd)
|
|
49
|
-
return () => {
|
|
50
|
-
dom.removeEventListener('touchstart', touchStart)
|
|
51
|
-
dom.removeEventListener('touchend', touchEnd)
|
|
52
62
|
}
|
|
53
63
|
}
|
|
54
64
|
|
package/src/index.js
CHANGED
|
@@ -1,75 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export default
|
|
5
|
-
const {
|
|
6
|
-
usePromise = false, // 是否转为 promise 格式
|
|
7
|
-
whiteList = [], // 强制变成 promise 格式的 api
|
|
8
|
-
blackList = [], // 强制不变成 promise 格式的 api
|
|
9
|
-
platform = {},
|
|
10
|
-
exclude = ['shareImageMessage'], // 强制不进行代理的api,临时fix微信分享朋友圈白屏
|
|
11
|
-
custom = {}, // 自定义转化规则
|
|
12
|
-
fallbackMap = {} // 对于不支持的API,允许配置一个映射表,接管不存在的API
|
|
13
|
-
} = options
|
|
14
|
-
|
|
15
|
-
let { from = '', to = '' } = platform
|
|
16
|
-
/* eslint-disable camelcase, no-undef */
|
|
17
|
-
if (typeof __mpx_src_mode__ !== 'undefined') {
|
|
18
|
-
if (from && from !== __mpx_src_mode__) {
|
|
19
|
-
console.warn && console.warn('the platform from field inconsistent with the current environment value\n')
|
|
20
|
-
}
|
|
21
|
-
from = `__mpx_src_mode_${__mpx_src_mode__}__`
|
|
22
|
-
} else {
|
|
23
|
-
if (!from) {
|
|
24
|
-
from = 'wx'
|
|
25
|
-
console.warn && console.warn('the platform from field is empty, wx will be used by default\n')
|
|
26
|
-
}
|
|
27
|
-
from = `__mpx_src_mode_${from}__`
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (typeof __mpx_mode__ !== 'undefined') {
|
|
31
|
-
to = __mpx_mode__
|
|
32
|
-
} else if (!to) {
|
|
33
|
-
console.warn && console.warn('the platform to field is empty, ali will be used by default\n')
|
|
34
|
-
to = 'wx'
|
|
35
|
-
}
|
|
36
|
-
/* eslint-enable */
|
|
37
|
-
|
|
38
|
-
const transedApi = transformApi({
|
|
39
|
-
exclude,
|
|
40
|
-
from,
|
|
41
|
-
to,
|
|
42
|
-
custom
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
const promisedApi = usePromise ? promisify(transedApi, whiteList, blackList) : {}
|
|
46
|
-
const allApi = Object.assign({}, transedApi, promisedApi)
|
|
47
|
-
|
|
48
|
-
Object.keys(allApi).forEach(api => {
|
|
49
|
-
try {
|
|
50
|
-
if (typeof allApi[api] !== 'function') {
|
|
51
|
-
target[api] = allApi[api]
|
|
52
|
-
return
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
target[api] = (...args) => {
|
|
56
|
-
return allApi[api].apply(target, args)
|
|
57
|
-
}
|
|
58
|
-
} catch (e) {
|
|
59
|
-
} // 支付宝不支持重写 call 方法
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
// Fallback Map option
|
|
63
|
-
Object.keys(fallbackMap)
|
|
64
|
-
.forEach(k => {
|
|
65
|
-
if (!target[k]) {
|
|
66
|
-
target[k] = fallbackMap[k]
|
|
67
|
-
}
|
|
68
|
-
})
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export function getProxy (options = {}) {
|
|
72
|
-
const apiProxy = {}
|
|
73
|
-
install(apiProxy, options)
|
|
74
|
-
return apiProxy
|
|
75
|
-
}
|
|
1
|
+
import install, { getProxy } from './install'
|
|
2
|
+
export * from './platform'
|
|
3
|
+
export { getProxy }
|
|
4
|
+
export default install
|
package/src/install.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import * as platformApi from './platform'
|
|
2
|
+
import { getEnvObj, getEnvStr } from './common/js'
|
|
3
|
+
import promisify from './common/js/promisify'
|
|
4
|
+
|
|
5
|
+
export default function install (target, options = {}) {
|
|
6
|
+
const {
|
|
7
|
+
usePromise = false, // 是否转为 promise 格式
|
|
8
|
+
whiteList = [], // 强制变成 promise 格式的 api
|
|
9
|
+
blackList = [], // 强制不变成 promise 格式的 api
|
|
10
|
+
custom = {}, // 自定义转化规则
|
|
11
|
+
fallbackMap = {} // 对于不支持的API,允许配置一个映射表,接管不存在的API
|
|
12
|
+
} = options
|
|
13
|
+
|
|
14
|
+
let transedApi = {}
|
|
15
|
+
const envStr = getEnvStr()
|
|
16
|
+
|
|
17
|
+
if (__mpx_env__ === 'web') {
|
|
18
|
+
transedApi = platformApi
|
|
19
|
+
} else {
|
|
20
|
+
const envObj = getEnvObj()
|
|
21
|
+
Object.keys(envObj).concat(Object.keys(platformApi)).forEach((key) => {
|
|
22
|
+
transedApi[key] = platformApi[key] || envObj[key]
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const promisedApi = usePromise ? promisify(transedApi, whiteList, blackList) : {}
|
|
27
|
+
const allApi = Object.assign({}, transedApi, promisedApi)
|
|
28
|
+
|
|
29
|
+
Object.keys(allApi).forEach(api => {
|
|
30
|
+
try {
|
|
31
|
+
if (typeof allApi[api] !== 'function') {
|
|
32
|
+
target[api] = allApi[api]
|
|
33
|
+
return
|
|
34
|
+
}
|
|
35
|
+
target[api] = (...args) => {
|
|
36
|
+
return allApi[api].apply(target, args)
|
|
37
|
+
}
|
|
38
|
+
} catch (e) {
|
|
39
|
+
} // 支付宝不支持重写 call 方法
|
|
40
|
+
})
|
|
41
|
+
if (custom[envStr]) {
|
|
42
|
+
Object.keys(custom[envStr])
|
|
43
|
+
.forEach(k => {
|
|
44
|
+
target[k] = (...args) => {
|
|
45
|
+
return custom[envStr][k].apply(target, args)
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
// Fallback Map option
|
|
50
|
+
Object.keys(fallbackMap)
|
|
51
|
+
.forEach(k => {
|
|
52
|
+
if (!target[k]) {
|
|
53
|
+
target[k] = fallbackMap[k]
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function getProxy (options = {}) {
|
|
59
|
+
const apiProxy = {}
|
|
60
|
+
install(apiProxy, options)
|
|
61
|
+
return apiProxy
|
|
62
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { webHandleSuccess, webHandleFail, createDom, bindTap, getRootElement } from '../../../common/js'
|
|
2
2
|
import '../../../common/stylus/ActionSheet.styl'
|
|
3
3
|
|
|
4
|
-
export default class ActionSheet
|
|
4
|
+
export default class ActionSheet {
|
|
5
5
|
constructor () {
|
|
6
|
-
super()
|
|
6
|
+
// super()
|
|
7
7
|
this.defaultOpts = {
|
|
8
8
|
itemList: [],
|
|
9
9
|
itemColor: '#000000',
|
|
@@ -45,7 +45,7 @@ export default class ActionSheet extends ToPromise {
|
|
|
45
45
|
tapIndex: index
|
|
46
46
|
}
|
|
47
47
|
webHandleSuccess(res, opts.success, opts.complete)
|
|
48
|
-
this.toPromiseResolve(res)
|
|
48
|
+
// this.toPromiseResolve(res)
|
|
49
49
|
}))
|
|
50
50
|
list.appendChild(sheet)
|
|
51
51
|
})
|
|
@@ -58,7 +58,7 @@ export default class ActionSheet extends ToPromise {
|
|
|
58
58
|
this.hide()
|
|
59
59
|
const err = { errMsg: 'showActionSheet:fail cancel' }
|
|
60
60
|
webHandleFail(err, opts.fail, opts.complete)
|
|
61
|
-
!opts.fail && this.toPromiseReject(err)
|
|
61
|
+
// !opts.fail && this.toPromiseReject(err)
|
|
62
62
|
}))
|
|
63
63
|
// make transition next frame
|
|
64
64
|
this.actionSheet.classList.add('show')
|
|
@@ -67,7 +67,7 @@ export default class ActionSheet extends ToPromise {
|
|
|
67
67
|
this.box.classList.add('show')
|
|
68
68
|
}, 17)
|
|
69
69
|
|
|
70
|
-
return this.toPromiseInitPromise()
|
|
70
|
+
// return this.toPromiseInitPromise()
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
hide () {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { changeOpts, noop } from '../../../common/js'
|
|
2
|
+
function showActionSheet (options = {}) {
|
|
3
|
+
const opts = changeOpts(options, {
|
|
4
|
+
itemList: 'items'
|
|
5
|
+
})
|
|
6
|
+
|
|
7
|
+
const cacheSuc = opts.success || noop
|
|
8
|
+
const cacheFail = opts.fail || noop
|
|
9
|
+
|
|
10
|
+
opts.success = function (res) {
|
|
11
|
+
const sucRes = changeOpts(res, {
|
|
12
|
+
index: 'tapIndex'
|
|
13
|
+
})
|
|
14
|
+
if (sucRes.tapIndex === -1) {
|
|
15
|
+
cacheFail.call(this, {
|
|
16
|
+
errMsg: 'showActionSheet:fail cancel'
|
|
17
|
+
})
|
|
18
|
+
} else {
|
|
19
|
+
cacheSuc.call(this, sucRes)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
my.showActionSheet(opts)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export {
|
|
27
|
+
showActionSheet
|
|
28
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { getEnvObj, envError } from '../../../common/js'
|
|
2
|
+
|
|
3
|
+
const ENV_OBJ = getEnvObj()
|
|
4
|
+
|
|
5
|
+
const onError = ENV_OBJ.onError || envError('onError')
|
|
6
|
+
|
|
7
|
+
const offError = ENV_OBJ.offError || envError('offError')
|
|
8
|
+
|
|
9
|
+
const onAppShow = ENV_OBJ.onAppShow || envError('onAppShow')
|
|
10
|
+
|
|
11
|
+
const offAppShow = ENV_OBJ.offAppShow || envError('offAppShow')
|
|
12
|
+
|
|
13
|
+
const onAppHide = ENV_OBJ.onAppHide || envError('onAppHide')
|
|
14
|
+
|
|
15
|
+
const offAppHide = ENV_OBJ.offAppHide || envError('offAppHide')
|
|
16
|
+
|
|
17
|
+
export {
|
|
18
|
+
onAppShow,
|
|
19
|
+
onAppHide,
|
|
20
|
+
offAppShow,
|
|
21
|
+
offAppHide,
|
|
22
|
+
onError,
|
|
23
|
+
offError
|
|
24
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { getEnvObj, envError } from '../../../common/js'
|
|
2
|
+
|
|
3
|
+
const ENV_OBJ = getEnvObj()
|
|
4
|
+
|
|
5
|
+
const base64ToArrayBuffer = ENV_OBJ.base64ToArrayBuffer || envError('base64ToArrayBuffer')
|
|
6
|
+
|
|
7
|
+
const arrayBufferToBase64 = ENV_OBJ.arrayBufferToBase64 || envError('arrayBufferToBase64')
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
base64ToArrayBuffer,
|
|
11
|
+
arrayBufferToBase64
|
|
12
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
function closeBLEConnection (options = {}) {
|
|
2
|
+
my.disconnectBLEDevice(options)
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
function createBLEConnection (options = {}) {
|
|
6
|
+
my.connectBLEDevice(options)
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function onBLEConnectionStateChange (callback) {
|
|
10
|
+
my.onBLEConnectionStateChanged(callback)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
closeBLEConnection,
|
|
15
|
+
createBLEConnection,
|
|
16
|
+
onBLEConnectionStateChange
|
|
17
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { getEnvObj, envError } from '../../../common/js'
|
|
2
|
+
|
|
3
|
+
const ENV_OBJ = getEnvObj()
|
|
4
|
+
|
|
5
|
+
const closeBLEConnection = ENV_OBJ.closeBLEConnection || envError('closeBLEConnection')
|
|
6
|
+
|
|
7
|
+
const createBLEConnection = ENV_OBJ.createBLEConnection || envError('createBLEConnection')
|
|
8
|
+
|
|
9
|
+
const onBLEConnectionStateChange = ENV_OBJ.onBLEConnectionStateChange || envError('onBLEConnectionStateChange')
|
|
10
|
+
|
|
11
|
+
export {
|
|
12
|
+
closeBLEConnection,
|
|
13
|
+
createBLEConnection,
|
|
14
|
+
onBLEConnectionStateChange
|
|
15
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { changeOpts, handleSuccess } from '../../../common/js'
|
|
2
|
+
|
|
3
|
+
function canvasToTempFilePath (options = {}) {
|
|
4
|
+
handleSuccess(options, res => {
|
|
5
|
+
return changeOpts(
|
|
6
|
+
res,
|
|
7
|
+
{ errMsg: 'canvasToTempFilePath:ok' }
|
|
8
|
+
)
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
my.canvasToTempFilePath(options)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export {
|
|
15
|
+
canvasToTempFilePath
|
|
16
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { getEnvObj, envError } from '../../../common/js'
|
|
2
|
+
|
|
3
|
+
const ENV_OBJ = getEnvObj()
|
|
4
|
+
|
|
5
|
+
const createCanvasContext = ENV_OBJ.createCanvasContext || envError('createCanvasContext')
|
|
6
|
+
|
|
7
|
+
const canvasToTempFilePath = ENV_OBJ.canvasToTempFilePath || envError('canvasToTempFilePath')
|
|
8
|
+
|
|
9
|
+
const canvasGetImageData = ENV_OBJ.canvasGetImageData || envError('canvasGetImageData')
|
|
10
|
+
|
|
11
|
+
export {
|
|
12
|
+
createCanvasContext,
|
|
13
|
+
canvasToTempFilePath,
|
|
14
|
+
canvasGetImageData
|
|
15
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { changeOpts, handleSuccess } from '../../../common/js'
|
|
2
|
+
|
|
3
|
+
function setClipboardData (options = {}) {
|
|
4
|
+
const opts = changeOpts(options, {
|
|
5
|
+
data: 'text'
|
|
6
|
+
})
|
|
7
|
+
handleSuccess(opts, res => {
|
|
8
|
+
return changeOpts(res, {
|
|
9
|
+
success: ''
|
|
10
|
+
}, {
|
|
11
|
+
errMsg: 'setClipboardData:ok'
|
|
12
|
+
})
|
|
13
|
+
})
|
|
14
|
+
my.setClipboard(opts)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function getClipboardData (options = {}) {
|
|
18
|
+
const opts = changeOpts(options)
|
|
19
|
+
|
|
20
|
+
handleSuccess(opts, res => {
|
|
21
|
+
return changeOpts(res, { text: 'data' })
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
my.getClipboard(opts)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export {
|
|
28
|
+
setClipboardData,
|
|
29
|
+
getClipboardData
|
|
30
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { getEnvObj, envError } from '../../../common/js'
|
|
2
|
+
|
|
3
|
+
const ENV_OBJ = getEnvObj()
|
|
4
|
+
|
|
5
|
+
const setClipboardData = ENV_OBJ.setClipboardData || envError('setClipboardData')
|
|
6
|
+
|
|
7
|
+
const getClipboardData = ENV_OBJ.getClipboardData || envError('getClipboardData')
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
setClipboardData,
|
|
11
|
+
getClipboardData
|
|
12
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { noop } from '../../../common/js'
|
|
2
|
+
|
|
3
|
+
function createSelectorQuery (options = {}) {
|
|
4
|
+
const selectorQuery = my.createSelectorQuery(options)
|
|
5
|
+
const proxyMethods = ['boundingClientRect', 'scrollOffset']
|
|
6
|
+
const cbs = []
|
|
7
|
+
proxyMethods.forEach((name) => {
|
|
8
|
+
const originalMethod = selectorQuery[name]
|
|
9
|
+
selectorQuery[name] = function (cb = noop) {
|
|
10
|
+
cbs.push(cb)
|
|
11
|
+
return originalMethod.call(this)
|
|
12
|
+
}
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
const originalExec = selectorQuery.exec
|
|
16
|
+
selectorQuery.exec = function (originalCb = noop) {
|
|
17
|
+
const cb = function (results) {
|
|
18
|
+
results.forEach((item, index) => {
|
|
19
|
+
cbs[index] && cbs[index](item)
|
|
20
|
+
})
|
|
21
|
+
originalCb(results)
|
|
22
|
+
}
|
|
23
|
+
return originalExec.call(this, cb)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
selectorQuery.in = function () {
|
|
27
|
+
return this
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return selectorQuery
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export {
|
|
34
|
+
createSelectorQuery
|
|
35
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { getEnvObj, envError } from '../../../../common/js'
|
|
2
|
+
|
|
3
|
+
const ENV_OBJ = getEnvObj()
|
|
4
|
+
|
|
5
|
+
const getNetworkType = ENV_OBJ.getNetworkType || envError('getNetworkType')
|
|
6
|
+
|
|
7
|
+
const onNetworkStatusChange = ENV_OBJ.onNetworkStatusChange || envError('onNetworkStatusChange')
|
|
8
|
+
|
|
9
|
+
const offNetworkStatusChange = ENV_OBJ.offNetworkStatusChange || envError('offNetworkStatusChange')
|
|
10
|
+
|
|
11
|
+
export {
|
|
12
|
+
getNetworkType,
|
|
13
|
+
onNetworkStatusChange,
|
|
14
|
+
offNetworkStatusChange
|
|
15
|
+
}
|