@mpxjs/api-proxy 2.9.41-react.0 → 2.9.43
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.
|
|
3
|
+
"version": "2.9.43",
|
|
4
4
|
"description": "convert miniprogram API at each end",
|
|
5
5
|
"module": "src/index.js",
|
|
6
6
|
"types": "@types/index.d.ts",
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"optional": true
|
|
64
64
|
}
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "92a347518d15400f87c380bc7248b8b6254631cf"
|
|
67
67
|
}
|
|
@@ -2,11 +2,6 @@ import { webHandleSuccess, webHandleFail } from '../../../common/js'
|
|
|
2
2
|
import { parseQuery } from '@mpxjs/utils'
|
|
3
3
|
|
|
4
4
|
function parseUrl (url) {
|
|
5
|
-
if (url.startsWith('/')) {
|
|
6
|
-
url = url.slice(1)
|
|
7
|
-
} else {
|
|
8
|
-
// todo 处理相对路径
|
|
9
|
-
}
|
|
10
5
|
let path = url
|
|
11
6
|
let query = ''
|
|
12
7
|
const queryIndex = url.indexOf('?')
|
|
@@ -21,12 +16,46 @@ function parseUrl (url) {
|
|
|
21
16
|
}
|
|
22
17
|
}
|
|
23
18
|
|
|
19
|
+
function getBasePath (navigation) {
|
|
20
|
+
if (navigation) {
|
|
21
|
+
const state = navigation.getState()
|
|
22
|
+
return '/' + state.routes[state.index].name
|
|
23
|
+
}
|
|
24
|
+
return '/'
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function resolvePath (relative, base) {
|
|
28
|
+
const firstChar = relative.charAt(0)
|
|
29
|
+
if (firstChar === '/') {
|
|
30
|
+
return relative
|
|
31
|
+
}
|
|
32
|
+
const stack = base.split('/')
|
|
33
|
+
stack.pop()
|
|
34
|
+
// resolve relative path
|
|
35
|
+
const segments = relative.replace(/^\//, '').split('/')
|
|
36
|
+
for (let i = 0; i < segments.length; i++) {
|
|
37
|
+
const segment = segments[i]
|
|
38
|
+
if (segment === '..') {
|
|
39
|
+
stack.pop()
|
|
40
|
+
} else if (segment !== '.') {
|
|
41
|
+
stack.push(segment)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
// ensure leading slash
|
|
45
|
+
if (stack[0] !== '') {
|
|
46
|
+
stack.unshift('')
|
|
47
|
+
}
|
|
48
|
+
return stack.join('/')
|
|
49
|
+
}
|
|
50
|
+
|
|
24
51
|
function navigateTo (options = {}) {
|
|
25
|
-
const
|
|
52
|
+
const navigation = Object.values(global.__mpxPagesMap || {})[0]?.[1]
|
|
26
53
|
const navigationHelper = global.__navigationHelper
|
|
27
|
-
if (
|
|
54
|
+
if (navigation && navigationHelper) {
|
|
28
55
|
const { path, queryObj } = parseUrl(options.url)
|
|
29
|
-
|
|
56
|
+
const basePath = getBasePath(navigation)
|
|
57
|
+
const finalPath = resolvePath(path, basePath).slice(1)
|
|
58
|
+
navigation.push(finalPath, queryObj)
|
|
30
59
|
navigationHelper.lastSuccessCallback = () => {
|
|
31
60
|
const res = { errMsg: 'navigateTo:ok' }
|
|
32
61
|
webHandleSuccess(res, options.success, options.complete)
|
|
@@ -39,11 +68,13 @@ function navigateTo (options = {}) {
|
|
|
39
68
|
}
|
|
40
69
|
|
|
41
70
|
function redirectTo (options = {}) {
|
|
42
|
-
const
|
|
71
|
+
const navigation = Object.values(global.__mpxPagesMap || {})[0]?.[1]
|
|
43
72
|
const navigationHelper = global.__navigationHelper
|
|
44
|
-
if (
|
|
73
|
+
if (navigation && navigationHelper) {
|
|
45
74
|
const { path, queryObj } = parseUrl(options.url)
|
|
46
|
-
|
|
75
|
+
const basePath = getBasePath(navigation)
|
|
76
|
+
const finalPath = resolvePath(path, basePath).slice(1)
|
|
77
|
+
navigation.replace(finalPath, queryObj)
|
|
47
78
|
navigationHelper.lastSuccessCallback = () => {
|
|
48
79
|
const res = { errMsg: 'redirectTo:ok' }
|
|
49
80
|
webHandleSuccess(res, options.success, options.complete)
|
|
@@ -56,10 +87,10 @@ function redirectTo (options = {}) {
|
|
|
56
87
|
}
|
|
57
88
|
|
|
58
89
|
function navigateBack (options = {}) {
|
|
59
|
-
const
|
|
90
|
+
const navigation = Object.values(global.__mpxPagesMap || {})[0]?.[1]
|
|
60
91
|
const navigationHelper = global.__navigationHelper
|
|
61
|
-
if (
|
|
62
|
-
|
|
92
|
+
if (navigation && navigationHelper) {
|
|
93
|
+
navigation.pop(options.delta || 1)
|
|
63
94
|
navigationHelper.lastSuccessCallback = () => {
|
|
64
95
|
const res = { errMsg: 'navigateBack:ok' }
|
|
65
96
|
webHandleSuccess(res, options.success, options.complete)
|
|
@@ -72,15 +103,17 @@ function navigateBack (options = {}) {
|
|
|
72
103
|
}
|
|
73
104
|
|
|
74
105
|
function reLaunch (options = {}) {
|
|
75
|
-
const
|
|
106
|
+
const navigation = Object.values(global.__mpxPagesMap || {})[0]?.[1]
|
|
76
107
|
const navigationHelper = global.__navigationHelper
|
|
77
|
-
if (
|
|
108
|
+
if (navigation && navigationHelper) {
|
|
78
109
|
const { path, queryObj } = parseUrl(options.url)
|
|
79
|
-
|
|
110
|
+
const basePath = getBasePath(navigation)
|
|
111
|
+
const finalPath = resolvePath(path, basePath).slice(1)
|
|
112
|
+
navigation.reset({
|
|
80
113
|
index: 0,
|
|
81
114
|
routes: [
|
|
82
115
|
{
|
|
83
|
-
name:
|
|
116
|
+
name: finalPath,
|
|
84
117
|
params: queryObj
|
|
85
118
|
}
|
|
86
119
|
]
|