app.js
7.2 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
235
236
237
238
239
240
241
242
243
244
245
246
247
var mta=require('mta-wechat-analysis')
var uri_dc = require('utils/uri.js')
import PubSub from 'utils/PubSub'
global.regeneratorRuntime = require('lib/regenerator/runtime-module')
const { regeneratorRuntime } = global
Array.prototype._indexOf = function (val) {
for (var i = 0; i < this.length; i++) {
if (this[i] == val) return i;
}
return -1;
};
Array.prototype.remove = function(val) {
var index = this._indexOf(val);
if (index > -1) {
this.splice(index, 1);
}
};
//import log from 'utils/realTimeLog'
// "tabBar": {
// "custom": true,
// "color": "#999999",
// "selectedColor": "#C0A369",
// "backgroundColor": "#262628",
// "borderStyle": "black",
// "list": [
// {
// "pagePath": "pages/reserve/index",
// "text": "附近"
// },
// {
// "pagePath": "pages/reserve/search",
// "text": "搜索"
// },
// {
// "pagePath": "pages/me/list",
// "text": "订单"
// },
// {
// "pagePath": "pages/me/index",
// "text": "我的"
// }
// ]
// },
App({
openid:"",
system:{},
shareTicket:"",
isAdmin:false,//是否运营人员
location:null,//人的位置信息
meListType:'',//订单页面标识
onLaunch: async function (opt) {
if (!wx.cloud) {
console.error('请使用 2.2.3 或以上的基础库以使用云能力')
} else {
wx.cloud.init({
traceUser: true,
env: 'suzi-714ca6'
})
}
if(wx.getLogManager){
const logger =wx.getLogManager()
console.log.prototype=function(){
console.log(...arguments)
logger.debug(...arguments)
};
}
console.log('onLaunch',opt,wx.env);
wx.removeStorage({key: 'formids'});//清理历史formids
mta.App.init({
"appID":"500667280",
"eventID":"500667287",
"statPullDownFresh":true,
"statShareApp":true,
"statReachBottom":true,
"lauchOpts":opt, //渠道分析
});
if(opt.shareTicket){
this.shareTicket=opt.shareTicket;
}
this.getSystemInfo();
//this.openid=await this.getOpenid();
//console.log('this.openid',this.openid,mta);
},
onShow:async function(){
//this._getOpenid();
if (wx.canIUse('getUpdateManager')) {
const updateManager = wx.getUpdateManager();
updateManager.onCheckForUpdate(function (res) {
// 请求完新版本信息的回调
console.log('onCheckForUpdate',res)
})
updateManager.onUpdateReady(function (res) {
console.log('onUpdateReady',res)
updateManager.applyUpdate();
wx.showToast({
title:'版本已更新',
duration:2000,
mask:true,
success:function(){
}
})
})
updateManager.onUpdateFailed(function (res) {
// 新的版本下载失败
console.log('onUpdateFailed',res)
})
}
},
async getSystemInfo(){
this._getSystemInfo().then((res)=>{
console.log('wx.getSystemInfo',res);
this.system=res;
}).catch(res=>{
this.getSystemInfo();
})
},
_getSystemInfo(){
return new Promise((success,fail)=>{
wx.getSystemInfo({
success:(res)=>{
if(res.errMsg=='getSystemInfo:ok'){
success(res);
}else{
fail(res);
}
},
fail:(res)=>{
fail(res);
}
})
})
},
async _login(){
return new Promise((success,fail)=>{
wx.login({
success: (login_res)=>{
console.log('wx.login',login_res)
success(login_res);
},
fail:(res)=>{
fail(res);
}
})
})
},
async _getLiteOpenidByCode(code,app_unionid){
return new Promise((success,fail)=>{
let params={code:code}
if(app_unionid){
params.unionid=app_unionid
}
wx.request({
url: uri_dc.HOST__LINE+'App.Reserve.GetLiteOpenid',
method: 'POST',
data: params,
header: {
'content-type': 'application/x-www-form-urlencoded'
},
success: function (res) {
try{
let openid=res.data.data.openid;
wx.setStorage({key:'customer_openid',data:openid});
wx.setStorage({key:'customer_session_key',data:res.data.data.session_key});
success(openid);
}catch(e){
console.log(res);
fail(res);
}
},
fail: function (res) {
console.log(res);
fail(res);
}
})
})
},
async _getOpenid(app_unionid){
try{
let login_res=await this._login();
let openid=await this._getLiteOpenidByCode(login_res.code,app_unionid)
return openid
}catch(e){
console.log('_getOpenid.catch',e)
return;
}
},
async getOpenid(app_unionid=''){
let openid=''
if(app_unionid){
openid= await this._getOpenid(app_unionid);
}else{
openid=wx.getStorageSync('customer_openid');
if(!openid){
openid= await this._getOpenid(app_unionid);
}
}
this.openid=openid
return openid;
},
onHide(){
console.log('onHide');
PubSub.emit('appHide')
wx.getStorage({
key:'EVENT_LOG_CACHE',
success:async res=>{
wx.request({
url: uri_dc.HOST__LINE+'App.Customer.SetUserLogs',
method: 'POST',
data: {
openid:await this.getOpenid(),
logs:JSON.stringify(res.data)
},
header: {
'content-type': 'application/x-www-form-urlencoded'
},
success:()=>{
wx.removeStorage({key:'EVENT_LOG_CACHE'})
},
})
}
})
let time=new Date()/1000;
wx.getStorageInfo({
success:(res)=>{
console.log(res.keys);
if(res.keys.length>0){
res.keys.forEach(key=>{
wx.getStorage({
key:key,
success:(ca)=>{
//console.log('obHide',ca.data.timeout,time);
if(ca.data.timeout && ca.data.timeout<time && ca.data.timeout!=-1){
wx.removeStorage({key:key})
}
}
})
})
}
},
})
}
})