-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
97 lines (96 loc) · 2.33 KB
/
app.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
90
91
92
93
94
95
96
97
//app.js
const regeneratorRuntime = require('./libs/runtime');
const stores = require('./store/stores.js');
let observer = require('./libs/observer.js').observer;
App(observer({
globalData: {
...stores
},
onLaunch: function () {
},
success: function (title, duration) {
title = title || '';
if (typeof title !== 'string') {
title = JSON.stringify(title);
}
wx.showToast({
title: title,
icon: 'success',
image: '', // todo icon
duration: duration || 1500
});
},
info: function (title, duration) {
title = title || '';
if (typeof title !== 'string') {
title = JSON.stringify(title);
}
wx.showToast({
title: title,
icon: 'none',
image: '', // todo icon
duration: duration || 1500
});
},
err: function (title, duration) {
title = title || '';
if (typeof title !== 'string') {
title = JSON.stringify(title);
}
wx.showToast({
title: title,
icon: 'success',
image: '', // todo icon
duration: duration || 1500
});
},
loading: function (title) {
title = title || '';
if (typeof title !== 'string') {
title = JSON.stringify(title);
}
wx.showLoading({
title: title || "请求中",
});
},
hideLoading: function () {
wx.hideLoading();
},
doWithCatch: async (func, showToast = true, onErr) => {
try {
func && await func();
} catch (e) {
console.error(e);
onErr && await onErr();
if (showToast) {
if (typeof e === 'string') {
getApp().err(e);
} else if (typeof e === 'object') {
getApp().err(e.msg || e.message || '未知错误');
}
}
}
},
doWithLoading: async (func, msg, showErrToast = false, onErr, afterSuccess) => {
try {
getApp().loading(msg);
wx.showNavigationBarLoading();
await func();
getApp().hideLoading();
wx.hideNavigationBarLoading();
afterSuccess && await afterSuccess();
} catch (e) {
console.error(e);
getApp().hideLoading();
wx.hideNavigationBarLoading();
if (showErrToast) {
if (typeof e === 'string') {
getApp().err(e);
} else if (typeof e === 'object') {
getApp().err(e.msg || e.message || '未知错误');
}
}
onErr && onErr(e)
}
},
}));