app.js
5.9 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
App({
onLaunch: function () {
},
post: function (url, data, headerParams) {
/**
* 自定义post函数,返回Promise
* +-------------------
* @param {String} url 接口网址
* @param {arrayObject} data 要传的数组对象 like: {name: 'name', age: 32}
* +-------------------
* @return {Promise} promise 返回promise供后续操作
*/
// wx.showLoading({
// title: '加载中',
// })
wx.showNavigationBarLoading()
wx.showLoading({
title: '加载中',
})
var promise = new Promise((resolve, reject) => {
//init
let that = this;
let postData = data;
let baseUrl = 'http://anleguo.w.bronet.cn';
// let baseUrl = 'http://192.168.1.15/public';
// postData.signature = that.makeSign(postData);
//网络请求
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.data);
} else if (res.data.code == '40000') {//返回错误提示信息
wx.showToast({
title: res.data.msg,
icon: 'none'
})
} else if (res.data.code == '40001') {//返回错误提示信息
wx.showModal({
title: '提示',
content: '登录已过期请重新登录!',
showCancel: false,
success: function (res) {
if (res.confirm) {
wx.removeStorageSync('token');
wx.navigateTo({
// url: '/pages/startRecord/startRecord',
})
}
}
})
} else if (res.data.code == '40002') {
console.log(res)
// wx.showModal({
// title: '提示',
// // content: res.data.msg,
// showCancel: false,
// success: function (res) { }
// })
} else if (res.data.code == '40003') {
// 初始化用户信息判断
let usetrInfoType = {
hasUserInfo: false
}
resolve(usetrInfoType);
// wx.showModal({
// title: '提示',
// content: res.data.msg,
// showCancel: false
// })
} else {
console.log(res)
// wx.showModal({
// title: '提示',
// // content: res.data.msg,
// showCancel: false
// })
reject(res.data)
}
setTimeout(function () {
wx.hideLoading()
wx.hideNavigationBarLoading()
}, 600)
},
fail: function (e) {
reject('网络出错');
// wx.hideLoading()
wx.hideNavigationBarLoading()
}
})
});
return promise;
},
/**
* 自定义上传文件,返回文件路径
* +-------------------
* @filetype{String} 文件类型.image,video,audio,file
* @filePath String 要传的文件路径
* +-------------------
* @return url 返回文件路径
*/
upload (filetype, file) {
var promise = new Promise((resolve, reject) => {
wx.showNavigationBarLoading()
wx.showLoading({
title: '上传中',
})
let url = 'http://anleguo.w.bronet.cn/portal/common/upload';
let head = {
'XX-Token': wx.getStorageSync('token'),
'XX-Device-Type': ''
}
let typename = {
filetype: filetype
}
wx.uploadFile({
url: url, //仅为示例,非真实的接口地址
filePath: file,
name: 'file',
header: {},
formData: typename,
success: function (res) {
console.log('上传文件后',res)
let temdata = JSON.parse(res.data);
let urlobj = {
url: temdata.data.preview_url
}
resolve(urlobj);
wx.hideNavigationBarLoading();
wx.hideLoading();
},
fail: function (res) {
reject('网络出错');
wx.hideNavigationBarLoading()
wx.hideLoading()
},
complete: () => {
wx.hideNavigationBarLoading()
wx.hideLoading()
},
})
});
return promise;
},
formCollect(id) {
let url = '/sign/formid'
let params = {
formid: id,
openid: wx.getStorageSync('openId')
}
this.post(url, params).then((res) => {
console.log(res)
}).catch((errMsg) => {
})
},
nowDate() {
let date = new Date();
let month = date.getMonth() + 1;
let day = date.getDate();
let dayobj={};
dayobj.newdate = date.getFullYear() + '年' + (month > 9 ? month : ('0' + month)) + '月' + (day > 9 ? day : ('0' + day)) + '日';
dayobj.date = date.getFullYear() + '-' + (month > 9 ? month : ('0' + month)) + '-' + (day > 9 ? day : ('0' + day)) ;
return dayobj
},
initDate(a) {
let date1 = new Date();
let time1 = date1.getFullYear() + "年" + (date1.getMonth() + 1) + "月" + date1.getDate() + '日';
let date2 = new Date(date1);
date2.setDate(date1.getDate() + a);
let time2 = date2.getFullYear() + "年" + (date2.getMonth() + 1) + "月" + date2.getDate() + '日';
return time2;
},
// 数组移除指定元素
arryRemove(arr, item) {
return arr.filter(function (ele) {
return ele != item;
})
},
strTime(strtime) {
let str = 'bronet' + strtime + 'beijing'
return md5(md5(str))
},
//数组变字符串,中间用,隔开
array_to_string(arr){
let str='';
for (let i = 0; i < arr.length;i++){
if (i == (arr.length-1)){
str +=arr[i]
}else{
str += arr[i]+','
}
}
return str;
},
globalData: {
userInfo: null,
baseUrl: 'http://beijing.w.bronet.cn'
}
})