@mpxjs/api-proxy 2.8.7 → 2.8.23-alpha
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 +1 -1
- package/src/common/stylus/Modal.tenon.styl +42 -0
- package/src/common/stylus/Toast.tenon.styl +56 -0
- package/src/index.tenon.js +27 -0
- package/src/mini/platform/wxToAli.js +8 -0
- package/src/tenon/api/animation/animation.js +225 -0
- package/src/tenon/api/animation/index.js +89 -0
- package/src/tenon/api/event-channel/index.js +61 -0
- package/src/tenon/api/index.js +29 -0
- package/src/tenon/api/modal/Modal.js +154 -0
- package/src/tenon/api/modal/index.js +12 -0
- package/src/tenon/api/next-tick/index.js +11 -0
- package/src/tenon/api/request/index.js +71 -0
- package/src/tenon/api/route/index.js +102 -0
- package/src/tenon/api/socket/SocketTask.js +105 -0
- package/src/tenon/api/socket/index.js +48 -0
- package/src/tenon/api/storage/index.js +143 -0
- package/src/tenon/api/system/index.js +52 -0
- package/src/tenon/api/toast/Toast.js +101 -0
- package/src/tenon/api/toast/index.js +36 -0
|
@@ -0,0 +1,101 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
}
|