index.js
2.84 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
// index.js
import wx from '../../utils/wx';
import event from '../../common/event';
import { getLoginButtonType } from '../../common/login';
import { parse } from '../../vendors/query-stringify';
import accountModel from '../../models/account/index';
import Promise from '../../vendors/es6-promise';
import config from '../../common/config';
import Yas from '../../common/yas';
let app = getApp();
let yas;
let router = global.router;
Page({
data: {
loginButtonType: '', // 获取登录button-type
channellist: [],
userInfo: {
phoneNum: '',
avatarUrl: '',
defaultAvatar: false,
nickName: ''
},
coinNum: 0,
isBound: false,
myQrCodeUrl: 'https://m.yohobuy.com/home/newQrcode?needLogin=1',
loginText: '点击登录'
},
onLoad: function() {
let that = this;
yas = new Yas(app); // 实例化埋点
yas.pageOpenReport();
event.on('user-login-success', this.showBindUserInfo);
event.on('user-login-callback', this.loginCallback.bind(this));
event.on('change-login-status', params => {
that.setData({
loginText: params.text || '点击登录'
});
});
},
onShow: function() {
setTimeout(() => {
app = app || getApp();
this.showBindUserInfo();
}, app ? 0 : 1000);
},
onReady: function() {
},
changeLoginStatus: function(params) {
console.log(params);
},
loginCallback: function(res) {
this.setData({
loginButtonType: getLoginButtonType()
});
},
showBindUserInfo: function() {
let that = this;
this.setData({
loginButtonType: getLoginButtonType()
});
if (app && app.getUid()) {
return Promise.all([
accountModel.getProfile(),
accountModel.getCoinTotal(),
]).then(res => {
let defaultAvatar = '../../static/images/icons/default-avatar.png';
let resUserInfo = res[0].data || {};
console.log('resUserInfo:', resUserInfo);
let user = Object.assign({}, this.data.userInfo, app.globalData.userInfo, {
nickName: resUserInfo.nickname,
avatarUrl: resUserInfo.head_ico || defaultAvatar,
phoneNum: resUserInfo.mobile,
defaultAvatar: (resUserInfo.head_ico || defaultAvatar) === defaultAvatar,
});
app.setUserInfo(user);// 把用户信息写入storage
that.setData({
isBound: true,
userInfo: user,
coinNum: res[1].data && res[1].data.total || 0
});
}).catch({});
}
},
outLogin: function() {
return wx.showModal({
title: '',
content: '确认退出?',
confirmText: '退出',
confirmColor: '#000'
}).then(res1 => {
if (res1.confirm) {
app.clearUserSession();
// app._setSync('disableAutoLogin', true);
wx.reLaunch({
url: '/pages/index/index'
});
}
});
}
});