person.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. */
  37. onHide: function () {
  38. },
  39. /**
  40. * 生命周期函数--监听页面卸载
  41. */
  42. onUnload: function () {
  43. },
  44. /**
  45. * 页面相关事件处理函数--监听用户下拉动作
  46. */
  47. onPullDownRefresh: function () {
  48. },
  49. /**
  50. * 页面上拉触底事件的处理函数
  51. */
  52. onReachBottom: function () {
  53. },
  54. /**
  55. * 用户点击右上角分享
  56. */
  57. onShareAppMessage: function () {
  58. },
  59. getInfo: async function (e) {
  60. const _self = this
  61. let userInfo = e.detail.userInfo
  62. userInfo['encryptedData'] = e.detail.encryptedData
  63. userInfo['iv'] = e.detail.iv
  64. let info = await app.wxLogin(userInfo);
  65. let hasMobile = false;
  66. if (info.mobile) {
  67. hasMobile = true
  68. }
  69. _self.setData({
  70. hasUserInfo: true,
  71. userInfo: info,
  72. hasMobile: hasMobile,
  73. })
  74. },
  75. gotoComment:async function (e) {
  76. console.log(this)
  77. const isAuth = await app.isAuth()
  78. if (!isAuth) {
  79. wx.redirectTo({
  80. url: '/pages/prompt/prompt?page=pages/comments/comments',
  81. })
  82. return
  83. }
  84. wx.navigateTo({
  85. url: '../comments/comments?title=我的评论&commentstype=my',
  86. })
  87. },
  88. gotoPersonInfo: function (e) {
  89. wx.navigateTo({
  90. url: '../personinfo/personinfo',
  91. })
  92. }
  93. })