...
|
...
|
@@ -19,6 +19,8 @@ import { |
|
|
stringify
|
|
|
} from './vendors/query-stringify';
|
|
|
|
|
|
import commonModel from './models/common';
|
|
|
|
|
|
let yas;
|
|
|
|
|
|
// app.js
|
...
|
...
|
@@ -50,7 +52,10 @@ App({ |
|
|
}
|
|
|
this.globalData.systemInfo = sysInfo;
|
|
|
|
|
|
this.globalData.unionType = options.query.union_type || options.scene;
|
|
|
if (options && options.query && options.query.unionType) {
|
|
|
this.updateUnionType(options.query.unionType)
|
|
|
}
|
|
|
|
|
|
let timestamp = new Date().getTime() + '';
|
|
|
|
|
|
this.globalData.sid = MD5(timestamp);
|
...
|
...
|
@@ -67,6 +72,7 @@ App({ |
|
|
this.getUserInfo();
|
|
|
this.getUnionID();
|
|
|
this.doLogin();
|
|
|
this.setUserUnionType(this.getUid());
|
|
|
}).catch(() => { // 微信登录过期
|
|
|
wx.setStorage({
|
|
|
key: 'thirdSession',
|
...
|
...
|
@@ -81,6 +87,17 @@ App({ |
|
|
key: 'unionID',
|
|
|
data: ''
|
|
|
});
|
|
|
|
|
|
wx.setStorage({
|
|
|
key: "unionTypeTime",
|
|
|
data: '',
|
|
|
});
|
|
|
|
|
|
wx.setStorage({
|
|
|
key: "unionType",
|
|
|
data: ''
|
|
|
});
|
|
|
|
|
|
this.setUserInfo({});
|
|
|
this.setSessionKey('');
|
|
|
|
...
|
...
|
@@ -205,6 +222,67 @@ App({ |
|
|
key: 'userInfo',
|
|
|
data: this.globalData.userInfo
|
|
|
});
|
|
|
|
|
|
this.setUserUnionType(this.globalData.userInfo.uid);
|
|
|
},
|
|
|
getUserUnionType() {
|
|
|
return this.globalData.userUnionType;
|
|
|
},
|
|
|
setUserUnionType(uid) {
|
|
|
if (!uid) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
commonModel.getUnionTypeWithUid(uid).then(result => {
|
|
|
this.globalData.userUnionType = result.unionType;
|
|
|
});
|
|
|
},
|
|
|
updateUnionType(unionType) {
|
|
|
if (!unionType) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
let timeS = new Date().getTime() + '';
|
|
|
this.globalData.unionType = unionType;
|
|
|
this.globalData.unionTypeTime = timeS;
|
|
|
wx.setStorage({
|
|
|
key: "unionTypeTime",
|
|
|
data: timeS,
|
|
|
});
|
|
|
wx.setStorage({
|
|
|
key: "unionType",
|
|
|
data: unionType
|
|
|
});
|
|
|
},
|
|
|
getUnionType() {
|
|
|
/*
|
|
|
*unionType表示渠道号,在推广阶段通过商品详情页等传入。
|
|
|
* 接收到该参数时,赋值给全局变量时,持久化到本地。
|
|
|
* 在取值时,先从全局变量获取,若未获取到则从本地缓存中获取。
|
|
|
* 时效7天
|
|
|
*/
|
|
|
try {
|
|
|
var value = this.checkUnionType(this.globalData.unionType, this.globalData.unionTypeTime);
|
|
|
if (!value) {
|
|
|
let unionType = wx.getStorageSync('unionType');
|
|
|
let unionTypeTime = wx.getStorageSync('unionTypeTime');
|
|
|
value = this.checkUnionType(unionType, unionTypeTime);
|
|
|
}
|
|
|
return value
|
|
|
} catch (e) {
|
|
|
// console.log(e)
|
|
|
}
|
|
|
},
|
|
|
|
|
|
checkUnionType(unionType, unionTypeTime) {
|
|
|
if (!unionType) return '';
|
|
|
let time_old = unionTypeTime;
|
|
|
let time_new = new Date().getTime() + '';
|
|
|
var dayDiff = parseInt((parseInt(time_new) - parseInt(time_old)) / 1000);
|
|
|
if (dayDiff > 7 * 24 * 3600) {
|
|
|
return '';
|
|
|
}
|
|
|
return unionType;
|
|
|
},
|
|
|
setSessionKey: function(sessionKey) {
|
|
|
this.globalData.sessionKey = sessionKey;
|
...
|
...
|
@@ -278,4 +356,4 @@ App({ |
|
|
getMiniappType() {
|
|
|
return config.mini_app_type;
|
|
|
}
|
|
|
}); |
|
|
}); |
|
|
\ No newline at end of file |
...
|
...
|
|