app.js
1.6 KB
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
//app.js
App({
post(url, data) {
/**
* 自定义post函数,返回Promise
* +-------------------
* @param {String} url 接口网址
* @param {arrayObject} data 要传的数组对象 like: {name: 'name', age: 32}
* +-------------------
* @return {Promise} promise 返回promise供后续操作
*/
wx.showNavigationBarLoading()
wx.showLoading({
title: '加载中',
})
var promise = new Promise((resolve, reject) => {
let that = this;
let postData = data;
// let baseurl = 'http://ewords.w.bronet.cn/portal/';//仅为测试地址
let baseurl = 'https://smallpro.igmat.cn/portal/'
//发起网络请求
wx.request({
url: baseurl + url,
data: postData,
method: 'POST',
header: {
'content-type': 'application/x-www-form-urlencoded'
},
success: function(res) {
//返回取得的数据
if (res.data.code == 1) {
resolve(res);
setTimeout(function() {
wx.hideLoading()
}, 600)
wx.hideNavigationBarLoading()
} else if (res.data.code == '40000') {
wx.showModal({
title: '提示',
content: '登陆超时,请重新登陆',
showCancel: false,
success: function(res) {
if (res.confirm) {
wx.navigateTo({
url: '/pages/star/star',
})
}
}
})
}
},
error: function(e) {
reject("网络错误");
wx.hideLoading();
wx.hideNavigationBarLoading();
wx.showModal({
title: '提示',
content: res.data.msg,
showCancel: false
})
}
})
})
wx.hideLoading();
return promise;
},
globalData: {
userInfo: null,
}
})