@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.
Files changed (110) 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 +25 -15
  6. package/src/index.js +4 -75
  7. package/src/install.js +62 -0
  8. package/src/{web → platform}/api/action-sheet/ActionSheet.js +6 -6
  9. package/src/platform/api/action-sheet/index.ali.js +28 -0
  10. package/src/platform/api/action-sheet/index.js +9 -0
  11. package/src/platform/api/add-phone-contact/index.ali.js +13 -0
  12. package/src/platform/api/add-phone-contact/index.js +9 -0
  13. package/src/platform/api/animation/index.js +9 -0
  14. package/src/platform/api/app/index.js +24 -0
  15. package/src/platform/api/audio/index.js +9 -0
  16. package/src/platform/api/base/index.js +12 -0
  17. package/src/platform/api/ble-connection/index.ali.js +17 -0
  18. package/src/platform/api/ble-connection/index.js +15 -0
  19. package/src/platform/api/canvas/index.ali.js +16 -0
  20. package/src/platform/api/canvas/index.js +15 -0
  21. package/src/platform/api/check-session/index.js +9 -0
  22. package/src/platform/api/clipboard-data/index.ali.js +30 -0
  23. package/src/platform/api/clipboard-data/index.js +12 -0
  24. package/src/platform/api/create-intersection-observer/index.ali.js +7 -0
  25. package/src/platform/api/create-intersection-observer/index.js +9 -0
  26. package/src/platform/api/create-selector-query/index.ali.js +35 -0
  27. package/src/platform/api/create-selector-query/index.js +9 -0
  28. package/src/platform/api/device/network/index.js +15 -0
  29. package/src/platform/api/file/index.ali.js +35 -0
  30. package/src/platform/api/file/index.js +12 -0
  31. package/src/platform/api/get-user-info/index.ali.js +18 -0
  32. package/src/platform/api/get-user-info/index.js +9 -0
  33. package/src/platform/api/image/index.ali.js +36 -0
  34. package/src/platform/api/image/index.js +12 -0
  35. package/src/platform/api/login/index.ali.js +15 -0
  36. package/src/platform/api/login/index.js +9 -0
  37. package/src/platform/api/make-phone-call/index.ali.js +12 -0
  38. package/src/platform/api/make-phone-call/index.js +9 -0
  39. package/src/{web → platform}/api/modal/Modal.js +2 -7
  40. package/src/platform/api/modal/index.ali.js +32 -0
  41. package/src/platform/api/modal/index.js +9 -0
  42. package/src/platform/api/next-tick/index.ali.js +7 -0
  43. package/src/platform/api/next-tick/index.js +9 -0
  44. package/src/platform/api/next-tick/index.tt.js +7 -0
  45. package/src/platform/api/page-scroll-to/index.js +9 -0
  46. package/src/platform/api/pull-down/index.js +12 -0
  47. package/src/{web/api/pull-down/index.js → platform/api/pull-down/index.web.js} +14 -22
  48. package/src/platform/api/request/index.ali.js +26 -0
  49. package/src/platform/api/request/index.js +9 -0
  50. package/src/{web/api/request/index.js → platform/api/request/index.web.js} +2 -5
  51. package/src/platform/api/request-payment/index.ali.js +45 -0
  52. package/src/platform/api/request-payment/index.js +9 -0
  53. package/src/platform/api/route/index.js +21 -0
  54. package/src/{web/api/route/index.js → platform/api/route/index.web.js} +59 -80
  55. package/src/platform/api/scan-code/index.ali.js +17 -0
  56. package/src/platform/api/scan-code/index.js +9 -0
  57. package/src/platform/api/screen-brightness/index.ali.js +26 -0
  58. package/src/platform/api/screen-brightness/index.js +12 -0
  59. package/src/platform/api/set-navigation-bar/index.ali.js +25 -0
  60. package/src/platform/api/set-navigation-bar/index.js +12 -0
  61. package/src/{web/api/set-navigation-bar/index.js → platform/api/set-navigation-bar/index.web.js} +0 -1
  62. package/src/{web → platform}/api/socket/SocketTask.js +1 -1
  63. package/src/platform/api/socket/index.js +9 -0
  64. package/src/platform/api/storage/index.ali.js +59 -0
  65. package/src/platform/api/storage/index.js +36 -0
  66. package/src/{web/api/storage/index.js → platform/api/storage/index.web.js} +0 -10
  67. package/src/platform/api/system/index.ali.js +38 -0
  68. package/src/platform/api/system/index.js +12 -0
  69. package/src/{web/api/system/index.js → platform/api/system/index.web.js} +0 -1
  70. package/src/platform/api/tab-bar/index.js +18 -0
  71. package/src/{web/api/tab-bar/index.js → platform/api/tab-bar/index.web.js} +0 -8
  72. package/src/{web → platform}/api/toast/Toast.js +1 -3
  73. package/src/platform/api/toast/index.ali.js +39 -0
  74. package/src/platform/api/toast/index.js +18 -0
  75. package/src/platform/api/video/index.js +9 -0
  76. package/src/platform/api/window/index.js +12 -0
  77. package/src/platform/index.js +106 -0
  78. package/src/common/js/ToPromise.js +0 -25
  79. package/src/index.web.js +0 -24
  80. package/src/mini/platform/wxToAli.js +0 -667
  81. package/src/mini/platform/wxToQq.js +0 -20
  82. package/src/mini/platform/wxToTt.js +0 -9
  83. package/src/mini/transform.js +0 -71
  84. package/src/web/api/index.js +0 -68
  85. /package/src/{web/api/action-sheet/index.js → platform/api/action-sheet/index.web.js} +0 -0
  86. /package/src/{web → platform}/api/animation/animation.js +0 -0
  87. /package/src/{web/api/animation/index.js → platform/api/animation/index.web.js} +0 -0
  88. /package/src/{web/api/app/index.js → platform/api/app/index.web.js} +0 -0
  89. /package/src/{web/api/audio/index.js → platform/api/audio/index.web.js} +0 -0
  90. /package/src/{web → platform}/api/base/base64.js +0 -0
  91. /package/src/{web/api/base/index.js → platform/api/base/index.web.js} +0 -0
  92. /package/src/{web → platform}/api/create-intersection-observer/IntersectionObserver.js +0 -0
  93. /package/src/{web/api/create-intersection-observer/index.js → platform/api/create-intersection-observer/index.web.js} +0 -0
  94. /package/src/{web → platform}/api/create-selector-query/NodesRef.js +0 -0
  95. /package/src/{web → platform}/api/create-selector-query/SelectQuery.js +0 -0
  96. /package/src/{web/api/create-selector-query/index.js → platform/api/create-selector-query/index.web.js} +0 -0
  97. /package/src/{web → platform}/api/device/network/getNetworkType.js +0 -0
  98. /package/src/{web/api/device/network/index.js → platform/api/device/network/index.web.js} +0 -0
  99. /package/src/{web → platform}/api/device/network/onNetworkStatusChange.js +0 -0
  100. /package/src/{web/api/event-channel/index.js → platform/api/event-channel/index.web.js} +0 -0
  101. /package/src/{web/api/preview-image → platform/api/image}/Preview.js +0 -0
  102. /package/src/{web/api/preview-image/index.js → platform/api/image/index.web.js} +0 -0
  103. /package/src/{web/api/modal/index.js → platform/api/modal/index.web.js} +0 -0
  104. /package/src/{web/api/next-tick/index.js → platform/api/next-tick/index.web.js} +0 -0
  105. /package/src/{web/api/page-scroll-to/index.js → platform/api/page-scroll-to/index.web.js} +0 -0
  106. /package/src/{web → platform}/api/request/RequestTask.js +0 -0
  107. /package/src/{web/api/socket/index.js → platform/api/socket/index.web.js} +0 -0
  108. /package/src/{web/api/toast/index.js → platform/api/toast/index.web.js} +0 -0
  109. /package/src/{web/api/video/index.js → platform/api/video/index.web.js} +0 -0
  110. /package/src/{web/api/window/index.js → platform/api/window/index.web.js} +0 -0
@@ -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,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,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, createDom, getRootElement, webHandleSuccess } from '../../../common/js'
1
+ import { createDom, getRootElement, 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: '',
@@ -82,7 +81,6 @@ export default class Modal extends ToPromise {
82
81
  confirm: false
83
82
  }
84
83
  webHandleSuccess(result, opts.success, opts.complete)
85
- this.toPromiseResolve(result)
86
84
  }
87
85
  this.confirmBtn.onclick = () => {
88
86
  this.hide()
@@ -92,12 +90,9 @@ export default class Modal extends ToPromise {
92
90
  confirm: true
93
91
  }
94
92
  webHandleSuccess(result, opts.success, opts.complete)
95
- this.toPromiseResolve(result)
96
93
  }
97
94
 
98
95
  this.modal.classList.add('show')
99
-
100
- return this.toPromiseInitPromise()
101
96
  }
102
97
 
103
98
  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
+ }
@@ -20,17 +20,13 @@ function stopPullDownRefresh (options = {}) {
20
20
  }
21
21
  }
22
22
  }
23
- return new Promise((resolve, reject) => {
24
- if (err) {
25
- const res = { errMsg: `stopPullDownRefresh:fail ${err}` }
26
- webHandleFail(res, options.fail, options.complete)
27
- reject(res)
28
- } else {
29
- const res = { errMsg: 'stopPullDownRefresh:ok' }
30
- webHandleSuccess(res, options.success, options.complete)
31
- resolve(res)
32
- }
33
- })
23
+ if (err) {
24
+ const res = { errMsg: `stopPullDownRefresh:fail ${err}` }
25
+ webHandleFail(res, options.fail, options.complete)
26
+ } else {
27
+ const res = { errMsg: 'stopPullDownRefresh:ok' }
28
+ webHandleSuccess(res, options.success, options.complete)
29
+ }
34
30
  }
35
31
  }
36
32
 
@@ -54,17 +50,13 @@ function startPullDownRefresh (options = {}) {
54
50
  }
55
51
  }
56
52
  }
57
- return new Promise((resolve, reject) => {
58
- if (err) {
59
- const res = { errMsg: `startPullDownRefresh:fail ${err}` }
60
- webHandleFail(res, options.fail, options.complete)
61
- reject(res)
62
- } else {
63
- const res = { errMsg: 'startPullDownRefresh:ok' }
64
- webHandleSuccess(res, options.success, options.complete)
65
- resolve(res)
66
- }
67
- })
53
+ if (err) {
54
+ const res = { errMsg: `startPullDownRefresh:fail ${err}` }
55
+ webHandleFail(res, options.fail, options.complete)
56
+ } else {
57
+ const res = { errMsg: 'startPullDownRefresh:ok' }
58
+ webHandleSuccess(res, options.success, options.complete)
59
+ }
68
60
  }
69
61
  }
70
62
 
@@ -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
+ }
@@ -51,13 +51,11 @@ function request (options = { url: '' }) {
51
51
  clarifyTimeoutError: false
52
52
  }
53
53
  }
54
-
55
54
  if (method === 'GET') {
56
55
  rOptions.params = rOptions.data || {}
57
56
  delete rOptions.data
58
57
  }
59
-
60
- const promise = axios(rOptions).then(res => {
58
+ axios(rOptions).then(res => {
61
59
  let data = res.data
62
60
  if (dataType === 'json' && typeof data === 'string') {
63
61
  try {
@@ -81,8 +79,7 @@ function request (options = { url: '' }) {
81
79
  }
82
80
  })
83
81
 
84
- promise.__returned = requestTask
85
- return promise
82
+ return requestTask
86
83
  }
87
84
 
88
85
  export {
@@ -0,0 +1,45 @@
1
+ import { changeOpts, error, noop } from '../../../common/js'
2
+
3
+ const TIPS_NAME = '支付宝环境 mpx'
4
+
5
+ function requestPayment (options = {}) {
6
+ if (!options.tradeNO) {
7
+ error(`请在支付函数 ${TIPS_NAME}.requestPayment 中添加 tradeNO 参数用于支付宝支付`)
8
+ }
9
+
10
+ const opts = changeOpts(options, {
11
+ timeStamp: '',
12
+ nonceStr: '',
13
+ package: '',
14
+ signType: '',
15
+ paySign: ''
16
+ })
17
+
18
+ const cacheSuc = opts.success || noop
19
+ const cacheFail = opts.fail || noop
20
+
21
+ // 抹平用微信的 complete
22
+ if (typeof opts.complete === 'function') {
23
+ const cacheComplete = opts.complete
24
+ opts.complete = function (res) {
25
+ if (+res.resultCode === 9000) {
26
+ res.errMsg = 'requestPayment:ok'
27
+ cacheComplete.call(this, res)
28
+ }
29
+ }
30
+ }
31
+
32
+ opts.success = function (res) {
33
+ if (+res.resultCode === 9000) {
34
+ cacheSuc.call(this, res)
35
+ } else {
36
+ cacheFail.call(this, res)
37
+ }
38
+ }
39
+
40
+ my.tradePay(opts)
41
+ }
42
+
43
+ export {
44
+ requestPayment
45
+ }
@@ -0,0 +1,9 @@
1
+ import { getEnvObj, envError } from '../../../common/js'
2
+
3
+ const ENV_OBJ = getEnvObj()
4
+
5
+ const requestPayment = ENV_OBJ.requestPayment || envError('requestPayment')
6
+
7
+ export {
8
+ requestPayment
9
+ }
@@ -0,0 +1,21 @@
1
+ import { getEnvObj, envError } from '../../../common/js'
2
+
3
+ const ENV_OBJ = getEnvObj()
4
+
5
+ const redirectTo = ENV_OBJ.redirectTo || envError('redirectTo')
6
+
7
+ const navigateTo = ENV_OBJ.navigateTo || envError('navigateTo')
8
+
9
+ const navigateBack = ENV_OBJ.navigateBack || envError('navigateBack')
10
+
11
+ const reLaunch = ENV_OBJ.reLaunch || envError('reLaunch')
12
+
13
+ const switchTab = ENV_OBJ.switchTab || envError('switchTab')
14
+
15
+ export {
16
+ redirectTo,
17
+ navigateTo,
18
+ navigateBack,
19
+ reLaunch,
20
+ switchTab
21
+ }