forked from whyymj/EWEIWX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
308 lines (282 loc) · 8.38 KB
/
app.js
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
/**
*
* app.js
*
* @create 2017-1-1
* @author Young
*
* @update Young 2017-01-05
*
*/
var core = require('utils/core.js');
App({
onShow: function () {
this.onLaunch();
},
onLaunch: function () {
var $this = this;
wx.getSystemInfo({
success: function (res) {
var model = res.model;
var iponeX = model.indexOf("iPhone X");
if (iponeX == '0'){
$this.setCache("isIpx", res.model);
}else{
$this.setCache("isIpx", '');
}
}
})
let that = this;
wx.getSystemInfo({// 获取页面的有关信息
success: function (res) {
wx.setStorageSync('systemInfo', res)
var ww = res.windowWidth;
var hh = res.windowHeight;
that.globalData.ww = ww;
that.globalData.hh = hh;
}
});
},
/**
* 小程序检查是否授权方法,写入当前页面路径和参数缓存
* @date 2018-10-22
* @author Vencenty
*/
checkAuth: function () {
const url = '/pages/message/auth/index'
const currentPages = getCurrentPages()
const currentPage = currentPages[currentPages.length - 1]
const routeData = {
'params': currentPage.options || null,
'url': currentPage.route
}
// 处理扫码进来的商品信息
if(routeData.params.hasOwnProperty('scene')) {
const params = {}
const scene = decodeURIComponent(routeData.params.scene)
const paramsArr = scene.split('&').shift().split('=')
params.id = paramsArr[1]
routeData.params = params
}
this.setCache('routeData', routeData)
const userinfo = this.getCache('userinfo')
wx.getSetting({
success: function (settings) {
if (!settings.authSetting['scope.userInfo']) {
wx.redirectTo({url: url})
} else {
if (!userinfo) {
wx.redirectTo({ url: url })
} else {
core.get('member', {}, function (ret) {
if (ret.error) {
wx.redirectTo({ url: url })
}
})
}
}
}
})
},
requirejs: function (jsname) {
return require('utils/' + jsname + '.js');
},
getConfig: function () {
if (this.globalData.api !== null) {
return {
api: this.globalData.api,
approot: this.globalData.approot,
appid: this.globalData.appid
};
}
var ext = wx.getExtConfigSync();
this.globalData.api = ext.config.api;
this.globalData.approot = ext.config.approot;
this.globalData.appid = ext.config.appid;
return ext.config;
},
getCache: function (key, defaultValue) {
var time = (+new Date()) / 1000, data = '';
time = parseInt(time);
try {
data = wx.getStorageSync(key + this.globalData.appid);
if (data.expire > time || data.expire == 0) {
data = data.value;
} else {
data = '';
this.removeCache(key);
}
} catch (e) {
data = typeof (defaultValue) === 'undefined' ? '' : defaultValue;
}
data = data || '';
return data;
},
setCache: function (key, value, expire) {
var time = (+new Date()) / 1000, rt = true;
var data = {
expire: expire ? time + parseInt(expire) : 0,
value: value
};
try {
wx.setStorageSync(key + this.globalData.appid, data);
} catch (e) {
rt = false;
}
return rt;
},
removeCache: function (key) {
var rt = true;
try {
wx.removeStorageSync(key + this.globalData.appid);
} catch (e) {
rt = false;
}
return rt;
},
close: function () {
this.globalDataClose.flag = true;
wx.reLaunch({
url: '/pages/index/index',
})
},
getSet: function () {
var $this = this;
var cacheset = $this.getCache("cacheset");
if (cacheset == '') {
// var sysset = $this.getCache("sysset");
// if (sysset == '') {
setTimeout(function () {
var cacheset = $this.getCache("cacheset");
core.get('cacheset', { version: cacheset.version }, function (result) {
if (result.update) {
$this.setCache("cacheset", result.data);
}
// $this.setCache("sysset", result.sysset, 7200);
});
}, 10);
}
},
url: function (options) {
options = options || {};
var arg = {}, mid = '', merchid = '', user = this.getCache('usermid');
mid = options.mid || '';
merchid = options.merchid || '';
for (let i in user) {
if (typeof user[i] != 'undefined') {
arg[i] = user[i]
}
}
if (user != '') {
if (user.mid == '' || typeof user.mid == 'undefined') {
arg.mid = mid;
}
if (user.merchid == '' || typeof user.merchid == 'undefined') {
arg.merchid = merchid;
}
} else {
arg.mid = mid;
arg.merchid = merchid;
}
this.setCache('usermid', arg);
},
/*再次发起授权*/
impower: function(limit, msg, route) {
wx.getSetting({
success: function(res) {
var limits = res.authSetting['scope.' + limit];
if(!limits) {
wx.showModal({
title: '用户未授权',
content: '您点击了拒绝授权,暂时无法' + msg + ',点击去设置可重新获取授权喔~',
confirmText: '去设置',
success: function(res) {
if(res.confirm) {
wx.openSetting({
success: function(res) {}
})
}else{
if(route == 'route'){
wx.switchTab({
url: '/pages/index/index'
})
}else if(route == 'details'){
//停留在当前页面
}else{
wx.navigateTo({
url: '/pages/index/index'
})
}
}
}
})
}
}
})
},
globalDataClose: {
flag: false,
},
//晚秋
// globalData: {
// appid:'wx3d3b2fd41970f6db',
// api: "https://api.clubmall.cn/app/ewei_shopv2_api.php?i=16",
// approot: "https://api.clubmall.cn/addons/ewei_shopv2/",
// userInfo: null
// }
//姜倩
// globalData: {
// appid: 'wx5f691ef96a19887c',
// api: "https://jqnyrv.ifkvip.com/app/ewei_shopv2_api.php?i=4",
// approot: "https://jqnyrv.ifkvip.com/addons/ewei_shopv2/",
// userInfo: null
// }
// demo站点
// globalData: {
// appid: 'wx5d7c9a63ffdf10f8',
// api: "https://demo.foxteam.cc/app/ewei_shopv2_api.php?i=11",
// approot: "https://demo.foxteam.cc/addons/ewei_shopv2/",
// userInfo: null
// }
// elinkkc
// globalData: {
// appid:'wx3d3b2fd41970f6db',
// api: "https://yctcs.100cms.com/app/ewei_shopv2_api.php?i=2",
// approot: "https://yctcs.100cms.com/addons/ewei_shopv2/",
// userInfo: null
// }
// 售后
// globalData: {
// appid: "wx3502a0f358ee367f",
// api: "https://shn2mgo.ifkvip.com/app/ewei_shopv2_api.php?i=2",
// approot: "https://shn2mgo.ifkvip.com/addons/ewei_shopv2/",
// userInfo: null
// }
// 测试站
globalData: {
appid: "wx3d3b2fd41970f6db",
api: "https://yctcs.100cms.com/app/ewei_shopv2_api.php?i=2",
approot: "https://yctcs.100cms.com/addons/ewei_shopv2/",
userInfo: null
}
// 姜倩
// globalData: {
// appid: "wx21e66d345b76074d",
// api: "https://jqnyrv.ifkvip.com/app/ewei_shopv2_api.php?i=51",
// approot: "https://jqnyrv.ifkvip.com/addons/ewei_shopv2/",
// userInfo: null
// }
//api
// globalData: {
// appid: "wx3d3b2fd41970f6db",
// api: "https://api.clubmall.cn/app/ewei_shopv2_api.php?i=16",
// approot: "https://api.clubmall.cn/addons/ewei_shopv2/",
// userInfo: null
// }
// globalData: {
// appid: null,
// api: null,
// approot: null,
// userInfo: null
// }
})