app.js
5.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
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
//app.js
App({
onLaunch: function () {
// 展示本地存储能力
// var logs = wx.getStorageSync('logs') || []
// logs.unshift(Date.now())
// wx.setStorageSync('logs', logs)
// 登录
// wx.login({
// success: res => {
// // 发送 res.code 到后台换取 openId, sessionKey, unionId
// }
// })
// 获取用户信息
// wx.getSetting({
// success: res => {
// if (res.authSetting['scope.userInfo']) {
// // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
// wx.getUserInfo({
// success: res => {
// // 可以将 res 发送给后台解码出 unionId
// this.globalData.userInfo = res.userInfo
// // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// // 所以此处加入 callback 以防止这种情况
// if (this.userInfoReadyCallback) {
// this.userInfoReadyCallback(res)
// }
// }
// })
// }
// }
// })
},
ajax(url, params, successData, errorData, completeData) {
var https = "https://shipin.wx.broteam.cn/index.php/"
wx.request({
url: https + url,
method: "POST",
header: {
'content-type': 'application/x-www-form-urlencoded',
},
data: params,
success: (res) => {
successData(res)
},
error(res) {
errorData(res)
}
})
},
// 多张图片上传
uploadImg: function (data) {
var that = this,
i = data.i ? data.i : 0,
success = data.success ? data.success : 0,
fail = data.fail ? data.fail : 0
wx.uploadFile({
url: data.url,
filePath: data.path[i],
name: 'fileData', // 这里根据自己的实际情况修改
formData: null,
success: function (resp) {
success++
console.log(resp)
console.log(i)
/*
这里肯能有bug,失败也会执行这里,所以这里应该是后台返回过来的状态码为成功时,
这里的succes才+1
*/
},
fail: function (res) {
fail++
console.log('fail: ' + i + 'fail: ' + fail)
},
complete: function (res) {
console.log(i)
i++
if (i == data.path.length) { //当图片传完时,停止调用
console.log('执行完毕');
console.log('成功:' + success + " 失败:" + fail);
} else { //若图片还没有传完,则继续调用函数
console.log(i);
data.i = i;
data.success = success;
data.fail = fail;
that.uploadimg(data);
}
if (i == data.path.length) { // 当图片传完时,停止调用
console.log('执行完毕')
console.log('成功:' + success + '失败:' + fail)
} else { // 若图片还没有传完,则继续调用函数
console.log(i)
data.i = i
data.success = success
data.fail = fail
that.uploadimg(data)
}
}
})
},
getNowDate() {
var now = new Date();
var week = now.getDay()
var str = "星期";
switch (now.getDay()) {
case 0:
str = str + "日";
break;
case 1:
str = str + "一";
break;
case 2:
str = str + "二";
break;
case 3:
str = str + "三";
break;
case 4:
str = str + "四";
break;
case 5:
str = str + "五";
break;
case 6:
str = str + "六";
break;
}
var year = now.getFullYear();
var month = now.getMonth() + 1;
var day = now.getDate();
if (month < 10) {
month = '0' + month;
};
if (day < 10) {
day = '0' + day;
};
// 如果需要时分秒,就放开
// var h = now.getHours();
// var m = now.getMinutes();
// var s = now.getSeconds();
var formatDate = year + '-' + month + '-' + day + '('+str+')';
return formatDate;
},
globalData: {
imgUrlUp: "https://shipin.wx.broteam.cn/index.php/MyComment/upload",
userInfo: null,
// 下导航
tabBar: [{
name: "首页",
state: true,
img: "http://omega.wx.bronet.cn/public/static/images/menu_icon1_select@2x_81.png",
selectImg: "http://omega.wx.bronet.cn/public/static/images/menu_icon1_select@2x.png",
num: null,
url: "../index/index"
},
{
name: "购物车",
state: false,
img: "http://omega.wx.bronet.cn/public/static/images/92@2x.png",
selectImg: "http://omega.wx.bronet.cn/public/static/images/92@2x_55.png",
num: 0,
url: "../shopCart/shopCart"
},
{
name: "我的",
state: false,
img: "http://omega.wx.bronet.cn/public/static/images/menu_icon3_select@2x.png",
selectImg: "http://omega.wx.bronet.cn/public/static/images/menu_icon3_select@2x_57.png",
num: null,
url: "../me/me"
},
],
unique_id: null, //公众号与小程序共有id
shoppingCart: null,
nearest_spot: null,//就近自提地址及id
nearest_store: null,//到店堂食地址及id
orderRemarkValue: null,
btnStart: true //选择的自提还是堂食
}
})