person.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // pages/person/person.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. hasUserInfo: false
  9. },
  10. /**
  11. * 生命周期函数--监听页面加载
  12. */
  13. onLoad: async function (options) {
  14. let userInfo = await app.getWxUserInfo()
  15. console.log(userInfo);
  16. if (userInfo) {
  17. this.setData({
  18. userInfo: userInfo,
  19. hasUserInfo: true,
  20. hasMobile: userInfo.mobile ? true : false
  21. })
  22. }
  23. },
  24. /**
  25. * 生命周期函数--监听页面初次渲染完成
  26. */
  27. onReady: function () {
  28. },
  29. /**
  30. * 生命周期函数--监听页面显示
  31. */
  32. onShow: async function () {},
  33. /**
  34. * 生命周期函数--监听页面隐藏
  35. */
  36. onHide: function () {
  37. },
  38. /**
  39. * 生命周期函数--监听页面卸载
  40. */
  41. onUnload: function () {
  42. },
  43. /**
  44. * 页面相关事件处理函数--监听用户下拉动作
  45. */
  46. onPullDownRefresh: function () {
  47. },
  48. /**
  49. * 页面上拉触底事件的处理函数
  50. */
  51. onReachBottom: function () {
  52. },
  53. /**
  54. * 用户点击右上角分享
  55. */
  56. onShareAppMessage: function () {
  57. },
  58. getInfo: async function (e) {
  59. const _self = this
  60. let userInfo = e.detail.userInfo
  61. userInfo['encryptedData'] = e.detail.encryptedData
  62. userInfo['iv'] = e.detail.iv
  63. let info = await app.wxLogin(userInfo);
  64. let hasMobile = false;
  65. if (info.mobile) {
  66. hasMobile = true
  67. }
  68. _self.setData({
  69. hasUserInfo: true,
  70. userInfo: info,
  71. hasMobile: hasMobile,
  72. })
  73. },
  74. gotoComment: async function (e) {
  75. console.log(this)
  76. const isAuth = await app.isAuth()
  77. if (!isAuth) {
  78. wx.redirectTo({
  79. url: '/pages/prompt/prompt?page=pages/comments/comments',
  80. })
  81. return
  82. }
  83. wx.navigateTo({
  84. url: '../comments/comments?title=我的评论&commentstype=my',
  85. })
  86. },
  87. gotoPersonInfo: function (e) {
  88. wx.navigateTo({
  89. url: '../personinfo/personinfo',
  90. })
  91. }
  92. })