me.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. // pages/me/me.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. userInfo: {
  9. avatarUrl:"../../images/person.png"
  10. },
  11. loginif:false
  12. },
  13. /**
  14. * 生命周期函数--监听页面加载
  15. */
  16. onLoad: function (options) {
  17. console.log(app.globalData);
  18. if(wx.getStorageSync('openid')){
  19. this.setData({
  20. loginif:true
  21. })
  22. }else{
  23. this.setData({
  24. loginif:false
  25. })
  26. }
  27. if (app.globalData.userInfo) {
  28. this.setData({
  29. userInfo: app.globalData.userInfo,
  30. })
  31. } else if (this.data.canIUse) {
  32. app.userInfoReadyCallback = res => {
  33. this.setData({
  34. userInfo: res.userInfo,
  35. hasUserInfo: true
  36. })
  37. }
  38. } else {
  39. // 在没有 open-type=getUserInfo 版本的兼容处理
  40. wx.getUserInfo({
  41. success: res => {
  42. app.globalData.userInfo = res.userInfo
  43. this.setData({
  44. userInfo: res.userInfo,
  45. })
  46. }
  47. })
  48. };
  49. },
  50. login:function(){
  51. wx.navigateTo ({
  52. url: '/pages/auth/auth',
  53. })
  54. },
  55. getUserInfo: function(e) {
  56. //点击取消按钮
  57. if (e.detail.userInfo == null) {
  58. console.log("授权失败")
  59. }
  60. else {//点击允许按钮
  61. this.setData({
  62. userInfo: e.detail.userInfo,
  63. hasUserInfo: true
  64. })
  65. }
  66. //全局对象用户信息赋值
  67. app.globalData.userInfo = e.detail.userInfo
  68. },
  69. /**
  70. * 生命周期函数--监听页面初次渲染完成
  71. */
  72. onReady: function () {
  73. },
  74. /**
  75. * 生命周期函数--监听页面显示
  76. */
  77. onShow: function () {
  78. this.onLoad()
  79. },
  80. /**
  81. * 生命周期函数--监听页面隐藏
  82. */
  83. onHide: function () {
  84. },
  85. /**
  86. * 生命周期函数--监听页面卸载
  87. */
  88. onUnload: function () {
  89. },
  90. /**
  91. * 页面相关事件处理函数--监听用户下拉动作
  92. */
  93. onPullDownRefresh: function () {
  94. },
  95. /**
  96. * 页面上拉触底事件的处理函数
  97. */
  98. onReachBottom: function () {
  99. },
  100. /**
  101. * 用户点击右上角分享
  102. */
  103. onShareAppMessage: function () {
  104. },
  105. gotoAttention(){
  106. if(wx.getStorageSync('openid')){
  107. wx.navigateTo({
  108. url: '../attention/attention',
  109. })
  110. }else{
  111. wx.showLoading({title: '请先授权登录'})
  112. setTimeout(function(){
  113. wx.hideLoading()
  114. },600);
  115. }
  116. },
  117. gotoAbout(){
  118. wx.showToast({
  119. title: '正在开发中',
  120. icon:'loading',
  121. duration:500
  122. })
  123. }
  124. })