@mpxjs/api-proxy 2.10.6-beta.4 → 2.10.7-beta.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/api-proxy",
3
- "version": "2.10.6-beta.4",
3
+ "version": "2.10.7-beta.1",
4
4
  "description": "convert miniprogram API at each end",
5
5
  "module": "src/index.js",
6
6
  "types": "@types/index.d.ts",
@@ -37,7 +37,7 @@
37
37
  },
38
38
  "homepage": "https://github.com/didi/mpx#readme",
39
39
  "dependencies": {
40
- "@mpxjs/utils": "^2.10.6 | ^2.10.6-beta.1",
40
+ "@mpxjs/utils": "^2.10.7 | ^2.10.7-beta.1",
41
41
  "axios": "^1.7.3"
42
42
  },
43
43
  "peerDependencies": {
@@ -95,6 +95,30 @@ function getCurrentPageId () {
95
95
  return id
96
96
  }
97
97
 
98
+ function resolvePath (relative, base) {
99
+ const firstChar = relative.charAt(0)
100
+ if (firstChar === '/') {
101
+ return relative
102
+ }
103
+ const stack = base.split('/')
104
+ stack.pop()
105
+ // resolve relative path
106
+ const segments = relative.replace(/^\//, '').split('/')
107
+ for (let i = 0; i < segments.length; i++) {
108
+ const segment = segments[i]
109
+ if (segment === '..') {
110
+ stack.pop()
111
+ } else if (segment !== '.') {
112
+ stack.push(segment)
113
+ }
114
+ }
115
+ // ensure leading slash
116
+ if (stack[0] !== '') {
117
+ stack.unshift('')
118
+ }
119
+ return stack.join('/')
120
+ }
121
+
98
122
  const ENV_OBJ = getEnvObj()
99
123
 
100
124
  export {
@@ -110,5 +134,6 @@ export {
110
134
  successHandle,
111
135
  failHandle,
112
136
  getFocusedNavigation,
113
- getCurrentPageId
137
+ getCurrentPageId,
138
+ resolvePath
114
139
  }
@@ -1,6 +1,7 @@
1
- import { successHandle, failHandle } from '../../../common/js'
1
+ import { successHandle, failHandle, resolvePath } from '../../../common/js'
2
2
  import { parseUrlQuery as parseUrl } from '@mpxjs/utils'
3
3
  import { nextTick } from '../next-tick'
4
+ import { EventChannel } from '../event-channel'
4
5
 
5
6
  function getBasePath (navigation) {
6
7
  if (navigation) {
@@ -10,29 +11,6 @@ function getBasePath (navigation) {
10
11
  return '/'
11
12
  }
12
13
 
13
- function resolvePath (relative, base) {
14
- const firstChar = relative.charAt(0)
15
- if (firstChar === '/') {
16
- return relative
17
- }
18
- const stack = base.split('/')
19
- stack.pop()
20
- // resolve relative path
21
- const segments = relative.replace(/^\//, '').split('/')
22
- for (let i = 0; i < segments.length; i++) {
23
- const segment = segments[i]
24
- if (segment === '..') {
25
- stack.pop()
26
- } else if (segment !== '.') {
27
- stack.push(segment)
28
- }
29
- }
30
- // ensure leading slash
31
- if (stack[0] !== '') {
32
- stack.unshift('')
33
- }
34
- return stack.join('/')
35
- }
36
14
  let timerId = null
37
15
  function isLock (navigationHelper, type, options) {
38
16
  if (navigationHelper.lastSuccessCallback && navigationHelper.lastFailCallback) {
@@ -57,12 +35,21 @@ function navigateTo (options = {}) {
57
35
  }
58
36
  const navigation = Object.values(global.__mpxPagesMap || {})[0]?.[1]
59
37
  if (navigation && navigationHelper) {
38
+ const eventChannel = new EventChannel()
39
+ if (options.events) {
40
+ eventChannel._addListeners(options.events)
41
+ }
60
42
  const { path, queryObj } = parseUrl(options.url)
61
43
  const basePath = getBasePath(navigation)
62
44
  const finalPath = resolvePath(path, basePath).slice(1)
45
+
46
+ global.__mpxEventChannel = {
47
+ route: finalPath,
48
+ eventChannel
49
+ }
63
50
  navigation.push(finalPath, queryObj)
64
51
  navigationHelper.lastSuccessCallback = () => {
65
- const res = { errMsg: 'navigateTo:ok' }
52
+ const res = { errMsg: 'navigateTo:ok', eventChannel }
66
53
  successHandle(res, options.success, options.complete)
67
54
  }
68
55
  navigationHelper.lastFailCallback = (msg) => {
@@ -1,4 +1,4 @@
1
- import { successHandle, failHandle, isTabBarPage, throwSSRWarning, isBrowser } from '../../../common/js'
1
+ import { successHandle, failHandle, isTabBarPage, throwSSRWarning, isBrowser, resolvePath } from '../../../common/js'
2
2
  import { EventChannel } from '../event-channel'
3
3
 
4
4
  let routeCount = 0
@@ -46,9 +46,13 @@ function navigateTo (options = {}) {
46
46
  const res = { errMsg: 'navigateTo:fail can not navigateTo a tabBar page' }
47
47
  failHandle(res, options.fail, options.complete)
48
48
  }
49
+ const finalPath = resolvePath(options.url, router.currentRoute.path).slice(1)
49
50
  const eventChannel = new EventChannel()
50
51
  router.__mpxAction = {
51
- type: 'to',
52
+ type: 'to'
53
+ }
54
+ global.__mpxEventChannel = {
55
+ route: finalPath,
52
56
  eventChannel
53
57
  }
54
58
  if (options.events) {