// var utils = require('../../utils/util.js');
//self.js 个人中心首页
//获取应用实例
var app = getApp()
Page({
data: {
userInfo: null,
certificationOk: null,
avatarUrl: '',
userInfo: {},
logged: false,
takeSession: false,
requestResult: '',
username:''
},
onPullDownRefresh :function(){
utils.getUserData();
wx.stopPullDownRefresh()
},
onLoad: function (options) {
var that = this;
wx.getSetting({
success: res => {
if (res.authSetting['scope.userInfo']) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
console.log("已经授权");
wx.getUserInfo({
success: res => {
console.log(res);
this.setData({
avatarUrl: res.userInfo.avatarUrl,
userInfo: res.userInfo,
username:res.userInfo.nickName
})
}
})
}else{
console.log("未授权");
}
}
})
},
onReady:function(){
var that = this;
if (that.data.userInfo){
if (that.data.certificationOk == 0){
wx.showModal({
title: '认证提醒',
content: '您还没有认证',
cancelText: "下次再说",
cancelColor: "",
success: function (res) {
if (res.confirm) {
wx.navigateTo({
url: '../toAuth/toAuth',
})
} else if (res.cancel) {
console.log('用户点击取消')
}
}
})
}
}
},
onShow: function () {
var that = this;
console.log(that+"==================")
// utils.checkSettingStatu(that);
},
//事件处理函数
bindViewTap: function () {
wx.navigateTo({
url: '../logs/logs'
})
},
login:function(e){
//认证信息及个人信息切换
var that = this;
console.log(that);
console.log(e);
console.log(this.data.logged);
console.log(e.detail.userInfo);
wx.getSetting({
success: res => {
if (res.authSetting['scope.userInfo']) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
console.log("已经授权");
wx.getUserInfo({
success: res => {
console.log(res);
this.setData({
avatarUrl: res.userInfo.avatarUrl,
userInfo: res.userInfo,
username:res.userInfo.nickName
})
}
})
}else{
console.log("未授权");
}
}
})
// wx.getUserInfo({
// complete: (res) => {
// console.log(res);
// if (res.authSetting['scope.userInfo']) {
// this.setData({
// logged: true,
// avatarUrl: res.detail.userInfo.avatarUrl,
// userInfo: res.detail.userInfo,
// username:res.detail.userInfo.nickName
// })
// wx.navigateTo({
// url: '../toAuth/toAuth',
// })
// }else{
// console.log(已授权);
// }
// },
// })
},
// if (that.data.certificationOk == 2){
// //个人信息页面
// wx.navigateTo({
// url: '../selfInfo/selfInfo',
// })
// }else{
// //去认证页面
// wx.navigateTo({
// url: '../toAuth/toAuth',
// })
// }
// },
openAccount: function (event) {
//打开我的账户
wx.navigateTo({
url: '../myAccount/myAccount',
})
},
openBookList:function(event){
//打开个人中心图书列表
var index = event.currentTarget.dataset.index;
wx.navigateTo({
url: '../bookList/bookList?index=' + index,
})
},
//自营点上传图书
uploadPilot: function () {
wx.navigateTo({
url: '../zcone/zcone'
})
},
openOpinion:function(){
//打开意见反馈
wx.navigateTo({
url: '../opinion/opinion',
})
},
aboutUs:function(){
//打开关于我们
wx.navigateTo({
url: '../aboutUs/aboutUs',
})
},
openSetting:function(){
wx.navigateTo({
url: '../setting/setting',
})
},
openCards:function(){
wx.navigateTo({
url: '../card/card',
})
}
})
当我点击授权按钮的时候执行的是
login:function(e){
//认证信息及个人信息切换
var that = this;
console.log(that);
console.log(e);
console.log(this.data.logged);
console.log(e.detail.userInfo);
wx.getSetting({
success: res => {
if (res.authSetting['scope.userInfo']) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
console.log("已经授权");
wx.getUserInfo({
success: res => {
console.log(res);
this.setData({
avatarUrl: res.userInfo.avatarUrl,
userInfo: res.userInfo,
username:res.userInfo.nickName
})
}
})
}else{
console.log("未授权");
}
}
})
z这个login函数,但是每次授权都得重新进一次页面才能获取用户信息,这是为什么,顺便问一下{{userInfo.nickName?userInfo.nickName:"点击授权登录"}}这个意思是
z这个变量不为空就显示变量,变量为空就显示点击授权登录?,劳烦解答一下,先谢谢大佬们了