@mpxjs/api-proxy 2.7.0-alpha.0 → 2.7.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.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/api-proxy",
|
|
3
|
-
"version": "2.7.0
|
|
3
|
+
"version": "2.7.0",
|
|
4
4
|
"description": "convert miniprogram API at each end",
|
|
5
5
|
"module": "src/index.js",
|
|
6
6
|
"types": "@types/index.d.ts",
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"@types",
|
|
16
16
|
"README.md"
|
|
17
17
|
],
|
|
18
|
+
"main": "src/index.js",
|
|
18
19
|
"repository": {
|
|
19
20
|
"type": "git",
|
|
20
21
|
"url": "git@github.com/didi/mpx.git"
|
|
@@ -35,11 +36,8 @@
|
|
|
35
36
|
"url": "https://github.com/didi/mpx/issues"
|
|
36
37
|
},
|
|
37
38
|
"homepage": "https://github.com/didi/mpx#readme",
|
|
38
|
-
"peerDependencies": {
|
|
39
|
-
"@mpxjs/core": "^2.6.95-alpha.0"
|
|
40
|
-
},
|
|
41
39
|
"dependencies": {
|
|
42
40
|
"axios": "^0.21.1"
|
|
43
41
|
},
|
|
44
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "0f2454782bfca526bd281618b99b9aacb1ca2a75"
|
|
45
43
|
}
|
package/src/common/js/web.js
CHANGED
|
@@ -8,7 +8,15 @@ function webHandleFail (result, fail, complete) {
|
|
|
8
8
|
typeof complete === 'function' && complete(result)
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
function isTabBarPage (url, router) {
|
|
12
|
+
const tabBarPagesMap = global.__tabBarPagesMap
|
|
13
|
+
if (!tabBarPagesMap || !url) return false
|
|
14
|
+
const path = router.match(url, router.history.current).path
|
|
15
|
+
return !!tabBarPagesMap[path.slice(1)]
|
|
16
|
+
}
|
|
17
|
+
|
|
11
18
|
export {
|
|
12
19
|
webHandleSuccess,
|
|
13
|
-
webHandleFail
|
|
20
|
+
webHandleFail,
|
|
21
|
+
isTabBarPage
|
|
14
22
|
}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import { webHandleSuccess, webHandleFail } from '../../../common/js'
|
|
1
|
+
import { webHandleSuccess, webHandleFail, isTabBarPage } from '../../../common/js'
|
|
2
2
|
import { EventChannel } from '../event-channel'
|
|
3
3
|
|
|
4
4
|
function redirectTo (options = {}) {
|
|
5
5
|
const router = global.__mpxRouter
|
|
6
6
|
if (router) {
|
|
7
|
+
if (isTabBarPage(options.url, router)) {
|
|
8
|
+
const res = { errMsg: 'redirectTo:fail can not redirectTo a tabBar page' }
|
|
9
|
+
webHandleFail(res, options.fail, options.complete)
|
|
10
|
+
return Promise.reject(res)
|
|
11
|
+
}
|
|
7
12
|
router.__mpxAction = { type: 'redirect' }
|
|
8
13
|
return new Promise((resolve, reject) => {
|
|
9
14
|
router.replace(
|
|
@@ -28,6 +33,11 @@ function redirectTo (options = {}) {
|
|
|
28
33
|
function navigateTo (options = {}) {
|
|
29
34
|
const router = global.__mpxRouter
|
|
30
35
|
if (router) {
|
|
36
|
+
if (isTabBarPage(options.url, router)) {
|
|
37
|
+
const res = { errMsg: 'navigateTo:fail can not navigateTo a tabBar page' }
|
|
38
|
+
webHandleFail(res, options.fail, options.complete)
|
|
39
|
+
return Promise.reject(res)
|
|
40
|
+
}
|
|
31
41
|
const eventChannel = new EventChannel()
|
|
32
42
|
router.__mpxAction = {
|
|
33
43
|
type: 'to',
|
|
@@ -71,11 +81,13 @@ function navigateBack (options = {}) {
|
|
|
71
81
|
}
|
|
72
82
|
}
|
|
73
83
|
|
|
84
|
+
let reLaunchCount = 0
|
|
85
|
+
|
|
74
86
|
function reLaunch (options = {}) {
|
|
75
87
|
const router = global.__mpxRouter
|
|
76
88
|
if (router) {
|
|
89
|
+
if (reLaunchCount === 0 && router.currentRoute.query.reLaunchCount) reLaunchCount = router.currentRoute.query.reLaunchCount
|
|
77
90
|
const delta = router.stack.length - 1
|
|
78
|
-
let reLaunchCount = router.currentRoute.query.reLaunchCount || 0
|
|
79
91
|
router.__mpxAction = {
|
|
80
92
|
type: 'reLaunch',
|
|
81
93
|
path: options.url,
|
|
@@ -120,7 +132,7 @@ function switchTab (options = {}) {
|
|
|
120
132
|
const toRoute = router.match(options.url, router.history.current)
|
|
121
133
|
const currentRoute = router.currentRoute
|
|
122
134
|
if (toRoute.path !== currentRoute.path) {
|
|
123
|
-
if (
|
|
135
|
+
if (!isTabBarPage(options.url, router)) {
|
|
124
136
|
const res = { errMsg: 'switchTab:fail can not switch to no-tabBar page!' }
|
|
125
137
|
webHandleFail(res, options.fail, options.complete)
|
|
126
138
|
return Promise.reject(res)
|