app.js
6.4 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
//app.js
App({
onLaunch: function () {
wx.getSystemInfo({
success: res => {
//导航高度
this.globalData.navHeight = res.statusBarHeight + 46;
}, fail(err) {
console.log(err);
}
})
// 展示本地存储能力
var logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs', logs)
//自动更新版本
const updateManager = wx.getUpdateManager()
updateManager.onCheckForUpdate(function (res) {
// 请求完新版本信息的回调
})
updateManager.onUpdateReady(function () {
wx.showModal({
title: '更新提示',
content: '新版本已经准备好,是否重启应用?',
success: function (res) {
if (res.confirm) {
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
updateManager.applyUpdate()
}
}
})
})
updateManager.onUpdateFailed(function () {
// 新的版本下载失败
wx.showModal({
title: '更新提示',
content: '新版本下载失败',
showCancel: false
})
})
},
post: function (url, data, headerParams, showLoad) {
wx.showNavigationBarLoading()
var promise = new Promise((resolve, reject) => {
//init
let that = this;
let postData = data;
let baseUrl = 'http://grouppay.w.bronet.cn/api/';
//网络请求
let header = {
'content-type': 'application/x-www-form-urlencoded'
}
header = Object.assign(header, headerParams)
//网络请求
wx.request({
url: baseUrl + url,
data: postData,
method: 'POST',
header: header,
success: function (res) { //返回取得的数据
if (res.data.code == '20000') {
resolve(res.data);
} else if (res.data.code == '201') {
resolve(res.data);
}
// else if (res.data.code == '10001') {
// wx.showToast({
// title: res.data.msg,
// icon: 'none',
// duration: 1000,
// success: function (res) {
// let t = setInterval(function () {
// clearInterval(t)
// wx.navigateTo({
// url: '/pages/index/index',
// })
// }, 1000)
// }
// })
// }
else {
// wx.showModal({
// title: '提示',
// content: res.data.msg,
// showCancel: false
// })
reject(res.data)
}
setTimeout(function () {
// if (show||show==undefined){
// wx.hideLoading()
// }
wx.hideNavigationBarLoading()
}, 600)
},
fail: function (e) {
reject('网络出错');
// wx.hideLoading()
wx.hideNavigationBarLoading()
}
})
});
return promise;
},
pay(res, successData) {
wx.requestPayment({
"timeStamp": res.pay.timeStamp,
"nonceStr": res.pay.nonceStr,
"package": res.pay.package,
"signType": "MD5",
"paySign": res.pay.paySign,
"success": function (res) {
wx.showToast({
title: '支付完成',
icon: "success",
duration: 1500,
success: function (data) {
successData(data)
}
})
},
"fail": function (res) {
wx.showToast({
title: '取消支付成功!',
icon: "icon",
duration: 1500,
})
}
})
},
// 上传图片
upload(filetype, file) {
var promise = new Promise((resolve, reject) => {
wx.showNavigationBarLoading()
wx.showLoading({
title: '上传中',
})
let url = 'http://grouppay.w.bronet.cn/api/user/upload/one';
let head = {
'XX-Token': wx.getStorageSync('token'),
'XX-Device-Type': 'wxapp'
}
let typename = {
filetype: filetype
}
wx.uploadFile({
url: url, //仅为示例,非真实的接口地址
filePath: file,
name: 'file',
header: head,
formData: typename,
success: function (res) {
console.log('上传文件后', res)
let temdata = JSON.parse(res.data);
console.log(temdata)
let urlobj = {
url: temdata.data.url
//url: temdata.data.filepath
}
resolve(urlobj);
wx.hideNavigationBarLoading();
wx.hideLoading();
},
fail: function (res) {
reject('网络出错');
wx.hideNavigationBarLoading()
wx.hideLoading()
},
complete: () => {
wx.hideNavigationBarLoading()
wx.hideLoading()
},
})
});
return promise;
},
nowDate() {
let date = new Date();
let month = date.getMonth() + 1;
let day = date.getDate();
return date.getFullYear() + '-' + (month > 9 ? month : ('0' + month)) + '-' + (day > 9 ? day : ('0' + day));
},
minDate() {
let date = new Date();
date.setDate(date.getDate() - 287);
let m = date.getMonth() + 1;
return date.getFullYear() + '-' + m + '-' + date.getDate();
},
timeFormate(timestamp, timeType) {
var timeStamp = timestamp.length == 13 ? timestamp : timestamp * 1000
var date = new Date(timeStamp); //时间戳为10位需*1000,时间戳为13位的话不需乘1000
var Y = date.getFullYear() + '-';
var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
var D = date.getDate() + ' ';
var h = date.getHours() + ':';
var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes());
var s = date.getSeconds();
if (timeType == 'YYMMDD') {
return Y + M + D;
} else {
return h + m;
}
},
//接口管理
interface: {
historyDelete:'/home/index/historyDelete',//删除
shopClass:'/home/index/shopClass',//分类
shopPage:'/home/index/shopPage',//分页
history:'/home/index/history',//检索
index: '/home/index/index', //首页
login: '/wxapp/public/login', //小程序登录注册
getSessionKey: '/wxapp/public/getSessionKey', //获取sessionKey和openid
},
//全局变量
globalData: {
userInfo: null,
cid: null,
class_id: null,
navHeight: 0
}
})