You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
1.7 KiB

var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');
var user = require('../../../services/user.js');
var app = getApp();
Page({
data: {
userInfo: {}
},
onLoad: function(options) {
var that = this
wx.getSetting({
success: res => {
if (res.authSetting['scope.userInfo']) {
console.log('已授权');
wx.getUserInfo({
withCredentials: true,
lang: '',
success: function(res) {
that.setData({
userInfo: res.userInfo
})
},
})
}
}
})
},
onReady: function() {
},
onShow: function() {
// let userInfo = wx.getStorageSync('userInfo');
// let token = wx.getStorageSync('token');
// // 页面显示
// if (userInfo && token) {
// app.globalData.userInfo = userInfo;
// app.globalData.token = token;
// }
// this.setData({
// userInfo: app.globalData.userInfo,
// });
},
onHide: function() {
// 页面隐藏
},
onUnload: function() {
// 页面关闭
},
goLogin() {
user.loginByWeixin().then(res => {
this.setData({
userInfo: res.data.userInfo
});
app.globalData.userInfo = res.data.userInfo;
app.globalData.token = res.data.token;
}).catch((err) => {
console.log(err)
});
},
exitLogin: function() {
wx.showModal({
title: '',
confirmColor: '#b4282d',
content: '退出登录?',
success: function(res) {
if (res.confirm) {
wx.removeStorageSync('token');
wx.removeStorageSync('userInfo');
wx.switchTab({
url: '/pages/index/index'
});
}
}
})
}
})