@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
package/src/index.tenon.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import * as allApi from './tenon/api'
|
|
2
|
-
import { EventChannel } from './tenon/api/event-channel'
|
|
3
|
-
import { genFromMap } from './common/js'
|
|
4
|
-
|
|
5
|
-
export default function install (target) {
|
|
6
|
-
const fromMap = genFromMap()
|
|
7
|
-
|
|
8
|
-
global.EventChannel = new EventChannel()
|
|
9
|
-
|
|
10
|
-
Object.keys(allApi).forEach(api => {
|
|
11
|
-
target[api] = function (...args) {
|
|
12
|
-
if (args.length > 0) {
|
|
13
|
-
const from = args.pop()
|
|
14
|
-
if (typeof from !== 'string' || !fromMap[from]) {
|
|
15
|
-
args.push(from)
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return allApi[api].apply(target, args)
|
|
20
|
-
}
|
|
21
|
-
})
|
|
22
|
-
}
|
|
23
|
-
export function getProxy () {
|
|
24
|
-
const apiProxy = {}
|
|
25
|
-
install(apiProxy)
|
|
26
|
-
return apiProxy
|
|
27
|
-
}
|
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
import { warn } from '../../../common/js'
|
|
2
|
-
class Animation {
|
|
3
|
-
constructor (options) {
|
|
4
|
-
this._actions = []
|
|
5
|
-
this._propMaps = {}
|
|
6
|
-
this._options = options
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
// 处理size
|
|
10
|
-
_processSize (size) {
|
|
11
|
-
if (typeof size === 'number') {
|
|
12
|
-
return `${size}hm`
|
|
13
|
-
} else {
|
|
14
|
-
return size
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
_collectData (type, value) {
|
|
19
|
-
this._propMaps[type] = {
|
|
20
|
-
type: type,
|
|
21
|
-
value: value
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// 不支持
|
|
26
|
-
right (value) {
|
|
27
|
-
warn('不支持right方法')
|
|
28
|
-
return this
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// 不支持
|
|
32
|
-
left (value) {
|
|
33
|
-
warn('不支持left方法')
|
|
34
|
-
return this
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// 不支持
|
|
38
|
-
top (value) {
|
|
39
|
-
warn('不支持top方法')
|
|
40
|
-
return this
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// 不支持
|
|
44
|
-
bottom (value) {
|
|
45
|
-
warn('不支持bottom方法')
|
|
46
|
-
return this
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
width (value) {
|
|
50
|
-
this._collectData('width', value)
|
|
51
|
-
return this
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
height (value) {
|
|
55
|
-
this._collectData('height', value)
|
|
56
|
-
return this
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
opacity (value) {
|
|
60
|
-
this._collectData('opacity', parseFloat(value))
|
|
61
|
-
return this
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
backgroundColor (color) {
|
|
65
|
-
this._collectData('backgroundColor', color)
|
|
66
|
-
return this
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// 不支持
|
|
70
|
-
matrix (...value) {
|
|
71
|
-
warn('不支持matrix方法')
|
|
72
|
-
return this
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// 不支持
|
|
76
|
-
matrix3d (...value) {
|
|
77
|
-
warn('不支持matrix3d方法')
|
|
78
|
-
return this
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// 不支持
|
|
82
|
-
rotate (...value) {
|
|
83
|
-
warn('不支持rotate方法')
|
|
84
|
-
return this
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// 不支持
|
|
88
|
-
rotate3d (...value) {
|
|
89
|
-
warn('不支持rotate3d方法')
|
|
90
|
-
return this
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
rotateX (value) {
|
|
94
|
-
this._collectData('rotationX', `${parseFloat(value)}deg`)
|
|
95
|
-
return this
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
rotateY (value) {
|
|
99
|
-
this._collectData('rotationY', `${parseFloat(value)}deg`)
|
|
100
|
-
return this
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
rotateZ (value) {
|
|
104
|
-
this._collectData('rotationZ', `${parseFloat(value)}deg`)
|
|
105
|
-
return this
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
scale (...value) {
|
|
109
|
-
const [x, y = x] = value
|
|
110
|
-
this._collectData('scaleX', x)
|
|
111
|
-
this._collectData('scaleY', y)
|
|
112
|
-
return this
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// 不支持
|
|
116
|
-
scale3d (...value) {
|
|
117
|
-
warn('不支持scale3d方法')
|
|
118
|
-
return this
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
scaleX (value) {
|
|
122
|
-
this._collectData('scaleX', value)
|
|
123
|
-
return this
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
scaleY (value) {
|
|
127
|
-
this._collectData('scaleY', value)
|
|
128
|
-
return this
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// 不支持
|
|
132
|
-
scaleZ (value) {
|
|
133
|
-
warn('不支持scaleZ方法')
|
|
134
|
-
return this
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// 不支持
|
|
138
|
-
skew (...value) {
|
|
139
|
-
warn('不支持skew方法')
|
|
140
|
-
return this
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// 不支持
|
|
144
|
-
skewX (value) {
|
|
145
|
-
warn('不支持skewX方法')
|
|
146
|
-
return this
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// 不支持
|
|
150
|
-
skewY (value) {
|
|
151
|
-
warn('不支持skewY方法')
|
|
152
|
-
return this
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
translate (...value) {
|
|
156
|
-
const [x = 0, y = 0] = value
|
|
157
|
-
this._collectData('position', {
|
|
158
|
-
x: `${parseFloat(x)}hm`,
|
|
159
|
-
y: `${parseFloat(y)}hm`
|
|
160
|
-
})
|
|
161
|
-
return this
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// 不支持
|
|
165
|
-
translate3d (...value) {
|
|
166
|
-
warn('不支持translate3d方法')
|
|
167
|
-
return this
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
translateX (value) {
|
|
171
|
-
this._collectData('position', { x: `${parseFloat(value)}hm`, y: 0 })
|
|
172
|
-
return this
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
translateY (value) {
|
|
176
|
-
this._collectData('position', { x: `${parseFloat(value)}hm`, y: 0 })
|
|
177
|
-
return this
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
// 不支持
|
|
181
|
-
translateZ (value) {
|
|
182
|
-
warn('不支持tranlateZ方法')
|
|
183
|
-
return this
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
step (opt) {
|
|
187
|
-
const option = {}
|
|
188
|
-
const animates = []
|
|
189
|
-
if (opt) {
|
|
190
|
-
Object.assign(option, this._options, opt)
|
|
191
|
-
} else {
|
|
192
|
-
Object.assign(option, this._options)
|
|
193
|
-
}
|
|
194
|
-
Object.keys(this._propMaps).forEach((item) => {
|
|
195
|
-
animates.push(this._propMaps[item])
|
|
196
|
-
})
|
|
197
|
-
// action
|
|
198
|
-
this._actions.push({
|
|
199
|
-
animates,
|
|
200
|
-
option
|
|
201
|
-
})
|
|
202
|
-
return this
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
export () {
|
|
206
|
-
const actions = this._actions.slice(0)
|
|
207
|
-
this._actions.length = 0
|
|
208
|
-
// 一个action就是一个step
|
|
209
|
-
const steps = actions.map((v) => {
|
|
210
|
-
const styles = {}
|
|
211
|
-
v.animates.forEach(animate => {
|
|
212
|
-
styles[animate.type] = animate.value
|
|
213
|
-
})
|
|
214
|
-
return {
|
|
215
|
-
...v.option,
|
|
216
|
-
styles
|
|
217
|
-
}
|
|
218
|
-
})
|
|
219
|
-
return {
|
|
220
|
-
steps
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
export default Animation
|
|
@@ -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,61 +0,0 @@
|
|
|
1
|
-
class EventChannel {
|
|
2
|
-
constructor () {
|
|
3
|
-
this.listener = {}
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
emit (eventName, ...args) {
|
|
7
|
-
const cbs = this.listener[eventName]
|
|
8
|
-
if (cbs) {
|
|
9
|
-
cbs.forEach((item, index) => {
|
|
10
|
-
try {
|
|
11
|
-
item.fn.apply(this, args)
|
|
12
|
-
} catch (e) {
|
|
13
|
-
console.log(`event "${eventName}" error ${e}`)
|
|
14
|
-
}
|
|
15
|
-
if (item.type === 'once') {
|
|
16
|
-
cbs.splice(index, 1)
|
|
17
|
-
}
|
|
18
|
-
})
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
off (eventName, EventCallback) {
|
|
23
|
-
if (EventCallback) {
|
|
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
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
on (eventName, EventCallback) {
|
|
40
|
-
(this.listener[eventName] || (this.listener[eventName] = [])).push({ fn: EventCallback, type: 'on' })
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
once (eventName, EventCallback) {
|
|
44
|
-
(this.listener[eventName] || (this.listener[eventName] = [])).push({ fn: EventCallback, type: 'once' })
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
_addListener (eventName, EventCallback, type) {
|
|
48
|
-
(this.listener[eventName] || (this.listener[eventName] = [])).push({ fn: EventCallback, type })
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
_addListeners (events) {
|
|
52
|
-
if (Object.prototype.toString.call(events) === '[object Object]') {
|
|
53
|
-
Object.keys(events).forEach((eventName) => {
|
|
54
|
-
(this.listener[eventName] || (this.listener[eventName] = [])).push({ fn: events[eventName], type: 'on' })
|
|
55
|
-
})
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
export {
|
|
60
|
-
EventChannel
|
|
61
|
-
}
|
package/src/tenon/api/index.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
// showToast, hideToast, showLoading, hideLoading
|
|
2
|
-
export * from './toast'
|
|
3
|
-
|
|
4
|
-
// showModal
|
|
5
|
-
export * from './modal'
|
|
6
|
-
|
|
7
|
-
// setStorage, setStorageSync, getStorage, getStorageSync
|
|
8
|
-
// getStorageInfo, getStorageInfoSync, removeStorage, removeStorageSync
|
|
9
|
-
// clearStorage, clearStorageSync
|
|
10
|
-
export * from './storage'
|
|
11
|
-
|
|
12
|
-
// getSystemInfo, getSystemInfoSync
|
|
13
|
-
export * from './system'
|
|
14
|
-
|
|
15
|
-
// request
|
|
16
|
-
export * from './request'
|
|
17
|
-
|
|
18
|
-
// redirectTo, navigateTo, navigateBack, reLaunch, switchTab
|
|
19
|
-
export * from './route'
|
|
20
|
-
|
|
21
|
-
// connectSocket, sendSocketMessage, closeSocket
|
|
22
|
-
// onSocketOpen, onSocketError, onSocketMessage, onSocketClose
|
|
23
|
-
export * from './socket'
|
|
24
|
-
|
|
25
|
-
// nextTick
|
|
26
|
-
export * from './next-tick'
|
|
27
|
-
|
|
28
|
-
// createAnimation
|
|
29
|
-
export * from './animation'
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import { ToPromise, webHandleSuccess } 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
|
-
webHandleSuccess(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
|
-
webHandleSuccess(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,71 +0,0 @@
|
|
|
1
|
-
import { webHandleSuccess, webHandleFail } from '../../../common/js'
|
|
2
|
-
const { Request } = __GLOBAL__
|
|
3
|
-
|
|
4
|
-
function request (options = { url: '' }) {
|
|
5
|
-
let {
|
|
6
|
-
data = {},
|
|
7
|
-
method = 'GET',
|
|
8
|
-
dataType = 'json',
|
|
9
|
-
responseType = 'text',
|
|
10
|
-
timeout = 60 * 1000,
|
|
11
|
-
header = {},
|
|
12
|
-
success = null,
|
|
13
|
-
fail = null,
|
|
14
|
-
complete = null
|
|
15
|
-
} = options
|
|
16
|
-
|
|
17
|
-
method = method.toUpperCase()
|
|
18
|
-
|
|
19
|
-
if (
|
|
20
|
-
method === 'POST' &&
|
|
21
|
-
typeof data !== 'string' && // string 不做处理
|
|
22
|
-
(header['Content-Type'] === 'application/x-www-form-urlencoded' ||
|
|
23
|
-
header['content-type'] === 'application/x-www-form-urlencoded')
|
|
24
|
-
) {
|
|
25
|
-
// 重新设置data
|
|
26
|
-
data = Object.keys(data)
|
|
27
|
-
.reduce((pre, curKey) => {
|
|
28
|
-
return `${pre}&${encodeURIComponent(curKey)}=${encodeURIComponent(
|
|
29
|
-
data[curKey]
|
|
30
|
-
)}`
|
|
31
|
-
}, '')
|
|
32
|
-
.slice(1)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const requestFn = new Request()
|
|
36
|
-
|
|
37
|
-
requestFn.url = options.url
|
|
38
|
-
requestFn.method = method
|
|
39
|
-
requestFn.timeout = timeout
|
|
40
|
-
requestFn.header = header
|
|
41
|
-
requestFn.params = data
|
|
42
|
-
requestFn.send((response) => {
|
|
43
|
-
let { status, header: resHeader, data: resData, error } = response
|
|
44
|
-
// 返回的数据处理
|
|
45
|
-
|
|
46
|
-
if (responseType === 'text' && dataType === 'json') {
|
|
47
|
-
try {
|
|
48
|
-
resData = JSON.parse(resData)
|
|
49
|
-
} catch (e) {}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (status >= 200 && status < 300) {
|
|
53
|
-
const result = {
|
|
54
|
-
errMsg: 'request:ok',
|
|
55
|
-
data: resData,
|
|
56
|
-
statusCode: status,
|
|
57
|
-
header: resHeader
|
|
58
|
-
}
|
|
59
|
-
webHandleSuccess(result, success, complete)
|
|
60
|
-
return result
|
|
61
|
-
} else {
|
|
62
|
-
const res = { errMsg: `request:fail ${error.msg}` }
|
|
63
|
-
webHandleFail(res, fail, complete)
|
|
64
|
-
if (!fail) {
|
|
65
|
-
return Promise.reject(res)
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
})
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export { request }
|