app.js
3.23 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
import { getYHStorageSync } from './utils/util';
import {WeToast} from './vendors/toast/wetoast';
import { ttLogin, addLoginListenner } from './login/utils/login/login';
import { Event } from './login/utils/index';
global.event = new Event();
App({
globalData: {
selectedChannel: 'boy',
userInfo: {},
systemInfo: null,
WXThird_session: '',
WXUnion_ID: '',
openID: '',
verifyKey: '',
sessionkey: '',
sid: '',
udid: '',
cid: '1',
mobileRegisterState: '',
hasReportAwakeAction: 'false',
defraudurl: 'https://activity.yoho.cn/feature/45.html?title=防诈骗提醒',
union_type: '', // 渠道号,大数据上传用
union_type_time: '',
ch: '',
networkType: '0',
deviceInfo: {},
currentScene: 1001,
user_union_type: '', // 用户相关unionType 要与union_type区分开
user_union_type_imageUrl: '', // 联盟图片
user_nounion_type_imageUrl: '', // 非联盟用户分享banner图片
shareId: '',
shareInfo: {},
open_id: ''
},
onLaunch: function () {
let res = tt.getSystemInfoSync();
if (!res.screenHeight) {
res.screenHeight = res.windowHeight;
}
if (!res.screenWidth) {
res.screenWidth = res.windowWidth;
}
this.globalData.systemInfo = res;
ttLogin();
addLoginListenner();
},
getUserInfo() {
let userInfo = getYHStorageSync('userInfo', 'app');
this.globalData.userInfo = userInfo || {};
},
/*
*union_type表示渠道号,在推广阶段通过商品详情页等传入。
* 接收到该参数时,赋值给全局变量时,持久化到本地。
* 在取值时,先从全局变量获取,若未获取到则从本地缓存中获取。
* 时效7天
*/
getUnion_type: function () {
try {
var value = this.checkUnion_type(this.globalData.union_type, this.globalData.union_type_time);
if (!value) {
let union_type = getYHStorageSync('union_type', 'app') ? getYHStorageSync('union_type', 'app'):"";
let union_type_time = getYHStorageSync('union_type_time', 'app') ? getYHStorageSync('union_type_time', 'app'):"";
value = this.checkUnion_type(union_type, union_type_time);
}
return value
} catch (e) {
// console.log(e)
}
},
checkUnion_type: function (union_type, union_type_time) {
if (!union_type)return '';
let time_old = union_type_time;
let time_new = new Date().getTime() + '';
var dayDiff = parseInt ((parseInt(time_new) - parseInt(time_old)) / 1000 );
if (dayDiff > 7 * 24 * 3600) {
return '';
}
return union_type;
},
getUnionID: function () {
var value = getYHStorageSync('unionID','app')
if (value) {
this.globalData.WXUnion_ID = value;
}
},
isLogin: function () {
return this.globalData.userInfo.uid > 0 ? true : false
},
getUid: function() {
let uid = this.globalData.userInfo.uid || 0;
if (!uid || uid === 0) {
this.getUserInfo();
uid = this.globalData.userInfo.uid || 0;
}
return uid;
},
clearUserSession() {},
getSessionkey: function() {
let sessionKey = getYHStorageSync('sessionkey', 'app');
if (sessionKey) {
this.globalData.sessionkey = sessionKey;
}
return sessionKey || '';
},
WeToast
})