lzh/pages/index/my/my.js

164 lines
4.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// pages/index/my/my.js
let app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
userInfo: {},
hasUserInfo: false,
showPop: false,
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
let userInfo = wx.getStorageSync('userInfo');
console.log(userInfo);
if (userInfo) {
this.setData({
userInfo: userInfo,
hasUserInfo: true
})
} else {
// 查看是否授权
// let _this = this;
// wx.getSetting({
// success(res) {
// if (res.authSetting['scope.userInfo']) {
// // 已经授权,可以直接调用 getUserInfo 获取头像昵称
// wx.getUserInfo({
// success: function (res) {
// console.log(res);
// if (res.userInfo.nickName === '微信用户') {
// return;
// }
// _this.setData({
// userInfo:res.userInfo,
// hasUserInfo:true
// })
// wx.setStorageSync('userInfo', res.userInfo);
// }
// })
// }
// }
// })
}
},
getUserInfo(e) {
console.log(e.detail.userInfo)
},
getUserProfile(e) {
console.log(1122);
// 推荐使用wx.getUserProfile获取用户信息开发者每次通过该接口获取用户个人信息均需用户确认
// 开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
wx.getUserProfile({
desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
success: (res) => {
console.log(res);
// this.setData({
// userInfo: res.userInfo,
// hasUserInfo: true
// })
wx.setStorageSync('userProfile', res);
this.getdatainfo();
}
})
},
onClose() {
console.log(234324);
this.setData({
showPop: false
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow(e) {
console.log(e);
console.log(121);
},
getdatainfo() {
let _this = this;
wx.login({
success(res) {
if (res.code) {
console.log(res.code);
//发起网络请求
let d = wx.getStorageSync('userProfile');
if (!d) {
return;
}
console.log(d);
// app.http._post('http://127.0.0.1:889/hb/jd/getcode',{code:res.code,encryptedData:d.encryptedData,iv:d.iv}).then(res3=>{
// console.log(res3);
// })
app.http._post('user/loginUser', {
code: res.code,
encryptedData: d.encryptedData,
iv: d.iv
}).then(res => {
console.log(res);
if (res.code == 1) {
wx.setStorageSync('userInfo', res.data);
_this.setData({
userInfo: res.data,
hasUserInfo: true
})
}
})
} else {
console.log('登录失败!' + res.errMsg)
}
}
})
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})