|
@@ -1,18 +1,58 @@
|
|
|
// pages/me/me.js
|
|
|
+const app = getApp()
|
|
|
Page({
|
|
|
|
|
|
/**
|
|
|
* 页面的初始数据
|
|
|
*/
|
|
|
data: {
|
|
|
-
|
|
|
+ userInfo: {
|
|
|
+ avatarUrl:"../../images/person.png"
|
|
|
+ },
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
onLoad: function (options) {
|
|
|
-
|
|
|
+ if (app.globalData.userInfo) {
|
|
|
+ this.setData({
|
|
|
+ userInfo: app.globalData.userInfo, //将全局用户信息赋值给变量
|
|
|
+ })
|
|
|
+ } else if (this.data.canIUse) { //getUserInfo在当前版本可用
|
|
|
+ // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
|
|
|
+ // 所以此处加入 callback 以防止这种情况
|
|
|
+ app.userInfoReadyCallback = res => {
|
|
|
+ this.setData({
|
|
|
+ userInfo: res.userInfo,
|
|
|
+ hasUserInfo: true
|
|
|
+ })
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 在没有 open-type=getUserInfo 版本的兼容处理
|
|
|
+ wx.getUserInfo({
|
|
|
+ success: res => {
|
|
|
+ app.globalData.userInfo = res.userInfo
|
|
|
+ this.setData({
|
|
|
+ userInfo: res.userInfo,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ };
|
|
|
+ },
|
|
|
+ getUserInfo: function(e) {
|
|
|
+ //点击取消按钮
|
|
|
+ if (e.detail.userInfo == null) {
|
|
|
+ console.log("授权失败")
|
|
|
+ }
|
|
|
+ else {//点击允许按钮
|
|
|
+ this.setData({
|
|
|
+ userInfo: e.detail.userInfo,
|
|
|
+ hasUserInfo: true
|
|
|
+ })
|
|
|
+ }
|
|
|
+ //全局对象用户信息赋值
|
|
|
+ app.globalData.userInfo = e.detail.userInfo
|
|
|
},
|
|
|
|
|
|
/**
|
|
@@ -62,5 +102,10 @@ Page({
|
|
|
*/
|
|
|
onShareAppMessage: function () {
|
|
|
|
|
|
+ },
|
|
|
+ gotoAttention(){
|
|
|
+ wx.navigateTo({
|
|
|
+ url: '../attention/attention',
|
|
|
+ })
|
|
|
}
|
|
|
})
|