@mpxjs/api-proxy 2.8.23-alpha → 2.9.0-beta.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 +2 -2
- package/src/common/js/utils.js +6 -2
- package/src/index.web.js +0 -3
- package/src/web/api/action-sheet/index.js +5 -0
- package/src/web/api/animation/animation.js +8 -2
- package/src/web/api/app/index.js +10 -3
- package/src/web/api/audio/index.js +5 -0
- package/src/web/api/create-intersection-observer/index.js +5 -0
- package/src/web/api/create-selector-query/index.js +5 -0
- package/src/web/api/device/network/getNetworkType.js +6 -2
- package/src/web/api/device/network/onNetworkStatusChange.js +9 -1
- package/src/web/api/modal/index.js +5 -0
- package/src/web/api/page-scroll-to/index.js +5 -1
- package/src/web/api/pull-down/index.js +9 -1
- package/src/web/api/route/index.js +21 -2
- package/src/web/api/set-navigation-bar/index.js +9 -1
- package/src/web/api/socket/index.js +5 -1
- package/src/web/api/storage/index.js +41 -1
- package/src/web/api/system/index.js +9 -1
- package/src/web/api/toast/index.js +9 -0
- package/src/web/api/video/index.js +6 -0
- 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/tenon/api/animation/animation.js +0 -225
- package/src/tenon/api/animation/index.js +0 -89
- package/src/tenon/api/event-channel/index.js +0 -61
- package/src/tenon/api/index.js +0 -29
- package/src/tenon/api/modal/Modal.js +0 -154
- package/src/tenon/api/modal/index.js +0 -12
- package/src/tenon/api/next-tick/index.js +0 -11
- package/src/tenon/api/request/index.js +0 -71
- package/src/tenon/api/route/index.js +0 -102
- package/src/tenon/api/socket/SocketTask.js +0 -105
- package/src/tenon/api/socket/index.js +0 -48
- package/src/tenon/api/storage/index.js +0 -143
- package/src/tenon/api/system/index.js +0 -52
- package/src/tenon/api/toast/Toast.js +0 -101
- package/src/tenon/api/toast/index.js +0 -36
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { webHandleSuccess } from '../../../common/js'
|
|
2
|
-
import { EventChannel } from '../event-channel'
|
|
3
|
-
const { Navigator } = __GLOBAL__
|
|
4
|
-
|
|
5
|
-
function redirectTo (options = {}) {
|
|
6
|
-
if (Navigator) {
|
|
7
|
-
Navigator.__mpxAction = { type: 'redirect' }
|
|
8
|
-
return new Promise((resolve, reject) => {
|
|
9
|
-
// 关闭本页面的跳转
|
|
10
|
-
Navigator.openPage(
|
|
11
|
-
{
|
|
12
|
-
url: options.url,
|
|
13
|
-
closeSelf: true
|
|
14
|
-
},
|
|
15
|
-
// 执行环境变了 得不到执行的机会 故回调无效
|
|
16
|
-
() => {}
|
|
17
|
-
)
|
|
18
|
-
const res = { errMsg: 'redirectTo:ok' }
|
|
19
|
-
webHandleSuccess(res, options.success, options.complete)
|
|
20
|
-
resolve(res)
|
|
21
|
-
})
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function navigateTo (options = {}) {
|
|
26
|
-
if (Navigator) {
|
|
27
|
-
const eventChannel = new EventChannel()
|
|
28
|
-
Navigator.__mpxAction = {
|
|
29
|
-
type: 'to',
|
|
30
|
-
eventChannel
|
|
31
|
-
}
|
|
32
|
-
if (options.events) {
|
|
33
|
-
eventChannel._addListeners(options.events)
|
|
34
|
-
}
|
|
35
|
-
return new Promise((resolve, reject) => {
|
|
36
|
-
// 不关闭本页面的跳转
|
|
37
|
-
Navigator.openPage(
|
|
38
|
-
{
|
|
39
|
-
url: options.url
|
|
40
|
-
},
|
|
41
|
-
// 执行环境变了 得不到执行的机会 故回调无效
|
|
42
|
-
() => {}
|
|
43
|
-
)
|
|
44
|
-
const res = { errMsg: 'redirectTo:ok' }
|
|
45
|
-
webHandleSuccess(res, options.success, options.complete)
|
|
46
|
-
resolve(res)
|
|
47
|
-
})
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function navigateBack (options = {}) {
|
|
52
|
-
if (Navigator) {
|
|
53
|
-
const delta = options.delta || 1
|
|
54
|
-
Navigator.__mpxAction = {
|
|
55
|
-
type: 'back',
|
|
56
|
-
delta
|
|
57
|
-
}
|
|
58
|
-
// popBack方法
|
|
59
|
-
Navigator.popBack(delta, { animated: true })
|
|
60
|
-
const res = { errMsg: 'navigateBack:ok' }
|
|
61
|
-
webHandleSuccess(res, options.success, options.complete)
|
|
62
|
-
return Promise.resolve(res)
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function reLaunch (options = {}) {
|
|
67
|
-
if (Navigator) {
|
|
68
|
-
Navigator.__mpxAction = {
|
|
69
|
-
type: 'reLaunch'
|
|
70
|
-
}
|
|
71
|
-
Navigator.popToRootPage()
|
|
72
|
-
|
|
73
|
-
const res = { errMsg: 'reLaunch:ok' }
|
|
74
|
-
webHandleSuccess(res, options.success, options.complete)
|
|
75
|
-
return Promise.resolve(res)
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function switchTab (options = {}) {
|
|
80
|
-
if (Navigator) {
|
|
81
|
-
Navigator.__mpxAction = {
|
|
82
|
-
type: 'switch',
|
|
83
|
-
path: options.url,
|
|
84
|
-
replaced: true
|
|
85
|
-
}
|
|
86
|
-
return new Promise((resolve, reject) => {
|
|
87
|
-
Navigator.openPage(
|
|
88
|
-
{
|
|
89
|
-
url: options.url,
|
|
90
|
-
closeSelf: true
|
|
91
|
-
},
|
|
92
|
-
// 执行环境变了 得不到执行的机会 故回调无效
|
|
93
|
-
() => {}
|
|
94
|
-
)
|
|
95
|
-
const res = { errMsg: 'redirectTo:ok' }
|
|
96
|
-
webHandleSuccess(res, options.success, options.complete)
|
|
97
|
-
resolve(res)
|
|
98
|
-
})
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export { redirectTo, navigateTo, navigateBack, reLaunch, switchTab }
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { webHandleSuccess, webHandleFail, 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
|
-
webHandleSuccess(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
|
-
webHandleSuccess(res, success, complete)
|
|
56
|
-
return Promise.resolve(res)
|
|
57
|
-
} catch (err) {
|
|
58
|
-
const res = { errMsg: `closeSocket:fail ${err}` }
|
|
59
|
-
webHandleFail(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, webHandleSuccess, webHandleFail } 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
|
-
webHandleSuccess({ errMsg: 'connectSocket:ok' }, success, complete)
|
|
10
|
-
return socketTask
|
|
11
|
-
} catch (e) {
|
|
12
|
-
webHandleFail({ 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
|
-
}
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import { webHandleSuccess, webHandleFail, warn, hasOwn } from '../../../common/js'
|
|
2
|
-
const { Storage } = __GLOBAL__
|
|
3
|
-
|
|
4
|
-
function setStorage (options = {}) {
|
|
5
|
-
const { key, data, success, fail, complete } = options
|
|
6
|
-
|
|
7
|
-
try {
|
|
8
|
-
setStorageSync(key, data)
|
|
9
|
-
|
|
10
|
-
const res = { errMsg: 'setStorage:ok' }
|
|
11
|
-
webHandleSuccess(res, success, complete)
|
|
12
|
-
return Promise.resolve(res)
|
|
13
|
-
} catch (err) {
|
|
14
|
-
const res = { errMsg: `setStorage:fail ${err}` }
|
|
15
|
-
webHandleFail(res, fail, complete)
|
|
16
|
-
return Promise.reject(res)
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function setStorageSync (key = '', data) {
|
|
21
|
-
let obj = {}
|
|
22
|
-
|
|
23
|
-
if (typeof data === 'symbol') {
|
|
24
|
-
obj = { data: '' }
|
|
25
|
-
} else {
|
|
26
|
-
obj = { data }
|
|
27
|
-
}
|
|
28
|
-
Storage.set(key, JSON.stringify(obj))
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function getStorage (options = {}) {
|
|
32
|
-
const { key, success, fail, complete } = options
|
|
33
|
-
const { result, data } = getItem(key)
|
|
34
|
-
|
|
35
|
-
if (result) {
|
|
36
|
-
const res = { errMsg: 'getStorage:ok', data: data }
|
|
37
|
-
webHandleSuccess(res, success, complete)
|
|
38
|
-
return Promise.resolve(res)
|
|
39
|
-
} else {
|
|
40
|
-
const res = { errMsg: 'getStorage:fail', data: null }
|
|
41
|
-
webHandleFail(res, fail, complete)
|
|
42
|
-
return Promise.reject(res)
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function getStorageSync (key) {
|
|
47
|
-
const res = getItem(key)
|
|
48
|
-
if (res.result) return res.data
|
|
49
|
-
|
|
50
|
-
return ''
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function getItem (key) {
|
|
54
|
-
let item
|
|
55
|
-
try {
|
|
56
|
-
item = JSON.parse(Storage.get(key))
|
|
57
|
-
} catch (e) {}
|
|
58
|
-
|
|
59
|
-
if (item && typeof item === 'object' && hasOwn(item, 'data')) {
|
|
60
|
-
return { result: true, data: item.data }
|
|
61
|
-
} else {
|
|
62
|
-
return { result: false }
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function getStorageInfo (options = {}) {
|
|
67
|
-
const { success, fail, complete } = options
|
|
68
|
-
|
|
69
|
-
try {
|
|
70
|
-
const info = getStorageInfoSync()
|
|
71
|
-
|
|
72
|
-
const res = Object.assign({}, { errMsg: 'getStorageInfo:ok' }, info)
|
|
73
|
-
webHandleSuccess(res, success, complete)
|
|
74
|
-
return Promise.resolve(res)
|
|
75
|
-
} catch (err) {
|
|
76
|
-
const res = { errMsg: `getStorageInfo:fail ${err}` }
|
|
77
|
-
webHandleFail(res, fail, complete)
|
|
78
|
-
return Promise.reject(res)
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function getStorageInfoSync () {
|
|
83
|
-
return {
|
|
84
|
-
keys: Object.keys(Storage),
|
|
85
|
-
limitSize: null,
|
|
86
|
-
currentSize: null
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function removeStorage (options = { key: '' }) {
|
|
91
|
-
const { key, success, fail, complete } = options
|
|
92
|
-
|
|
93
|
-
try {
|
|
94
|
-
removeStorageSync(key)
|
|
95
|
-
|
|
96
|
-
const res = { errMsg: 'removeStorage:ok' }
|
|
97
|
-
webHandleSuccess(res, success, complete)
|
|
98
|
-
return Promise.resolve(res)
|
|
99
|
-
} catch (err) {
|
|
100
|
-
const res = { errMsg: `removeStorage:fail ${err}` }
|
|
101
|
-
webHandleFail(res, fail, complete)
|
|
102
|
-
return Promise.reject(res)
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function removeStorageSync (key) {
|
|
107
|
-
Storage.remove(key)
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function clearStorage (options = {}) {
|
|
111
|
-
warn('不支持clearStorageSync')
|
|
112
|
-
// const { success, fail, complete } = options
|
|
113
|
-
|
|
114
|
-
// try {
|
|
115
|
-
// clearStorageSync()
|
|
116
|
-
|
|
117
|
-
// const res = { errMsg: 'clearStorage:ok' }
|
|
118
|
-
// webHandleSuccess(res, success, complete)
|
|
119
|
-
// return Promise.resolve(res)
|
|
120
|
-
// } catch (err) {
|
|
121
|
-
// const res = { errMsg: `clearStorage:fail ${err}` }
|
|
122
|
-
// webHandleFail(res, fail, complete)
|
|
123
|
-
// return Promise.reject(res)
|
|
124
|
-
// }
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function clearStorageSync () {
|
|
128
|
-
// Storage.clear()
|
|
129
|
-
warn('不支持clearStorageSync')
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
export {
|
|
133
|
-
setStorage,
|
|
134
|
-
setStorageSync,
|
|
135
|
-
getStorage,
|
|
136
|
-
getStorageSync,
|
|
137
|
-
getStorageInfo,
|
|
138
|
-
getStorageInfoSync,
|
|
139
|
-
removeStorage,
|
|
140
|
-
removeStorageSync,
|
|
141
|
-
clearStorage,
|
|
142
|
-
clearStorageSync
|
|
143
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { webHandleSuccess } from '../../../common/js'
|
|
2
|
-
const { Hummer } = __GLOBAL__
|
|
3
|
-
|
|
4
|
-
function getSystemInfoSync () {
|
|
5
|
-
const {
|
|
6
|
-
platform,
|
|
7
|
-
osVersion,
|
|
8
|
-
deviceWidth,
|
|
9
|
-
deviceHeight,
|
|
10
|
-
availableWidth,
|
|
11
|
-
availableHeight,
|
|
12
|
-
safeAreaBottom
|
|
13
|
-
} = Hummer.env || {}
|
|
14
|
-
return {
|
|
15
|
-
brand: platform,
|
|
16
|
-
model: platform,
|
|
17
|
-
pixelRatio: null,
|
|
18
|
-
screenWidth: deviceWidth,
|
|
19
|
-
screenHeight: deviceHeight,
|
|
20
|
-
windowWidth: availableWidth,
|
|
21
|
-
windowHeight: availableHeight,
|
|
22
|
-
statusBarHeight: null,
|
|
23
|
-
language: null,
|
|
24
|
-
version: null,
|
|
25
|
-
system: platform + osVersion,
|
|
26
|
-
platform: platform,
|
|
27
|
-
fontSizeSetting: null,
|
|
28
|
-
SDKVersion: null,
|
|
29
|
-
benchmarkLevel: null,
|
|
30
|
-
albumAuthorized: null,
|
|
31
|
-
cameraAuthorized: null,
|
|
32
|
-
locationAuthorized: null,
|
|
33
|
-
microphoneAuthorized: null,
|
|
34
|
-
notificationAlertAuthorized: null,
|
|
35
|
-
notificationAuthorized: null,
|
|
36
|
-
notificationBadgeAuthorized: null,
|
|
37
|
-
notificationSoundAuthorized: null,
|
|
38
|
-
bluetoothEnabled: null,
|
|
39
|
-
locationEnabled: null,
|
|
40
|
-
wifiEnabled: null,
|
|
41
|
-
safeArea: safeAreaBottom
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function getSystemInfo (options = {}) {
|
|
46
|
-
const info = getSystemInfoSync()
|
|
47
|
-
const res = Object.assign({ errMsg: 'getSystemInfo:ok' }, info)
|
|
48
|
-
webHandleSuccess(res, options.success, options.complete)
|
|
49
|
-
return Promise.resolve(res)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export { getSystemInfo, getSystemInfoSync }
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { webHandleSuccess } from '../../../common/js'
|
|
2
|
-
import '../../../common/stylus/Toast.styl'
|
|
3
|
-
|
|
4
|
-
import { getClassStyle } from '@hummer/tenon-vue'
|
|
5
|
-
|
|
6
|
-
function createDom (Element, attrs = {}, children = []) {
|
|
7
|
-
const dom = new Element()
|
|
8
|
-
Object.keys(attrs).forEach(k => Reflect.set(dom, k, attrs[k]))
|
|
9
|
-
children.length && children.forEach(child => dom.appendChild(child))
|
|
10
|
-
return dom
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export default class Toast {
|
|
14
|
-
constructor () {
|
|
15
|
-
this.defaultOpts = {
|
|
16
|
-
title: '',
|
|
17
|
-
icon: 'success',
|
|
18
|
-
image: '',
|
|
19
|
-
duration: 1500,
|
|
20
|
-
mask: false,
|
|
21
|
-
success: () => {},
|
|
22
|
-
fail: () => {},
|
|
23
|
-
complete: () => {}
|
|
24
|
-
}
|
|
25
|
-
this.dialog = null
|
|
26
|
-
this.hideTimer = null
|
|
27
|
-
this.type = null
|
|
28
|
-
|
|
29
|
-
// create & combine toast
|
|
30
|
-
this.toast = createDom(View, { style: getClassStyle(null, '__mpx_toast__') }, [
|
|
31
|
-
// todo 暂不支持 mask隐藏
|
|
32
|
-
// this.mask = createDom(View, { style: getClassStyle(null, '__mpx_mask__') }),
|
|
33
|
-
this.content = createDom(View, { style: getClassStyle(null, '__mpx_toast_box__') }, [
|
|
34
|
-
this.icon = createDom(View, { style: getClassStyle(null, '__mpx_toast_icon__') }),
|
|
35
|
-
this.title = createDom(Text, { style: getClassStyle(null, '__mpx_toast_title__') })
|
|
36
|
-
])
|
|
37
|
-
])
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
show (options, type) {
|
|
41
|
-
if (this.hideTimer) {
|
|
42
|
-
clearTimeout(this.hideTimer)
|
|
43
|
-
this.hideTimer = null
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const opts = Object.assign({}, this.defaultOpts, options)
|
|
47
|
-
|
|
48
|
-
this.type = type
|
|
49
|
-
|
|
50
|
-
// if (opts.mask) {
|
|
51
|
-
// this.mask.class += 'show'
|
|
52
|
-
// } else {
|
|
53
|
-
// this.mask.classList.remove('show')
|
|
54
|
-
// }
|
|
55
|
-
|
|
56
|
-
// const defaultIconClass = '__mpx_toast_icon__'
|
|
57
|
-
|
|
58
|
-
const iconClass = opts.image
|
|
59
|
-
? '' // image
|
|
60
|
-
: opts.icon === 'none'
|
|
61
|
-
? '__hide_icon' // none
|
|
62
|
-
: opts.icon === 'error'
|
|
63
|
-
? '__error_icon'
|
|
64
|
-
: '__success_icon' // default
|
|
65
|
-
|
|
66
|
-
// 在Hummer环境,Object.assign 有一些问题,需要重新进行一次赋值
|
|
67
|
-
this.icon.style = Object.assign(this.icon.style, getClassStyle(null, `${iconClass}`))
|
|
68
|
-
|
|
69
|
-
opts.image && (this.icon.style = Object.assign(this.icon.style, { backgroundImage: opts.image }))
|
|
70
|
-
|
|
71
|
-
this.title.text = opts.title || ''
|
|
72
|
-
|
|
73
|
-
this.dialog = new Dialog()
|
|
74
|
-
this.dialog.cancelable = false
|
|
75
|
-
opts.icon === 'loading'
|
|
76
|
-
? this.dialog.loading(opts.title || 'loading...') // 空字符串也被过滤
|
|
77
|
-
: this.dialog.custom(this.toast)
|
|
78
|
-
|
|
79
|
-
opts.duration >= 0 && this.hide({ duration: opts.duration }, type)
|
|
80
|
-
|
|
81
|
-
const errMsg = type === 'loading' ? 'showLoading:ok' : 'showToast:ok'
|
|
82
|
-
webHandleSuccess({ errMsg }, opts.success, opts.complete)
|
|
83
|
-
return Promise.resolve({ errMsg })
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
hide (options = {}, type) {
|
|
87
|
-
if (this.type !== type) return
|
|
88
|
-
|
|
89
|
-
const duration = options.duration || 0
|
|
90
|
-
const errMsg = type === 'loading' ? 'hideLoading:ok' : 'hideToast:ok'
|
|
91
|
-
webHandleSuccess({ errMsg }, options.success, options.complete)
|
|
92
|
-
|
|
93
|
-
if (this.hideTimer) {
|
|
94
|
-
clearTimeout(this.hideTimer)
|
|
95
|
-
this.hideTimer = null
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
this.hideTimer = setTimeout(() => { this.dialog.dismiss() }, duration)
|
|
99
|
-
return Promise.resolve({ errMsg })
|
|
100
|
-
}
|
|
101
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import Toast from './Toast'
|
|
2
|
-
|
|
3
|
-
let toast = null
|
|
4
|
-
|
|
5
|
-
function showToast (options = { title: '' }) {
|
|
6
|
-
if (!toast) { toast = new Toast() }
|
|
7
|
-
return toast.show(options, 'toast')
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
function hideToast (options = {}) {
|
|
11
|
-
if (!toast) { return }
|
|
12
|
-
return toast.hide(Object.assign({ duration: 0 }, options), 'toast')
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function showLoading (options = { title: '' }) {
|
|
16
|
-
if (!toast) { toast = new Toast() }
|
|
17
|
-
return toast.show(Object.assign({
|
|
18
|
-
icon: 'loading',
|
|
19
|
-
duration: -1
|
|
20
|
-
}, options), 'loading')
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function hideLoading (options = {}) {
|
|
24
|
-
if (!toast) { return }
|
|
25
|
-
return toast.hide(Object.assign({
|
|
26
|
-
icon: 'loading',
|
|
27
|
-
duration: 0
|
|
28
|
-
}, options), 'loading')
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export {
|
|
32
|
-
showToast,
|
|
33
|
-
hideToast,
|
|
34
|
-
showLoading,
|
|
35
|
-
hideLoading
|
|
36
|
-
}
|