@mpxjs/api-proxy 2.9.70-alpha.0 → 2.9.70
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/@types/index.d.ts +13 -0
- package/LICENSE +433 -0
- package/package.json +4 -3
- package/src/common/js/index.js +0 -1
- package/src/common/js/promisify.js +11 -3
- package/src/common/js/utils.js +1 -11
- package/src/platform/api/action-sheet/rnActionSheet.jsx +67 -81
- package/src/platform/api/app/index.web.js +26 -11
- package/src/platform/api/create-intersection-observer/rnIntersectionObserver.js +2 -2
- package/src/platform/api/image/index.ali.js +4 -1
- package/src/platform/api/image/index.ios.js +45 -0
- package/src/platform/api/image/index.js +4 -1
- package/src/platform/api/image/index.web.js +46 -2
- package/src/platform/api/modal/rnModal.jsx +7 -8
- package/src/platform/api/request/index.web.js +2 -3
- package/src/platform/api/set-navigation-bar/index.ali.js +6 -1
- package/src/platform/api/set-navigation-bar/index.ios.js +6 -3
- package/src/platform/api/set-navigation-bar/index.js +4 -1
- package/src/platform/api/set-navigation-bar/index.web.js +5 -2
- package/src/platform/api/setting/index.js +19 -0
- package/src/platform/api/system/index.ios.js +84 -1
- package/src/platform/api/system/rnSystem.js +35 -72
- package/src/platform/api/toast/rnToast.jsx +23 -16
- package/src/platform/index.js +4 -1
- package/src/common/js/ToPromise.js +0 -25
- package/src/common/stylus/Modal.tenon.styl +0 -42
- package/src/common/stylus/Toast.tenon.styl +0 -56
- package/src/index.tenon.js +0 -27
- package/src/platform/api/animation/animation.tenon.js +0 -225
- package/src/platform/api/animation/index.tenon.js +0 -89
- package/src/platform/api/event-channel/index.tenon.js +0 -52
- package/src/platform/api/modal/index.tenon.js +0 -12
- package/src/platform/api/modal/tenonModal.js +0 -154
- package/src/platform/api/next-tick/index.tenon.js +0 -11
- package/src/platform/api/request/index.tenon.js +0 -85
- package/src/platform/api/request/tenonUtil.js +0 -0
- package/src/platform/api/route/index.tenon.js +0 -121
- package/src/platform/api/set-navigation-bar/index.tenon.js +0 -17
- package/src/platform/api/socket/SocketTask.tenon.js +0 -105
- package/src/platform/api/socket/index.tenon.js +0 -48
- package/src/platform/api/storage/index.tenon.js +0 -144
- package/src/platform/api/system/index.tenon.js +0 -52
- package/src/platform/api/system/rnWindowInfo.js +0 -42
- package/src/platform/api/toast/Toast.tenon.js +0 -101
- package/src/platform/api/toast/index.tenon.js +0 -36
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import Animation from './animation'
|
|
2
|
-
|
|
3
|
-
const createAnimation = function (options = {}) {
|
|
4
|
-
// timingFunction 修改为easing
|
|
5
|
-
options = Object.assign({
|
|
6
|
-
duration: 400,
|
|
7
|
-
timingFunction: 'linear',
|
|
8
|
-
delay: 0,
|
|
9
|
-
transformOrigin: '50% 50% 0'
|
|
10
|
-
}, options)
|
|
11
|
-
return new Animation(options)
|
|
12
|
-
}
|
|
13
|
-
// tennon需要返回的是一个对象
|
|
14
|
-
// 基础动画
|
|
15
|
-
// {
|
|
16
|
-
// duration: 5000,
|
|
17
|
-
// repeatCount: -1,
|
|
18
|
-
// easing: "linear",
|
|
19
|
-
// onStart: () => {console.log('Basic Animation Start!')},
|
|
20
|
-
// onEnd: () => {console.log('Basic Animation End!')},
|
|
21
|
-
// styles: {
|
|
22
|
-
// position: {
|
|
23
|
-
// x: '100hm',
|
|
24
|
-
// y: 0
|
|
25
|
-
// },
|
|
26
|
-
// opacity: 0.8
|
|
27
|
-
// }
|
|
28
|
-
// }
|
|
29
|
-
// 关键帧动画
|
|
30
|
-
// {
|
|
31
|
-
// duration: 5000, // 动画持续时间,单位 ms
|
|
32
|
-
// repeatCount: -1, // 重复的次数
|
|
33
|
-
// easing: "linear",
|
|
34
|
-
// onStart: () => {console.log('Frame Animation Start!')},
|
|
35
|
-
// onEnd: () => {console.log('Frame Animation End!')},
|
|
36
|
-
// keyframes: [{
|
|
37
|
-
// styles: {
|
|
38
|
-
// position: {
|
|
39
|
-
// x: '100hm',
|
|
40
|
-
// y: 0
|
|
41
|
-
// },
|
|
42
|
-
// opacity: 0.8
|
|
43
|
-
// },
|
|
44
|
-
// percent: 0.5
|
|
45
|
-
// }, {
|
|
46
|
-
// styles: {
|
|
47
|
-
// position: {
|
|
48
|
-
// x: '200hm',
|
|
49
|
-
// y: 0
|
|
50
|
-
// },
|
|
51
|
-
// opacity: 1
|
|
52
|
-
// },
|
|
53
|
-
// percent: 1
|
|
54
|
-
// }]
|
|
55
|
-
// }
|
|
56
|
-
// 次序动画
|
|
57
|
-
// {
|
|
58
|
-
// steps: [{
|
|
59
|
-
// duration: 5000,
|
|
60
|
-
// repeatCount: 1,
|
|
61
|
-
// easing: "linear",
|
|
62
|
-
// onStart: () => {console.log('Animation Start!')},
|
|
63
|
-
// onEnd: () => {console.log('Animation End!')},
|
|
64
|
-
// styles: {
|
|
65
|
-
// position: {
|
|
66
|
-
// x: '100hm',
|
|
67
|
-
// y: 0
|
|
68
|
-
// },
|
|
69
|
-
// opacity: 0.8
|
|
70
|
-
// }
|
|
71
|
-
// }, {
|
|
72
|
-
// duration: 5000,
|
|
73
|
-
// repeatCount: 1,
|
|
74
|
-
// easing: "linear",
|
|
75
|
-
// onStart: () => {console.log('Animation Start!')},
|
|
76
|
-
// onEnd: () => {console.log('Animation End!')},
|
|
77
|
-
// styles: {
|
|
78
|
-
// position: {
|
|
79
|
-
// x: '200hm',
|
|
80
|
-
// y: 0
|
|
81
|
-
// },
|
|
82
|
-
// opacity: 0.8
|
|
83
|
-
// }
|
|
84
|
-
// }]
|
|
85
|
-
// }
|
|
86
|
-
|
|
87
|
-
export {
|
|
88
|
-
createAnimation
|
|
89
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
const notifyCenter = Hummer.notifyCenter
|
|
2
|
-
const { Memory } = __GLOBAL__
|
|
3
|
-
// 通过Memory 和 notifyCenter实现跨页面事件通道
|
|
4
|
-
// FIXME:可能存在的问题once订阅的移除 emit事件传参数量
|
|
5
|
-
class EventChannel {
|
|
6
|
-
emit (eventName, ...args) {
|
|
7
|
-
notifyCenter.triggerEvent(eventName, args)
|
|
8
|
-
if (Memory.exist(`_ENENT_ONCE_${eventName}`)) {
|
|
9
|
-
// 订阅和发送可能不是一个上下文 暂时只能全部移除
|
|
10
|
-
this.off(eventName)
|
|
11
|
-
Memory.remove(`_ENENT_ONCE_${eventName}`)
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
off (eventName, EventCallback) {
|
|
16
|
-
notifyCenter.removeEventListener(eventName, EventCallback)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
on (eventName, EventCallback) {
|
|
20
|
-
notifyCenter.addEventListener(eventName, EventCallback)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
once (eventName, EventCallback) {
|
|
24
|
-
notifyCenter.addEventListener(eventName, EventCallback)
|
|
25
|
-
Memory.set(`_ENENT_ONCE_${eventName}`, 1)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
_addListener (eventName, EventCallback, type) {
|
|
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
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
_addListeners (events) {
|
|
43
|
-
if (Object.prototype.toString.call(events) === '[object Object]') {
|
|
44
|
-
Object.keys(events).forEach((eventName) => {
|
|
45
|
-
this.on(eventName, events[eventName])
|
|
46
|
-
})
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
export {
|
|
51
|
-
EventChannel
|
|
52
|
-
}
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import { ToPromise, successHandle } from '../../../common/js'
|
|
2
|
-
import '../../../common/stylus/Modal.styl'
|
|
3
|
-
import { getClassStyle } from '@hummer/tenon-vue'
|
|
4
|
-
|
|
5
|
-
// 汉字为两个字符,字母/数字为一个字符
|
|
6
|
-
const _getLength = t => {
|
|
7
|
-
let len = 0
|
|
8
|
-
for (let i = 0; i < t.length; i++) {
|
|
9
|
-
if (t.charCodeAt(i) > 127 || t.charCodeAt(i) === 94) {
|
|
10
|
-
len += 2
|
|
11
|
-
} else {
|
|
12
|
-
len++
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
return len
|
|
16
|
-
}
|
|
17
|
-
function createDom (Element, attrs = {}, children = []) {
|
|
18
|
-
const dom = new Element()
|
|
19
|
-
Object.keys(attrs).forEach(k => Reflect.set(dom, k, attrs[k]))
|
|
20
|
-
children.length && children.forEach(child => dom.appendChild(child))
|
|
21
|
-
return dom
|
|
22
|
-
}
|
|
23
|
-
export default class Modal extends ToPromise {
|
|
24
|
-
constructor () {
|
|
25
|
-
super()
|
|
26
|
-
this.defaultOpts = {
|
|
27
|
-
title: '',
|
|
28
|
-
content: '',
|
|
29
|
-
showCancel: true,
|
|
30
|
-
cancelText: '取消',
|
|
31
|
-
cancelColor: '#000000',
|
|
32
|
-
confirmText: '确定',
|
|
33
|
-
confirmColor: '#576B95',
|
|
34
|
-
success: (...args) => {},
|
|
35
|
-
fail: (...args) => {},
|
|
36
|
-
complete: (...args) => {}
|
|
37
|
-
}
|
|
38
|
-
this.hideTimer = null
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
show (options = {}) {
|
|
42
|
-
if (options.confirmText && _getLength(options.confirmText) > 8) {
|
|
43
|
-
// eslint-disable-next-line
|
|
44
|
-
return Promise.reject({
|
|
45
|
-
errMsg:
|
|
46
|
-
'showModal:fail confirmText length should not larger than 4 Chinese characters'
|
|
47
|
-
})
|
|
48
|
-
}
|
|
49
|
-
if (options.cancelText && _getLength(options.cancelText) > 8) {
|
|
50
|
-
// eslint-disable-next-line
|
|
51
|
-
return Promise.reject({
|
|
52
|
-
errMsg:
|
|
53
|
-
'showModal:fail cancelText length should not larger than 4 Chinese characters'
|
|
54
|
-
})
|
|
55
|
-
}
|
|
56
|
-
if (this.hideTimer) {
|
|
57
|
-
clearTimeout(this.hideTimer)
|
|
58
|
-
this.hideTimer = null
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
this.box = createDom(
|
|
62
|
-
View,
|
|
63
|
-
{ style: getClassStyle(null, '__mpx_modal_box__') },
|
|
64
|
-
[
|
|
65
|
-
createDom(
|
|
66
|
-
View,
|
|
67
|
-
{ style: getClassStyle(null, '__mpx_modal_title_view__') },
|
|
68
|
-
[
|
|
69
|
-
(this.title = createDom(Text, {
|
|
70
|
-
style: getClassStyle(null, '__mpx_modal_title__')
|
|
71
|
-
}))
|
|
72
|
-
]
|
|
73
|
-
),
|
|
74
|
-
createDom(
|
|
75
|
-
View,
|
|
76
|
-
{ style: getClassStyle(null, '__mpx_modal_content_view__') },
|
|
77
|
-
[
|
|
78
|
-
(this.content = createDom(Text, {
|
|
79
|
-
style: getClassStyle(null, '__mpx_modal_content__')
|
|
80
|
-
}))
|
|
81
|
-
]
|
|
82
|
-
),
|
|
83
|
-
(this.btns = createDom(
|
|
84
|
-
View,
|
|
85
|
-
{ style: getClassStyle(null, '__mpx_modal_btns__') },
|
|
86
|
-
[
|
|
87
|
-
(this.cancelBtn = createDom(Text, {
|
|
88
|
-
style: getClassStyle(null, '__mpx_modal_cancel__')
|
|
89
|
-
})),
|
|
90
|
-
(this.confirmBtn = createDom(Text, {
|
|
91
|
-
style: getClassStyle(null, '__mpx_modal_confirm__')
|
|
92
|
-
}))
|
|
93
|
-
]
|
|
94
|
-
))
|
|
95
|
-
]
|
|
96
|
-
)
|
|
97
|
-
|
|
98
|
-
const opts = Object.assign({}, this.defaultOpts, options)
|
|
99
|
-
this.title.text = opts.title
|
|
100
|
-
this.content.text = opts.content
|
|
101
|
-
this.dialog = new Dialog()
|
|
102
|
-
this.dialog.cancelable = false
|
|
103
|
-
this.cancelBtn.text = opts.cancelText
|
|
104
|
-
this.confirmBtn.text = opts.confirmText
|
|
105
|
-
this.confirmBtn.style = Object.assign(this.confirmBtn.style, { color: opts.confirmColor })
|
|
106
|
-
if (opts.showCancel !== true) {
|
|
107
|
-
this.cancelBtn.style = Object.assign(
|
|
108
|
-
this.cancelBtn.style,
|
|
109
|
-
getClassStyle(null, '__mpx_modal_hide__')
|
|
110
|
-
)
|
|
111
|
-
} else {
|
|
112
|
-
this.cancelBtn.style = Object.assign(
|
|
113
|
-
this.cancelBtn.style,
|
|
114
|
-
{ color: opts.cancelColor }
|
|
115
|
-
)
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
this.cancelBtn.addEventListener('tap', event => {
|
|
119
|
-
this.hide()
|
|
120
|
-
const result = {
|
|
121
|
-
errMsg: 'showModal:ok',
|
|
122
|
-
cancel: true,
|
|
123
|
-
confirm: false
|
|
124
|
-
}
|
|
125
|
-
successHandle(result, opts.success, opts.complete)
|
|
126
|
-
this.toPromiseResolve(result)
|
|
127
|
-
})
|
|
128
|
-
|
|
129
|
-
this.confirmBtn.addEventListener('tap', event => {
|
|
130
|
-
this.hide()
|
|
131
|
-
const result = {
|
|
132
|
-
errMsg: 'showModal:ok',
|
|
133
|
-
cancel: false,
|
|
134
|
-
confirm: true
|
|
135
|
-
}
|
|
136
|
-
successHandle(result, opts.success, opts.complete)
|
|
137
|
-
this.toPromiseResolve(result)
|
|
138
|
-
})
|
|
139
|
-
|
|
140
|
-
this.dialog.custom(this.box)
|
|
141
|
-
return this.toPromiseInitPromise()
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
hide () {
|
|
145
|
-
if (this.hideTimer) {
|
|
146
|
-
clearTimeout(this.hideTimer)
|
|
147
|
-
this.hideTimer = null
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
this.hideTimer = setTimeout(() => {
|
|
151
|
-
this.dialog.dismiss()
|
|
152
|
-
}, 0)
|
|
153
|
-
}
|
|
154
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { successHandle, failHandle } from '../../../common/js'
|
|
2
|
-
import { buildQueryStringUrl, parseHeader, tryJsonParse } from './tenonUtil'
|
|
3
|
-
const { Request } = __GLOBAL__
|
|
4
|
-
const requestFn = new Request()
|
|
5
|
-
|
|
6
|
-
function request (options = {}) {
|
|
7
|
-
let {
|
|
8
|
-
data = {},
|
|
9
|
-
method = 'GET',
|
|
10
|
-
dataType = 'form',
|
|
11
|
-
responseType = 'json',
|
|
12
|
-
timeout = 60 * 1000,
|
|
13
|
-
header = {},
|
|
14
|
-
success = null,
|
|
15
|
-
fail = null,
|
|
16
|
-
complete = null,
|
|
17
|
-
url = ''
|
|
18
|
-
} = options
|
|
19
|
-
|
|
20
|
-
method = method.toUpperCase()
|
|
21
|
-
|
|
22
|
-
if (['GET', 'PUT', 'DELETE'].indexOf(method) > -1) {
|
|
23
|
-
url = buildQueryStringUrl(data, url)
|
|
24
|
-
|
|
25
|
-
if (method === 'GET') {
|
|
26
|
-
data = {}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
switch (dataType) {
|
|
31
|
-
case 'form':
|
|
32
|
-
header = {
|
|
33
|
-
'Content-Type': 'application/x-www-form-urlencoded',
|
|
34
|
-
...header
|
|
35
|
-
}
|
|
36
|
-
break
|
|
37
|
-
|
|
38
|
-
case 'json':
|
|
39
|
-
header = {
|
|
40
|
-
'Content-Type': 'application/json',
|
|
41
|
-
...header
|
|
42
|
-
}
|
|
43
|
-
break
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
requestFn.url = url
|
|
47
|
-
requestFn.method = method
|
|
48
|
-
requestFn.timeout = timeout
|
|
49
|
-
requestFn.param = data
|
|
50
|
-
requestFn.header = header
|
|
51
|
-
|
|
52
|
-
return new Promise((resolve, reject) => {
|
|
53
|
-
requestFn.send((response) => {
|
|
54
|
-
let { status, header: resHeader, data: resData, error } = response
|
|
55
|
-
// 返回的数据处理
|
|
56
|
-
if (status >= 200 && status < 300) {
|
|
57
|
-
if (responseType === 'json' && typeof resData === 'string') {
|
|
58
|
-
try {
|
|
59
|
-
resData = JSON.parse(resData)
|
|
60
|
-
} catch (e) {
|
|
61
|
-
console.log('resDataType默认为"json", 尝试对返回内容进行JSON.parse, 但似乎出了些问题(若不希望对结果进行parse, 可传入resDataType: "text"): ', e)
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
const result = {
|
|
65
|
-
errMsg: 'request:ok',
|
|
66
|
-
data: resData,
|
|
67
|
-
statusCode: status,
|
|
68
|
-
header: resHeader
|
|
69
|
-
}
|
|
70
|
-
successHandle(result, success, complete)
|
|
71
|
-
resolve(result)
|
|
72
|
-
} else {
|
|
73
|
-
if (responseType === 'json') {
|
|
74
|
-
resData = tryJsonParse(resData)
|
|
75
|
-
}
|
|
76
|
-
header = parseHeader(header)
|
|
77
|
-
const res = { errMsg: `request:fail ${error.msg}`, data: resData, header }
|
|
78
|
-
failHandle(res, fail, complete)
|
|
79
|
-
reject(res)
|
|
80
|
-
}
|
|
81
|
-
})
|
|
82
|
-
})
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export { request }
|
|
File without changes
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { successHandle } from '../../../common/js'
|
|
2
|
-
import { EventChannel } from '../event-channel'
|
|
3
|
-
const { Navigator } = __GLOBAL__
|
|
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
|
-
|
|
28
|
-
function redirectTo (options = {}) {
|
|
29
|
-
const { url, query } = handleUrl(options.url || '')
|
|
30
|
-
if (Navigator) {
|
|
31
|
-
return new Promise((resolve, reject) => {
|
|
32
|
-
// 关闭本页面的跳转
|
|
33
|
-
Navigator.openPage(
|
|
34
|
-
{
|
|
35
|
-
url,
|
|
36
|
-
animated: false,
|
|
37
|
-
params: Object.assign({}, query, options.query || {}),
|
|
38
|
-
closeSelf: true
|
|
39
|
-
},
|
|
40
|
-
// 执行环境变了 得不到执行的机会 故回调无效
|
|
41
|
-
() => {}
|
|
42
|
-
)
|
|
43
|
-
const res = { errMsg: 'redirectTo:ok' }
|
|
44
|
-
successHandle(res, options.success, options.complete)
|
|
45
|
-
resolve(res)
|
|
46
|
-
})
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function navigateTo (options = {}) {
|
|
51
|
-
const { url, query } = handleUrl(options.url || '')
|
|
52
|
-
const events = options.events
|
|
53
|
-
|
|
54
|
-
if (Navigator) {
|
|
55
|
-
const eventChannel = new EventChannel()
|
|
56
|
-
if (events) {
|
|
57
|
-
eventChannel._addListeners(events)
|
|
58
|
-
}
|
|
59
|
-
return new Promise((resolve, reject) => {
|
|
60
|
-
// 不关闭本页面的跳转
|
|
61
|
-
Navigator.openPage({
|
|
62
|
-
url,
|
|
63
|
-
animated: true,
|
|
64
|
-
params: Object.assign({}, query, options.query || {})
|
|
65
|
-
})
|
|
66
|
-
const res = { errMsg: 'redirectTo:ok', eventChannel }
|
|
67
|
-
successHandle(res, options.success, options.complete)
|
|
68
|
-
resolve(res)
|
|
69
|
-
})
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function navigateBack (options = {}) {
|
|
74
|
-
if (Navigator) {
|
|
75
|
-
const delta = options.delta || 1
|
|
76
|
-
Navigator.popBack(delta, {
|
|
77
|
-
animated: true
|
|
78
|
-
})
|
|
79
|
-
const res = { errMsg: 'navigateBack:ok' }
|
|
80
|
-
successHandle(res, options.success, options.complete)
|
|
81
|
-
return Promise.resolve(res)
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function reLaunch (options = {}) {
|
|
86
|
-
if (Navigator) {
|
|
87
|
-
Navigator.__mpxAction = {
|
|
88
|
-
type: 'reLaunch'
|
|
89
|
-
}
|
|
90
|
-
Navigator.popToRootPage()
|
|
91
|
-
|
|
92
|
-
const res = { errMsg: 'reLaunch:ok' }
|
|
93
|
-
successHandle(res, options.success, options.complete)
|
|
94
|
-
return Promise.resolve(res)
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function switchTab (options = {}) {
|
|
99
|
-
if (Navigator) {
|
|
100
|
-
Navigator.__mpxAction = {
|
|
101
|
-
type: 'switch',
|
|
102
|
-
path: options.url,
|
|
103
|
-
replaced: true
|
|
104
|
-
}
|
|
105
|
-
return new Promise((resolve, reject) => {
|
|
106
|
-
Navigator.openPage(
|
|
107
|
-
{
|
|
108
|
-
url: options.url,
|
|
109
|
-
closeSelf: true
|
|
110
|
-
},
|
|
111
|
-
// 执行环境变了 得不到执行的机会 故回调无效
|
|
112
|
-
() => {}
|
|
113
|
-
)
|
|
114
|
-
const res = { errMsg: 'redirectTo:ok' }
|
|
115
|
-
successHandle(res, options.success, options.complete)
|
|
116
|
-
resolve(res)
|
|
117
|
-
})
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export { redirectTo, navigateTo, navigateBack, reLaunch, switchTab }
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { successHandle } 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
|
-
successHandle({ errMsg: 'setTitle:ok' }, success, complete)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function setNavigationBarColor (options = {}) {}
|
|
13
|
-
|
|
14
|
-
export {
|
|
15
|
-
setNavigationBarTitle,
|
|
16
|
-
setNavigationBarColor
|
|
17
|
-
}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { successHandle, failHandle, warn } from '../../../common/js'
|
|
2
|
-
const { WebSocket } = __GLOBAL__
|
|
3
|
-
|
|
4
|
-
class SocketTask {
|
|
5
|
-
constructor (url, protocols) {
|
|
6
|
-
this._openCb = null
|
|
7
|
-
this._closeCb = null
|
|
8
|
-
this._messageCb = null
|
|
9
|
-
this._errorCb = null
|
|
10
|
-
this._closeData = null
|
|
11
|
-
|
|
12
|
-
WebSocket.connect(url)
|
|
13
|
-
this.addListener(WebSocket)
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
get CONNECTING () {
|
|
17
|
-
warn('不支持CONNECTING')
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
get OPEN () {
|
|
21
|
-
warn('不支持OPEN')
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
get CLOSING () {
|
|
25
|
-
warn('不支持CLOSING')
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
get CLOSED () {
|
|
29
|
-
warn('不支持CLOSED')
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
get readyState () {
|
|
33
|
-
warn('不支持readyState')
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
send (options) {
|
|
37
|
-
// todo fail options needs tobe convert
|
|
38
|
-
// const { data = '', success, fail, complete } = options
|
|
39
|
-
const { data = '', success, complete } = options
|
|
40
|
-
WebSocket.send(data)
|
|
41
|
-
const res = { errMsg: 'sendSocketMessage:ok' }
|
|
42
|
-
successHandle(res, success, complete)
|
|
43
|
-
return Promise.resolve(res)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
close (options) {
|
|
47
|
-
const { code = 1000, reason = '', success, fail, complete } = options
|
|
48
|
-
this._closeData = {
|
|
49
|
-
code,
|
|
50
|
-
reason
|
|
51
|
-
}
|
|
52
|
-
try {
|
|
53
|
-
WebSocket.close()
|
|
54
|
-
const res = { errMsg: 'closeSocket:ok' }
|
|
55
|
-
successHandle(res, success, complete)
|
|
56
|
-
return Promise.resolve(res)
|
|
57
|
-
} catch (err) {
|
|
58
|
-
const res = { errMsg: `closeSocket:fail ${err}` }
|
|
59
|
-
failHandle(res, fail, complete)
|
|
60
|
-
if (!fail) {
|
|
61
|
-
return Promise.reject(res)
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
addListener (socket) {
|
|
67
|
-
socket.onOpen((event) => {
|
|
68
|
-
typeof this._openCb === 'function' && this._openCb(event)
|
|
69
|
-
})
|
|
70
|
-
socket.onMessage((event) => {
|
|
71
|
-
typeof this._messageCb === 'function' && this._messageCb(event)
|
|
72
|
-
})
|
|
73
|
-
socket.onError((event) => {
|
|
74
|
-
typeof this._errorCb === 'function' && this._errorCb(event)
|
|
75
|
-
})
|
|
76
|
-
socket.onClose((event) => {
|
|
77
|
-
if (typeof this._closeCb !== 'function') {
|
|
78
|
-
return
|
|
79
|
-
}
|
|
80
|
-
if (this._closeData) {
|
|
81
|
-
this._closeCb(event)
|
|
82
|
-
} else {
|
|
83
|
-
this._closeCb({ code: 2000, reason: `${event}` })
|
|
84
|
-
}
|
|
85
|
-
})
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
onOpen (cb) {
|
|
89
|
-
this._openCb = cb
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
onMessage (cb) {
|
|
93
|
-
this._messageCb = cb
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
onError (cb) {
|
|
97
|
-
this._errorCb = cb
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
onClose (cb) {
|
|
101
|
-
this._closeCb = cb
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export default SocketTask
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { warn, successHandle, failHandle } from '../../../common/js'
|
|
2
|
-
import SocketTask from './SocketTask'
|
|
3
|
-
|
|
4
|
-
function connectSocket (options = { url: '' }) {
|
|
5
|
-
const { url, protocols, success, fail, complete } = options
|
|
6
|
-
|
|
7
|
-
try {
|
|
8
|
-
const socketTask = new SocketTask(url, protocols)
|
|
9
|
-
successHandle({ errMsg: 'connectSocket:ok' }, success, complete)
|
|
10
|
-
return socketTask
|
|
11
|
-
} catch (e) {
|
|
12
|
-
failHandle({ errMsg: `connectSocket:fail ${e}` }, fail, complete)
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function sendSocketMessage () {
|
|
17
|
-
warn('sendSocketMessage 请使用 socketTask.send')
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function closeSocket () {
|
|
21
|
-
warn('closeSocket 请使用 socketTask.close')
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function onSocketOpen () {
|
|
25
|
-
warn('onSocketOpen 请使用 socketTask.onOpen')
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function onSocketError () {
|
|
29
|
-
warn('onSocketError 请使用 socketTask.onError')
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function onSocketMessage () {
|
|
33
|
-
warn('onSocketMessage 请使用 socketTask.onMessage')
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function onSocketClose () {
|
|
37
|
-
warn('onSocketClose 请使用 socketTask.onClose')
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export {
|
|
41
|
-
connectSocket,
|
|
42
|
-
sendSocketMessage,
|
|
43
|
-
closeSocket,
|
|
44
|
-
onSocketOpen,
|
|
45
|
-
onSocketError,
|
|
46
|
-
onSocketMessage,
|
|
47
|
-
onSocketClose
|
|
48
|
-
}
|