@mpxjs/api-proxy 2.9.6 → 2.9.9

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/api-proxy",
3
- "version": "2.9.6",
3
+ "version": "2.9.9",
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": "9034343edacc95da66b6e8ddb5c2f64a4be97231"
42
+ "gitHead": "7ec6526f024c00f9c6b935c631bfdc61be27b69b"
43
43
  }
@@ -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
- let startTime = 0; let x = 0; let y = 0
37
- const touchStart = (e) => {
38
- startTime = Date.now()
39
- x = e.touches[0].pageX
40
- y = e.touches[0].pageY
41
- }
42
- const touchEnd = (e) => {
43
- if (Date.now() - startTime < 300 && Math.abs(e.changedTouches[0].pageX - x) < 10 && Math.abs(e.changedTouches[0].pageY - y) < 10) {
44
- handler(e)
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