-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpageState.js
89 lines (80 loc) · 1.75 KB
/
pageState.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
const loading = (that) => {
return () => {
that.setData({
pageState: {
state: 'loading',
message: '加载中'
}
})
}
}
const error = (that, message) => {
return (message = '请检查您的网络连接') => {
console.log(message)
that.setData({
pageState: {
state: 'error',
stateMessage: message
}
})
}
}
const network = (that, message) => {
return (message = '请检查您的网络连接') => {
that.setData({
pageState: {
state: 'network',
stateMessage: message
}
})
}
}
const empty = (that, message) => {
return (message = '空空如也') => {
that.setData({
pageState: {
state: 'empty',
stateMessage: message
}
})
}
}
const finish = (that) => {
return () => {
that.setData({
pageState: {
state: 'finish',
stateMessage: ''
}
})
}
}
const fail = (that) => {
return (e) => {
if (e.statusCode === 404) {
error(that)(e.data.message)
} else{
network(that)()
}
}
}
export const reload = (that) => {
const pages = getCurrentPages()
const currentPage = pages[pages.length - 1]
that.onLoad(currentPage.options);
}
export const navigateBack = () => {
wx.navigateBack({
delta: 1
})
}
const pageState = (that) => {
return {
loading: loading(that),
error: error(that),
empty: empty(that),
finish: finish(that),
fail: fail(that)
}
}
export default pageState