me.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad: function (options) {
  16. console.log(app.globalData);
  17. if (app.globalData.userInfo) {
  18. this.setData({
  19. userInfo: app.globalData.userInfo,
  20. })
  21. } else if (this.data.canIUse) {
  22. app.userInfoReadyCallback = res => {
  23. this.setData({
  24. userInfo: res.userInfo,
  25. hasUserInfo: true
  26. })
  27. }
  28. } else {
  29. // 在没有 open-type=getUserInfo 版本的兼容处理
  30. wx.getUserInfo({
  31. success: res => {
  32. app.globalData.userInfo = res.userInfo
  33. this.setData({
  34. userInfo: res.userInfo,
  35. })
  36. }
  37. })
  38. };
  39. },
  40. getUserInfo: function(e) {
  41. //点击取消按钮
  42. if (e.detail.userInfo == null) {
  43. console.log("授权失败")
  44. }
  45. else {//点击允许按钮
  46. this.setData({
  47. userInfo: e.detail.userInfo,
  48. hasUserInfo: true
  49. })
  50. }
  51. //全局对象用户信息赋值
  52. app.globalData.userInfo = e.detail.userInfo
  53. },
  54. /**
  55. * 生命周期函数--监听页面初次渲染完成
  56. */
  57. onReady: function () {
  58. },
  59. /**
  60. * 生命周期函数--监听页面显示
  61. */
  62. onShow: function () {
  63. },
  64. /**
  65. * 生命周期函数--监听页面隐藏
  66. */
  67. onHide: function () {
  68. },
  69. /**
  70. * 生命周期函数--监听页面卸载
  71. */
  72. onUnload: function () {
  73. },
  74. /**
  75. * 页面相关事件处理函数--监听用户下拉动作
  76. */
  77. onPullDownRefresh: function () {
  78. },
  79. /**
  80. * 页面上拉触底事件的处理函数
  81. */
  82. onReachBottom: function () {
  83. },
  84. /**
  85. * 用户点击右上角分享
  86. */
  87. onShareAppMessage: function () {
  88. },
  89. gotoAttention(){
  90. wx.navigateTo({
  91. url: '../attention/attention',
  92. })
  93. },
  94. gotoAbout(){
  95. wx.showToast({
  96. title: '正在开发中',
  97. icon:'loading',
  98. duration:500
  99. })
  100. }
  101. })