工作日志 随手笔记 仅供参考
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
var that = this;
if (wx.getStorageSync('auth_token')){
that.gitauthtoken()
}else{
this.userInfoReadyCallback(this.gitauthtoken);
}
},
封装好的函数 用来判断用户是否登录 获取auth_token
userInfoReadyCallback: function (calback) {
var that = this;
//console.log(app.globalData.userInfo);
util.login().then((res) => {
//console.log("----------");
return util.getUserAuthRequest('https://pmcore.mbcore.com/weapp/login', { code: res.code })
}).then(function (res) {
//如果needBind 是true 则需要本地缓存paramBind验证手机号时用
console.log(res.data.result.needBind);
if (res.data.result.needBind) {
//为新用户,提示去绑定手机号页面
var paramBind = wx.getStorageSync('paramBind') || '';
paramBind = res.data.result.paramBind;
wx.setStorageSync('paramBind', paramBind);
wx.showModal({
title: '提示',
content: '您尚未登录,点击确定去往手机登录页面,点击取消将无法购买',
success: function (res) {
if (res.confirm) {
wx.navigateTo({
url: '/pages/bindphone/bindphone'
})
} else if (res.cancel) {
console.log("我点击了取消按钮");
wx.switchTab({
url: '/pages/index/index'
})
}
}
});
// wx.navigateTo({
// url: '/pages/bindphone/bindphone'
// })
} else {
//为老用户,可以正常登录,并本地存储auth_token
var auth_token = wx.getStorageSync('auth_token') || '';
auth_token = res.data.result.auth_token;
wx.setStorageSync('auth_token', auth_token);
//console.log(wx.getStorageSync('auth_token'));
if (calback) {
calback();
}
}
})
}
onShow: function () {
var that = this;
//用户拒绝微信位置请求
wx.getSetting({
success(res) {
if (!res.authSetting['scope.userLocation']) {
//用户没有授权位置信息
that.setData({
isAuthorizedLocation:false
})
wx.showModal({
title: '提示',
content: '查看附近的店需要您的地理位置',
confirmText: '去开启',
success: function (res) {
if (res.confirm) {
console.log('用户点击去开启')
wx.openSetting()
} else if (res.cancel) {
console.log('用户点击取消')
}
}
})
}else{
//用户授权了位置信息
that.setData({
isAuthorizedLocation: true
})
}
}
})
// if (wx.getStorageSync('auth_token')) {
// } else {
// this.userInfoReadyCallback(this.getLikeStatus);
// }
//this.changeClassify()
},