@mpxjs/api-proxy 2.8.39 → 2.8.40-test.1

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.
Files changed (111) hide show
  1. package/package.json +2 -2
  2. package/src/common/js/index.js +0 -1
  3. package/src/{mini → common/js}/promisify.js +4 -2
  4. package/src/common/js/utils.js +32 -1
  5. package/src/common/js/web.js +16 -0
  6. package/src/common/stylus/Preview.styl +29 -0
  7. package/src/index.js +4 -75
  8. package/src/install.js +62 -0
  9. package/src/{web → platform}/api/action-sheet/ActionSheet.js +2 -7
  10. package/src/platform/api/action-sheet/index.ali.js +28 -0
  11. package/src/platform/api/action-sheet/index.js +9 -0
  12. package/src/platform/api/add-phone-contact/index.ali.js +13 -0
  13. package/src/platform/api/add-phone-contact/index.js +9 -0
  14. package/src/platform/api/animation/index.js +9 -0
  15. package/src/platform/api/app/index.js +24 -0
  16. package/src/platform/api/audio/index.js +9 -0
  17. package/src/platform/api/base/index.js +12 -0
  18. package/src/platform/api/ble-connection/index.ali.js +17 -0
  19. package/src/platform/api/ble-connection/index.js +15 -0
  20. package/src/platform/api/canvas/index.ali.js +16 -0
  21. package/src/platform/api/canvas/index.js +15 -0
  22. package/src/platform/api/check-session/index.js +9 -0
  23. package/src/platform/api/clipboard-data/index.ali.js +30 -0
  24. package/src/platform/api/clipboard-data/index.js +12 -0
  25. package/src/{web → platform}/api/create-intersection-observer/IntersectionObserver.js +2 -10
  26. package/src/platform/api/create-intersection-observer/index.ali.js +7 -0
  27. package/src/platform/api/create-intersection-observer/index.js +9 -0
  28. package/src/{web → platform}/api/create-selector-query/SelectQuery.js +11 -3
  29. package/src/platform/api/create-selector-query/index.ali.js +35 -0
  30. package/src/platform/api/create-selector-query/index.js +9 -0
  31. package/src/platform/api/device/network/index.js +15 -0
  32. package/src/{web/api/event-channel/index.js → platform/api/event-channel/index.web.js} +13 -14
  33. package/src/platform/api/file/index.ali.js +35 -0
  34. package/src/platform/api/file/index.js +12 -0
  35. package/src/platform/api/get-user-info/index.ali.js +18 -0
  36. package/src/platform/api/get-user-info/index.js +9 -0
  37. package/src/platform/api/image/Preview.js +80 -0
  38. package/src/platform/api/image/index.ali.js +36 -0
  39. package/src/platform/api/image/index.js +12 -0
  40. package/src/platform/api/image/index.web.js +12 -0
  41. package/src/platform/api/login/index.ali.js +15 -0
  42. package/src/platform/api/login/index.js +9 -0
  43. package/src/platform/api/make-phone-call/index.ali.js +12 -0
  44. package/src/platform/api/make-phone-call/index.js +9 -0
  45. package/src/{web → platform}/api/modal/Modal.js +2 -7
  46. package/src/platform/api/modal/index.ali.js +32 -0
  47. package/src/platform/api/modal/index.js +9 -0
  48. package/src/platform/api/next-tick/index.ali.js +7 -0
  49. package/src/platform/api/next-tick/index.js +9 -0
  50. package/src/platform/api/next-tick/index.tt.js +7 -0
  51. package/src/platform/api/page-scroll-to/index.js +9 -0
  52. package/src/platform/api/pull-down/index.js +12 -0
  53. package/src/{web/api/pull-down/index.js → platform/api/pull-down/index.web.js} +14 -22
  54. package/src/platform/api/request/index.ali.js +26 -0
  55. package/src/platform/api/request/index.js +9 -0
  56. package/src/{web/api/request/index.js → platform/api/request/index.web.js} +14 -7
  57. package/src/platform/api/request-payment/index.ali.js +45 -0
  58. package/src/platform/api/request-payment/index.js +9 -0
  59. package/src/platform/api/route/index.js +21 -0
  60. package/src/{web/api/route/index.js → platform/api/route/index.web.js} +71 -78
  61. package/src/platform/api/scan-code/index.ali.js +17 -0
  62. package/src/platform/api/scan-code/index.js +9 -0
  63. package/src/platform/api/screen-brightness/index.ali.js +26 -0
  64. package/src/platform/api/screen-brightness/index.js +12 -0
  65. package/src/platform/api/set-navigation-bar/index.ali.js +25 -0
  66. package/src/platform/api/set-navigation-bar/index.js +12 -0
  67. package/src/{web/api/set-navigation-bar/index.js → platform/api/set-navigation-bar/index.web.js} +0 -1
  68. package/src/{web → platform}/api/socket/SocketTask.js +1 -1
  69. package/src/platform/api/socket/index.js +9 -0
  70. package/src/platform/api/storage/index.ali.js +59 -0
  71. package/src/platform/api/storage/index.js +36 -0
  72. package/src/{web/api/storage/index.js → platform/api/storage/index.web.js} +0 -10
  73. package/src/platform/api/system/index.ali.js +38 -0
  74. package/src/platform/api/system/index.js +12 -0
  75. package/src/{web/api/system/index.js → platform/api/system/index.web.js} +0 -1
  76. package/src/platform/api/tab-bar/index.js +18 -0
  77. package/src/{web/api/tab-bar/index.js → platform/api/tab-bar/index.web.js} +0 -8
  78. package/src/{web → platform}/api/toast/Toast.js +1 -10
  79. package/src/platform/api/toast/index.ali.js +39 -0
  80. package/src/platform/api/toast/index.js +18 -0
  81. package/src/platform/api/video/index.js +9 -0
  82. package/src/platform/api/window/index.js +12 -0
  83. package/src/platform/index.js +106 -0
  84. package/src/web/api/index.js +3 -0
  85. package/src/common/js/ToPromise.js +0 -25
  86. package/src/index.web.js +0 -27
  87. package/src/mini/platform/wxToAli.js +0 -667
  88. package/src/mini/platform/wxToQq.js +0 -20
  89. package/src/mini/platform/wxToTt.js +0 -9
  90. package/src/mini/transform.js +0 -71
  91. /package/src/{web/api/action-sheet/index.js → platform/api/action-sheet/index.web.js} +0 -0
  92. /package/src/{web → platform}/api/animation/animation.js +0 -0
  93. /package/src/{web/api/animation/index.js → platform/api/animation/index.web.js} +0 -0
  94. /package/src/{web/api/app/index.js → platform/api/app/index.web.js} +0 -0
  95. /package/src/{web/api/audio/index.js → platform/api/audio/index.web.js} +0 -0
  96. /package/src/{web → platform}/api/base/base64.js +0 -0
  97. /package/src/{web/api/base/index.js → platform/api/base/index.web.js} +0 -0
  98. /package/src/{web/api/create-intersection-observer/index.js → platform/api/create-intersection-observer/index.web.js} +0 -0
  99. /package/src/{web → platform}/api/create-selector-query/NodesRef.js +0 -0
  100. /package/src/{web/api/create-selector-query/index.js → platform/api/create-selector-query/index.web.js} +0 -0
  101. /package/src/{web → platform}/api/device/network/getNetworkType.js +0 -0
  102. /package/src/{web/api/device/network/index.js → platform/api/device/network/index.web.js} +0 -0
  103. /package/src/{web → platform}/api/device/network/onNetworkStatusChange.js +0 -0
  104. /package/src/{web/api/modal/index.js → platform/api/modal/index.web.js} +0 -0
  105. /package/src/{web/api/next-tick/index.js → platform/api/next-tick/index.web.js} +0 -0
  106. /package/src/{web/api/page-scroll-to/index.js → platform/api/page-scroll-to/index.web.js} +0 -0
  107. /package/src/{web → platform}/api/request/RequestTask.js +0 -0
  108. /package/src/{web/api/socket/index.js → platform/api/socket/index.web.js} +0 -0
  109. /package/src/{web/api/toast/index.js → platform/api/toast/index.web.js} +0 -0
  110. /package/src/{web/api/video/index.js → platform/api/video/index.web.js} +0 -0
  111. /package/src/{web/api/window/index.js → platform/api/window/index.web.js} +0 -0
@@ -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,9 @@
1
+ import { getEnvObj, envError } from '../../../common/js'
2
+
3
+ const ENV_OBJ = getEnvObj()
4
+
5
+ const createSelectorQuery = ENV_OBJ.createSelectorQuery || envError('createSelectorQuery')
6
+
7
+ export {
8
+ createSelectorQuery
9
+ }
@@ -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
+ }
@@ -19,13 +19,13 @@ class EventChannel {
19
19
  }
20
20
  }
21
21
 
22
- off (eventName, EventCallback) {
23
- if (EventCallback) {
22
+ off (eventName, listener) {
23
+ if (listener) {
24
24
  const cbs = this.listener[eventName]
25
25
  const copyCbs = []
26
26
  if (cbs) {
27
27
  cbs.forEach((item) => {
28
- if (item.fn !== EventCallback) {
28
+ if (item.fn !== listener) {
29
29
  copyCbs.push(item)
30
30
  }
31
31
  })
@@ -36,26 +36,25 @@ class EventChannel {
36
36
  }
37
37
  }
38
38
 
39
- on (eventName, EventCallback) {
40
- (this.listener[eventName] || (this.listener[eventName] = [])).push({ fn: EventCallback, type: 'on' })
39
+ on (eventName, listener) {
40
+ this._addListener(eventName, listener, 'on')
41
41
  }
42
42
 
43
- once (eventName, EventCallback) {
44
- (this.listener[eventName] || (this.listener[eventName] = [])).push({ fn: EventCallback, type: 'once' })
43
+ once (eventName, listener) {
44
+ this._addListener(eventName, listener, 'once')
45
45
  }
46
46
 
47
- _addListener (eventName, EventCallback, type) {
48
- (this.listener[eventName] || (this.listener[eventName] = [])).push({ fn: EventCallback, type })
47
+ _addListener (eventName, listener, type) {
48
+ (this.listener[eventName] || (this.listener[eventName] = [])).push({ fn: listener, type })
49
49
  }
50
50
 
51
51
  _addListeners (events) {
52
- if (Object.prototype.toString.call(events) === '[object Object]') {
53
- Object.keys(events).forEach((eventName) => {
54
- (this.listener[eventName] || (this.listener[eventName] = [])).push({ fn: events[eventName], type: 'on' })
55
- })
56
- }
52
+ Object.keys(events).forEach((eventName) => {
53
+ this.on(eventName, events[eventName])
54
+ })
57
55
  }
58
56
  }
57
+
59
58
  export {
60
59
  EventChannel
61
60
  }
@@ -0,0 +1,35 @@
1
+ import { changeOpts, handleSuccess } from '../../../common/js'
2
+
3
+ function downloadFile (options = {}) {
4
+ const opts = changeOpts(options)
5
+
6
+ handleSuccess(opts, res => {
7
+ return changeOpts(res, { apFilePath: 'tempFilePath' })
8
+ })
9
+
10
+ return my.downloadFile(opts)
11
+ }
12
+
13
+ function uploadFile (options = {}) {
14
+ const opts = changeOpts(options, { name: 'fileName' })
15
+
16
+ return my.uploadFile(opts)
17
+ }
18
+
19
+ function saveFile (options = {}) {
20
+ const opts = changeOpts(options, {
21
+ tempFilePath: 'apFilePath'
22
+ })
23
+
24
+ handleSuccess(opts, res => {
25
+ return changeOpts(res, { apFilePath: 'savedFilePath' })
26
+ })
27
+
28
+ my.saveFile(opts)
29
+ }
30
+
31
+ export {
32
+ downloadFile,
33
+ uploadFile,
34
+ saveFile
35
+ }
@@ -0,0 +1,12 @@
1
+ import { getEnvObj, envError } from '../../../common/js'
2
+
3
+ const ENV_OBJ = getEnvObj()
4
+
5
+ const downloadFile = ENV_OBJ.downloadFile || envError('downloadFile')
6
+
7
+ const uploadFile = ENV_OBJ.uploadFile || envError('uploadFile')
8
+
9
+ export {
10
+ downloadFile,
11
+ uploadFile
12
+ }
@@ -0,0 +1,18 @@
1
+ import { warn } from '../../../common/js'
2
+
3
+ const TIPS_NAME = '支付宝环境 mpx'
4
+
5
+ function getUserInfo (options = {}) {
6
+ if (options.withCredentials === true) {
7
+ warn(`支付宝不支持在 ${TIPS_NAME}.getUserInfo 使用 withCredentials 参数中获取等敏感信息`)
8
+ }
9
+ if (options.lang) {
10
+ warn(`支付宝不支持在 ${TIPS_NAME}.getUserInfo 中使用 lang 参数`)
11
+ }
12
+
13
+ my.getOpenUserInfo(options)
14
+ }
15
+
16
+ export {
17
+ getUserInfo
18
+ }
@@ -0,0 +1,9 @@
1
+ import { getEnvObj, envError } from '../../../common/js'
2
+
3
+ const ENV_OBJ = getEnvObj()
4
+
5
+ const getUserInfo = ENV_OBJ.getUserInfo || envError('getUserInfo')
6
+
7
+ export {
8
+ getUserInfo
9
+ }
@@ -0,0 +1,80 @@
1
+ import { webHandleSuccess, webHandleFail, createDom, warn } from '../../../common/js'
2
+ import '../../../common/stylus/Preview.styl'
3
+ /**
4
+ * Preview class for displaying images in a slideshow format.
5
+ * todo: unit test
6
+ */
7
+ export default class Preview {
8
+ constructor () {
9
+ this.currentIndex = 0
10
+ this.maxIndex = 0
11
+ this.minDistance = 30
12
+ this.preview = createDom('div', { class: '__mpx_preview__' }, [
13
+ this.textTip = createDom('div', { class: '__mpx_preview_tip__' })
14
+ ])
15
+ document.body.appendChild(this.preview)
16
+ this.initEvent()
17
+ }
18
+
19
+ /**
20
+ * Initializes the event listeners for the preview image feature.
21
+ */
22
+ initEvent () {
23
+ // swipe to change image
24
+ let startX = 0
25
+ this.preview.addEventListener('touchstart', (e) => {
26
+ startX = e.touches[0].pageX
27
+ })
28
+ this.preview.addEventListener('touchend', (e) => {
29
+ const endX = e.changedTouches[0].pageX
30
+ const distance = endX - startX
31
+ if (Math.abs(distance) < this.minDistance) {
32
+ return
33
+ }
34
+ if (distance > 0) {
35
+ this.currentIndex = Math.max(0, this.currentIndex - 1)
36
+ }
37
+ if (distance < 0) {
38
+ this.currentIndex = Math.min(this.maxIndex - 1, this.currentIndex + 1)
39
+ }
40
+ this.preview.querySelector('.__mpx_preview_images__').style.transform = `translateX(-${this.currentIndex * 100}%)`
41
+ this.updateTextTip()
42
+ })
43
+ // click to close
44
+ this.preview.addEventListener('click', () => {
45
+ this.preview.style.display = 'none'
46
+ this.preview.querySelector('.__mpx_preview_images__').remove()
47
+ })
48
+ }
49
+
50
+ /**
51
+ * 显示预览图片
52
+ * @param {Object} options - 选项对象
53
+ * @param {string[]} options.urls - 图片地址数组
54
+ */
55
+ show (options) {
56
+ const supported = ['urls', 'success', 'fail', 'complete']
57
+ Object.keys(options).forEach(key => !supported.includes(key) && warn(`previewImage: 暂不支持选项 ${key} !`))
58
+ const { urls, success, fail, complete } = options
59
+ try {
60
+ this.preview.style.display = 'block'
61
+ // create images with urls
62
+ // append to preview
63
+ this.preview.appendChild(createDom('div', { class: '__mpx_preview_images__' }, urls.map(url => createDom('div', {
64
+ style: `background-image: url(${url})`
65
+ }))))
66
+ this.maxIndex = urls.length
67
+ this.updateTextTip()
68
+ webHandleSuccess({ errMsg: 'previewImage:ok' }, success, complete)
69
+ } catch (e) {
70
+ webHandleFail({ errMsg: 'previewImage:fail', err: e }, fail, complete)
71
+ }
72
+ }
73
+
74
+ /**
75
+ * 更新文本提示
76
+ */
77
+ updateTextTip () {
78
+ this.textTip.textContent = `${this.currentIndex + 1}/${this.maxIndex}`
79
+ }
80
+ }
@@ -0,0 +1,36 @@
1
+ import { changeOpts, handleSuccess } from '../../../common/js'
2
+
3
+ function previewImage (options = {}) {
4
+ const opts = changeOpts(options)
5
+
6
+ if (opts.current) {
7
+ const idx = options.urls.indexOf(opts.current)
8
+ opts.current = idx !== -1 ? idx : 0
9
+ }
10
+
11
+ my.previewImage(opts)
12
+ }
13
+
14
+ function compressImage (options = {}) {
15
+ const opts = changeOpts(options, {
16
+ quality: ''
17
+ }, {
18
+ compressLevel: Math.round(options.quality / 100 * 4), // 支付宝图片压缩质量为 0 ~ 4,微信是 0 ~ 100
19
+ apFilePaths: [options.src]
20
+ })
21
+
22
+ handleSuccess(opts, res => {
23
+ return changeOpts(
24
+ res,
25
+ { apFilePaths: '' },
26
+ { tempFilePath: res.apFilePaths[0] }
27
+ )
28
+ })
29
+
30
+ my.compressImage(opts)
31
+ }
32
+
33
+ export {
34
+ previewImage,
35
+ compressImage
36
+ }
@@ -0,0 +1,12 @@
1
+ import { getEnvObj, envError } from '../../../common/js'
2
+
3
+ const ENV_OBJ = getEnvObj()
4
+
5
+ const previewImage = ENV_OBJ.previewImage || envError('previewImage')
6
+
7
+ const compressImage = ENV_OBJ.compressImage || envError('compressImage')
8
+
9
+ export {
10
+ previewImage,
11
+ compressImage
12
+ }
@@ -0,0 +1,12 @@
1
+ import Preview from './Preview'
2
+
3
+ let preview = null
4
+
5
+ /**
6
+ * 预览图片
7
+ * @param {Object} options - 预览图片的配置项
8
+ */
9
+ export const previewImage = (options) => {
10
+ if (!preview) preview = new Preview()
11
+ preview.show(options)
12
+ }
@@ -0,0 +1,15 @@
1
+ import { changeOpts, handleSuccess } from '../../../common/js'
2
+
3
+ function login (options = {}) {
4
+ const opts = changeOpts(options)
5
+
6
+ handleSuccess(opts, res => {
7
+ return changeOpts(res, { authCode: 'code' }, { errMsg: 'login:ok' })
8
+ })
9
+
10
+ my.getAuthCode(opts)
11
+ }
12
+
13
+ export {
14
+ login
15
+ }
@@ -0,0 +1,9 @@
1
+ import { getEnvObj, envError } from '../../../common/js'
2
+
3
+ const ENV_OBJ = getEnvObj()
4
+
5
+ const login = ENV_OBJ.login || envError('login')
6
+
7
+ export {
8
+ login
9
+ }
@@ -0,0 +1,12 @@
1
+ import { changeOpts } from '../../../common/js'
2
+
3
+ function makePhoneCall (options = {}) {
4
+ const opts = changeOpts(options, {
5
+ phoneNumber: 'number'
6
+ })
7
+ my.makePhoneCall(opts)
8
+ }
9
+
10
+ export {
11
+ makePhoneCall
12
+ }
@@ -0,0 +1,9 @@
1
+ import { getEnvObj, envError } from '../../../common/js'
2
+
3
+ const ENV_OBJ = getEnvObj()
4
+
5
+ const makePhoneCall = ENV_OBJ.makePhoneCall || envError('makePhoneCall')
6
+
7
+ export {
8
+ makePhoneCall
9
+ }
@@ -1,4 +1,4 @@
1
- import { ToPromise, webHandleSuccess } from '../../../common/js'
1
+ import { webHandleSuccess } from '../../../common/js'
2
2
  import '../../../common/stylus/Modal.styl'
3
3
  // import { forEach } from '@didi/mpx-fetch/src/util'
4
4
  // 汉字为两个字符,字母/数字为一个字符
@@ -13,9 +13,8 @@ const _getLength = (t) => {
13
13
  }
14
14
  return len
15
15
  }
16
- export default class Modal extends ToPromise {
16
+ export default class Modal {
17
17
  constructor () {
18
- super()
19
18
  this.defaultOpts = {
20
19
  title: '',
21
20
  content: '',
@@ -110,7 +109,6 @@ export default class Modal extends ToPromise {
110
109
  confirm: false
111
110
  }
112
111
  webHandleSuccess(result, opts.success, opts.complete)
113
- this.toPromiseResolve(result)
114
112
  }
115
113
  this.confirmBtn.onclick = () => {
116
114
  this.hide()
@@ -120,12 +118,9 @@ export default class Modal extends ToPromise {
120
118
  confirm: true
121
119
  }
122
120
  webHandleSuccess(result, opts.success, opts.complete)
123
- this.toPromiseResolve(result)
124
121
  }
125
122
 
126
123
  this.modal.classList.add('show')
127
-
128
- return this.toPromiseInitPromise()
129
124
  }
130
125
 
131
126
  hide () {
@@ -0,0 +1,32 @@
1
+ import { changeOpts, handleSuccess } from '../../../common/js'
2
+
3
+ function showModal (options = {}) {
4
+ let opts
5
+
6
+ if (options.showCancel === undefined || options.showCancel) {
7
+ opts = changeOpts(options, {
8
+ confirmText: 'confirmButtonText',
9
+ cancelText: 'cancelButtonText'
10
+ })
11
+
12
+ handleSuccess(opts, res => {
13
+ return changeOpts(res, undefined, { cancel: !res.confirm })
14
+ })
15
+
16
+ my.confirm(opts)
17
+ } else {
18
+ opts = changeOpts(options, {
19
+ confirmText: 'buttonText'
20
+ })
21
+
22
+ handleSuccess(opts, res => {
23
+ return changeOpts(res, undefined, { cancel: false, confirm: true })
24
+ })
25
+
26
+ my.alert(opts)
27
+ }
28
+ }
29
+
30
+ export {
31
+ showModal
32
+ }
@@ -0,0 +1,9 @@
1
+ import { getEnvObj, envError } from '../../../common/js'
2
+
3
+ const ENV_OBJ = getEnvObj()
4
+
5
+ const showModal = ENV_OBJ.showModal || envError('showModal')
6
+
7
+ export {
8
+ showModal
9
+ }
@@ -0,0 +1,7 @@
1
+ function nextTick (fn) {
2
+ Promise.resolve().then(fn)
3
+ }
4
+
5
+ export {
6
+ nextTick
7
+ }
@@ -0,0 +1,9 @@
1
+ import { getEnvObj, envError } from '../../../common/js'
2
+
3
+ const ENV_OBJ = getEnvObj()
4
+
5
+ const nextTick = ENV_OBJ.nextTick || envError('nextTick')
6
+
7
+ export {
8
+ nextTick
9
+ }
@@ -0,0 +1,7 @@
1
+ function nextTick (fn) {
2
+ Promise.resolve().then(fn)
3
+ }
4
+
5
+ export {
6
+ nextTick
7
+ }
@@ -0,0 +1,9 @@
1
+ import { getEnvObj, envError } from '../../../common/js'
2
+
3
+ const ENV_OBJ = getEnvObj()
4
+
5
+ const pageScrollTo = ENV_OBJ.pageScrollTo || envError('pageScrollTo')
6
+
7
+ export {
8
+ pageScrollTo
9
+ }
@@ -0,0 +1,12 @@
1
+ import { getEnvObj, envError } from '../../../common/js'
2
+
3
+ const ENV_OBJ = getEnvObj()
4
+
5
+ const stopPullDownRefresh = ENV_OBJ.stopPullDownRefresh || envError('stopPullDownRefresh')
6
+
7
+ const startPullDownRefresh = ENV_OBJ.startPullDownRefresh || envError('startPullDownRefresh')
8
+
9
+ export {
10
+ stopPullDownRefresh,
11
+ startPullDownRefresh
12
+ }
@@ -16,17 +16,13 @@ function stopPullDownRefresh (options = {}) {
16
16
  }
17
17
  }
18
18
  }
19
- return new Promise((resolve, reject) => {
20
- if (err) {
21
- const res = { errMsg: `stopPullDownRefresh:fail ${err}` }
22
- webHandleFail(res, options.fail, options.complete)
23
- reject(res)
24
- } else {
25
- const res = { errMsg: 'stopPullDownRefresh:ok' }
26
- webHandleSuccess(res, options.success, options.complete)
27
- resolve(res)
28
- }
29
- })
19
+ if (err) {
20
+ const res = { errMsg: `stopPullDownRefresh:fail ${err}` }
21
+ webHandleFail(res, options.fail, options.complete)
22
+ } else {
23
+ const res = { errMsg: 'stopPullDownRefresh:ok' }
24
+ webHandleSuccess(res, options.success, options.complete)
25
+ }
30
26
  }
31
27
  }
32
28
 
@@ -46,17 +42,13 @@ function startPullDownRefresh (options = {}) {
46
42
  }
47
43
  }
48
44
  }
49
- return new Promise((resolve, reject) => {
50
- if (err) {
51
- const res = { errMsg: `startPullDownRefresh:fail ${err}` }
52
- webHandleFail(res, options.fail, options.complete)
53
- reject(res)
54
- } else {
55
- const res = { errMsg: 'startPullDownRefresh:ok' }
56
- webHandleSuccess(res, options.success, options.complete)
57
- resolve(res)
58
- }
59
- })
45
+ if (err) {
46
+ const res = { errMsg: `startPullDownRefresh:fail ${err}` }
47
+ webHandleFail(res, options.fail, options.complete)
48
+ } else {
49
+ const res = { errMsg: 'startPullDownRefresh:ok' }
50
+ webHandleSuccess(res, options.success, options.complete)
51
+ }
60
52
  }
61
53
  }
62
54
 
@@ -0,0 +1,26 @@
1
+ import { changeOpts, handleSuccess } from '../../../common/js'
2
+
3
+ function request (options = {}) {
4
+ const opts = changeOpts(options, {
5
+ header: 'headers'
6
+ })
7
+
8
+ handleSuccess(opts, res => {
9
+ return changeOpts(res, {
10
+ headers: 'header',
11
+ status: 'statusCode'
12
+ })
13
+ })
14
+
15
+ // request 在 1.11.0 以上版本才支持
16
+ // httpRequest 即将被废弃,钉钉端仍需要使用
17
+ if (my.canIUse('request')) {
18
+ return my.request(opts)
19
+ } else {
20
+ return my.httpRequest(opts)
21
+ }
22
+ }
23
+
24
+ export {
25
+ request
26
+ }
@@ -0,0 +1,9 @@
1
+ import { getEnvObj, envError } from '../../../common/js'
2
+
3
+ const ENV_OBJ = getEnvObj()
4
+
5
+ const request = ENV_OBJ.request || envError('request')
6
+
7
+ export {
8
+ request
9
+ }
@@ -39,17 +39,25 @@ function request (options = { url: '' }) {
39
39
  headers: header,
40
40
  responseType,
41
41
  timeout,
42
- cancelToken: source.token
42
+ cancelToken: source.token,
43
+ transitional: {
44
+ // silent JSON parsing mode
45
+ // `true` - ignore JSON parsing errors and set response.data to null if parsing failed (old behaviour)
46
+ // `false` - throw SyntaxError if JSON parsing failed (Note: responseType must be set to 'json')
47
+ silentJSONParsing: true, // default value for the current Axios version
48
+ // try to parse the response string as JSON even if `responseType` is not 'json'
49
+ forcedJSONParsing: false,
50
+ // throw ETIMEDOUT error instead of generic ECONNABORTED on request timeouts
51
+ clarifyTimeoutError: false
52
+ }
43
53
  }
44
-
45
54
  if (method === 'GET') {
46
55
  rOptions.params = rOptions.data || {}
47
56
  delete rOptions.data
48
57
  }
49
-
50
- const promise = axios(rOptions).then(res => {
58
+ axios(rOptions).then(res => {
51
59
  let data = res.data
52
- if (responseType === 'text' && dataType === 'json') {
60
+ if (dataType === 'json' && typeof data === 'string') {
53
61
  try {
54
62
  data = JSON.parse(data)
55
63
  } catch (e) {
@@ -71,8 +79,7 @@ function request (options = { url: '' }) {
71
79
  }
72
80
  })
73
81
 
74
- promise.__returned = requestTask
75
- return promise
82
+ return requestTask
76
83
  }
77
84
 
78
85
  export {