app.js
1.3 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
//app.js
App({
onLaunch: function () {
},
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://192.168.1.112/portal/';//仅为测试地址
//发起网络请求
wx.request({
url: baseurl+url,
data:postData,
method:'POST',
header: { 'content-type': 'application/x-www-form-urlencoded' },
success:function(res){//返回取得的数据
resolve(res);
setTimeout(function(){
wx.hideLoading()
},600)
wx.hideNavigationBarLoading()
},
error:function(e){
reject("网络错误");
wx.hideLoading();
wx.hideNavigationBarLoading();
wx.showModal({
title: '提示',
content: res.data.msg,
showCancel:false
})
}
})
})
wx.hideLoading();
return promise;
},
globalData: {
userInfo: null,
users_id:''
}
})