app.js
4.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
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
98
99
100
101
102
103
104
105
106
107
108
//app.js
App({
onLaunch: function () {
},
/**
* 自定义post函数,返回Promise
* +-------------------
* @param {String} url 接口网址
* @param {arrayObject} data 要传的数组对象 like: {name: 'name', age: 32}
* +-------------------
* @return {Promise} promise 返回promise供后续操作
*/
post: function (url, data, headerParams) {
wx.showNavigationBarLoading()
wx.showLoading({
title: '加载中',
})
var promise = new Promise((resolve, reject) => {
let that = this;
let postData = data;
let baseUrl = 'http://saloon.w.bronet.cn/api/';
//网络请求
let header = {
'content-type': 'application/x-www-form-urlencoded'
}
// console.log(baseUrl/ + url)
header = Object.assign(header, headerParams)
wx.request({
url: baseUrl + url,
data: postData,
method: 'POST',
header: header,
success: function (res) {//返回取得的数据
// console.log(res)
if (res.data.code == '20000') {
resolve(res.data);
} else if (res.data.code == '10001') {//用户未
} else if (res.data.code == '40000') {
wx.showModal({
title: '提示',
content: res.data.msg,
showCancel: false,
success: function (res) {
}
})
} else if (res.data.code == '40005') {
wx.showModal({
title: '提示',
content: res.data.msg,
showCancel: false,
success: function (res) {
if (res.confirm) {
wx.reLaunch({
url: '/pages/start/start'
})
} else if (res.cancel) {
console.log('用户点击取消')
}
}
})
} else if (res.data.code == '40006') {
} else {
wx.showModal({
title: '提示',
content: res.data.msg,
showCancel: false,
})
reject(res.data)
}
wx.hideLoading()
wx.hideNavigationBarLoading()
},
fail: function (e) {
console.log(e)
reject('网络出错');
// wx.hideLoading()
wx.hideNavigationBarLoading()
}
})
});
return promise;
},
//根据年月日获取(星期等信息)////later=0 当前 later=1明天 later=2后天
dateLater(later) {
let dateObj = {};
let show_day = new Array('星期天', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六');
let date = new Date();
date.setDate(date.getDate() + later);
let day = date.getDay();
dateObj.year = date.getFullYear();
dateObj.month = ((date.getMonth() + 1) < 10 ? ("0" + (date.getMonth() + 1)) : date.getMonth() + 1);
dateObj.day = (date.getDate() < 10 ? ("0" + date.getDate()) : date.getDate());
dateObj.week = show_day[day];
dateObj.dataday = date.getFullYear() + '-' + ((date.getMonth() + 1) < 10 ? ("0" + (date.getMonth() + 1)) : date.getMonth() + 1) + '-' + (date.getDate() < 10 ? ("0" + date.getDate()) : date.getDate());
dateObj.houser = date.getHours();//当前时间点
console.log(date.getHours())
dateObj.housers = (date.getHours() < 10 ? ("0" + date.getHours()) : date.getHours()) + ':00:00';//当前时间点
dateObj.datadayhouser = date.getFullYear() + '/' + ((date.getMonth() + 1) < 10 ? ("0" + (date.getMonth() + 1)) : date.getMonth() + 1) + '/' + (date.getDate() < 10 ? ("0" + date.getDate()) : date.getDate()) + ' ' + (date.getHours() < 10 ? ("0" + date.getHours()) : date.getHours()) + ':00';//当前时间并时间点
return dateObj;
},
globalData: {
userInfo: null
}
})