// index.js // const app = getApp() // const { envList } = require('../../envList.js'); Page({ data: { detailInfo: '关于:前端程序员的生活博客', title: "yma16博客", userImageUrl: "https://yongma16.xyz/staticFile/common/img/logo.png", loginTitle: "点击授权", userName: '', userInfo: {}, hasUserInfo: false, isloading: true, }, getUserInfoBtn: function (info) { fgetUserProfile wx.showLoading({ title: '授权中', }); console.log('userinfo', info) if (info && info.detail) { const rowData = info.detail.rawData ? JSON.parse(info.detail.rawData) : { nickName: '未授权用户', avatarUrl: '' } this.setData({ userImageUrl: rowData.avatarUrl, userName: rowData.nickName, userInfo:rowData }) wx.setStorageSync('currentUserInfo',rowData) console.log('rowData', rowData) } wx.hideLoading(); }, getUserProfile(e) { // 推荐使用 wx.getUserProfile 获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认 // 开发者妥善保管用户快速填写的头像昵称,避免重复弹窗 wx.getUserProfile({ desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 success: (res) => { console.log('信息', res) console.log('信息', res.userInfo) wx.setStorageSync('currentUserInfo',res.userInfo) this.setData({ userInfo: res.userInfo, hasUserInfo: true }) // 跳转到home this.jumpTohome() } }) }, // 跳转到home jumpTohome: function () { const thisBack = this wx.navigateTo({ url: '/pages/home/home', success: function (res) { // 通过 eventChannel 向被打开页面传送数据 res.eventChannel.emit('setCurrentUserInfo', thisBack.data.userInfo) } }) }, onLoad: function (options) { this.jumpTohome() // 页面创建时执行 }, onShow: function () { // 页面出现在前台时执行 }, onReady: function () { // 页面首次渲染完毕时执行 }, onHide: function () { // 页面从前台变为后台时执行 }, onUnload: function () { // 页面销毁时执行 }, onPullDownRefresh: function () { // 触发下拉刷新时执行 }, onReachBottom: function () { // 页面触底时执行 }, onShareAppMessage: function () { // 页面被用户分享时执行 }, onPageScroll: function () { // 页面滚动时执行 }, onResize: function () { // 页面尺寸变化时执行 }, userLogin: function () { wx.login({ success(res) { if (res.code) { //发起网络请求 wx.request({ url: 'https://example.com/onLogin', data: { code: res.code } }) } else { console.log('登录失败!' + res.errMsg) } } }) } });