person.js 2.2 KB

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