@mpxjs/api-proxy 2.8.23-alpha → 2.8.25-alpha.18
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.8.
|
|
3
|
+
"version": "2.8.25-alpha.18",
|
|
4
4
|
"description": "convert miniprogram API at each end",
|
|
5
5
|
"module": "src/index.js",
|
|
6
6
|
"types": "@types/index.d.ts",
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"axios": "^0.21.1"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "14a16b3d7995ce01989d2b516038b381678006b3"
|
|
43
43
|
}
|
|
@@ -1,57 +1,48 @@
|
|
|
1
|
+
const notifyCenter = Hummer.notifyCenter
|
|
2
|
+
const { Memory } = __GLOBAL__
|
|
3
|
+
// 通过Memory 和 notifyCenter实现跨页面事件通道
|
|
4
|
+
// FIXME:可能存在的问题once订阅的移除 emit事件传参数量
|
|
1
5
|
class EventChannel {
|
|
2
|
-
constructor () {
|
|
3
|
-
this.listener = {}
|
|
4
|
-
}
|
|
5
|
-
|
|
6
6
|
emit (eventName, ...args) {
|
|
7
|
-
|
|
8
|
-
if (
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
} catch (e) {
|
|
13
|
-
console.log(`event "${eventName}" error ${e}`)
|
|
14
|
-
}
|
|
15
|
-
if (item.type === 'once') {
|
|
16
|
-
cbs.splice(index, 1)
|
|
17
|
-
}
|
|
18
|
-
})
|
|
7
|
+
notifyCenter.triggerEvent(eventName, args)
|
|
8
|
+
if (Memory.exist(`_ENENT_ONCE_${eventName}`)) {
|
|
9
|
+
// 订阅和发送可能不是一个上下文 暂时只能全部移除
|
|
10
|
+
this.off(eventName)
|
|
11
|
+
Memory.remove(`_ENENT_ONCE_${eventName}`)
|
|
19
12
|
}
|
|
20
13
|
}
|
|
21
14
|
|
|
22
15
|
off (eventName, EventCallback) {
|
|
23
|
-
|
|
24
|
-
const cbs = this.listener[eventName]
|
|
25
|
-
const copyCbs = []
|
|
26
|
-
if (cbs) {
|
|
27
|
-
cbs.forEach((item, index) => {
|
|
28
|
-
if (item.fn !== EventCallback) {
|
|
29
|
-
copyCbs.push(item)
|
|
30
|
-
}
|
|
31
|
-
})
|
|
32
|
-
}
|
|
33
|
-
this.listener[eventName] = copyCbs
|
|
34
|
-
} else {
|
|
35
|
-
this.listener[eventName] && (this.listener[eventName].length = 0)
|
|
36
|
-
}
|
|
16
|
+
notifyCenter.removeEventListener(eventName, EventCallback)
|
|
37
17
|
}
|
|
38
18
|
|
|
39
19
|
on (eventName, EventCallback) {
|
|
40
|
-
|
|
20
|
+
notifyCenter.addEventListener(eventName, EventCallback)
|
|
41
21
|
}
|
|
42
22
|
|
|
43
23
|
once (eventName, EventCallback) {
|
|
44
|
-
|
|
24
|
+
notifyCenter.addEventListener(eventName, EventCallback)
|
|
25
|
+
Memory.set(`_ENENT_ONCE_${eventName}`, 1)
|
|
45
26
|
}
|
|
46
27
|
|
|
47
28
|
_addListener (eventName, EventCallback, type) {
|
|
48
|
-
|
|
29
|
+
switch (type) {
|
|
30
|
+
case 'on':
|
|
31
|
+
this.on(eventName, EventCallback)
|
|
32
|
+
break
|
|
33
|
+
case 'once':
|
|
34
|
+
this.once(eventName, EventCallback)
|
|
35
|
+
break
|
|
36
|
+
default:
|
|
37
|
+
this.on(eventName, EventCallback)
|
|
38
|
+
break
|
|
39
|
+
}
|
|
49
40
|
}
|
|
50
41
|
|
|
51
42
|
_addListeners (events) {
|
|
52
43
|
if (Object.prototype.toString.call(events) === '[object Object]') {
|
|
53
44
|
Object.keys(events).forEach((eventName) => {
|
|
54
|
-
|
|
45
|
+
this.on(eventName, events[eventName])
|
|
55
46
|
})
|
|
56
47
|
}
|
|
57
48
|
}
|
|
@@ -38,7 +38,7 @@ function request (options = { url: '' }) {
|
|
|
38
38
|
requestFn.method = method
|
|
39
39
|
requestFn.timeout = timeout
|
|
40
40
|
requestFn.header = header
|
|
41
|
-
requestFn.
|
|
41
|
+
requestFn.param = data
|
|
42
42
|
requestFn.send((response) => {
|
|
43
43
|
let { status, header: resHeader, data: resData, error } = response
|
|
44
44
|
// 返回的数据处理
|
|
@@ -2,14 +2,39 @@ import { webHandleSuccess } from '../../../common/js'
|
|
|
2
2
|
import { EventChannel } from '../event-channel'
|
|
3
3
|
const { Navigator } = __GLOBAL__
|
|
4
4
|
|
|
5
|
+
function handleUrl (url) {
|
|
6
|
+
const [urlString, queryString] = url.split('?')
|
|
7
|
+
const queryObj = {}
|
|
8
|
+
|
|
9
|
+
if (!queryString) {
|
|
10
|
+
return {
|
|
11
|
+
query: queryObj,
|
|
12
|
+
url: urlString
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const paramsArray = queryString.split('&')
|
|
17
|
+
for (const pair of paramsArray) {
|
|
18
|
+
const [key, value] = pair.split('=')
|
|
19
|
+
queryObj[key] = decodeURIComponent(value)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
query: queryObj,
|
|
24
|
+
url: urlString
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
5
28
|
function redirectTo (options = {}) {
|
|
29
|
+
const { url, query } = handleUrl(options.url || '')
|
|
6
30
|
if (Navigator) {
|
|
7
|
-
Navigator.__mpxAction = { type: 'redirect' }
|
|
8
31
|
return new Promise((resolve, reject) => {
|
|
9
32
|
// 关闭本页面的跳转
|
|
10
33
|
Navigator.openPage(
|
|
11
34
|
{
|
|
12
|
-
url
|
|
35
|
+
url,
|
|
36
|
+
animated: false,
|
|
37
|
+
params: query,
|
|
13
38
|
closeSelf: true
|
|
14
39
|
},
|
|
15
40
|
// 执行环境变了 得不到执行的机会 故回调无效
|
|
@@ -23,25 +48,22 @@ function redirectTo (options = {}) {
|
|
|
23
48
|
}
|
|
24
49
|
|
|
25
50
|
function navigateTo (options = {}) {
|
|
51
|
+
const { url, query } = handleUrl(options.url || '')
|
|
52
|
+
const events = options.events
|
|
53
|
+
|
|
26
54
|
if (Navigator) {
|
|
27
55
|
const eventChannel = new EventChannel()
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
eventChannel
|
|
31
|
-
}
|
|
32
|
-
if (options.events) {
|
|
33
|
-
eventChannel._addListeners(options.events)
|
|
56
|
+
if (events) {
|
|
57
|
+
eventChannel._addListeners(events)
|
|
34
58
|
}
|
|
35
59
|
return new Promise((resolve, reject) => {
|
|
36
60
|
// 不关闭本页面的跳转
|
|
37
|
-
Navigator.openPage(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
)
|
|
44
|
-
const res = { errMsg: 'redirectTo:ok' }
|
|
61
|
+
Navigator.openPage({
|
|
62
|
+
url,
|
|
63
|
+
animated: true,
|
|
64
|
+
params: query
|
|
65
|
+
}, () => {})
|
|
66
|
+
const res = { errMsg: 'redirectTo:ok', eventChannel }
|
|
45
67
|
webHandleSuccess(res, options.success, options.complete)
|
|
46
68
|
resolve(res)
|
|
47
69
|
})
|
|
@@ -51,12 +73,9 @@ function navigateTo (options = {}) {
|
|
|
51
73
|
function navigateBack (options = {}) {
|
|
52
74
|
if (Navigator) {
|
|
53
75
|
const delta = options.delta || 1
|
|
54
|
-
Navigator.
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
// popBack方法
|
|
59
|
-
Navigator.popBack(delta, { animated: true })
|
|
76
|
+
Navigator.popBack(delta, {
|
|
77
|
+
animated: true
|
|
78
|
+
})
|
|
60
79
|
const res = { errMsg: 'navigateBack:ok' }
|
|
61
80
|
webHandleSuccess(res, options.success, options.complete)
|
|
62
81
|
return Promise.resolve(res)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { webHandleSuccess } from '../../../common/js'
|
|
2
|
+
const {
|
|
3
|
+
Hummer
|
|
4
|
+
} = __GLOBAL__
|
|
5
|
+
|
|
6
|
+
function setNavigationBarTitle (options = {}) {
|
|
7
|
+
const { title, success, complete } = options
|
|
8
|
+
Hummer.setTitle(title)
|
|
9
|
+
webHandleSuccess({ errMsg: 'setTitle:ok' }, success, complete)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function setNavigationBarColor (options = {}) {}
|
|
13
|
+
|
|
14
|
+
export {
|
|
15
|
+
setNavigationBarTitle,
|
|
16
|
+
setNavigationBarColor
|
|
17
|
+
}
|