user.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. // pages/user/user.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. userInfo: {},
  9. hasUserInfo: false,
  10. publisherId: [],
  11. publisherName: ""
  12. },
  13. bindGetUserInfo: function (e) {
  14. app.globalData.userInfo = e.detail.userInfo
  15. this.onShow()
  16. },
  17. publisherLogin: function () {
  18. wx.navigateTo({
  19. url: "/pages/publisherLogin/publisherLogin",
  20. })
  21. },
  22. publisherPage: function () {
  23. wx.navigateTo({
  24. url: "/pages/publisherPage/publisherPage?id=" + this.data.publisherId[0],
  25. })
  26. },
  27. myFollow:function(){
  28. wx.navigateTo({
  29. url: '/pages/myFollow/myFollow',
  30. })
  31. },
  32. myQuestion:function(){
  33. wx.navigateTo({
  34. url: '/pages/myQuestion/myQuestion',
  35. })
  36. },
  37. aboutUs:function(){
  38. wx.navigateTo({
  39. url: '/pages/aboutUs/aboutUs',
  40. })
  41. },
  42. opinion:function(){
  43. wx.navigateTo({
  44. url: '/pages/opinion/opinion',
  45. })
  46. },
  47. /**
  48. * 生命周期函数--监听页面加载
  49. */
  50. onLoad: function (options) {
  51. wx.showNavigationBarLoading()
  52. if (app.globalData.userInfo && app.globalData.publisherId) {
  53. this.setData({
  54. userInfo: app.globalData.userInfo,
  55. hasUserInfo: true,
  56. publisherId: app.globalData.publisherId
  57. })
  58. if (this.data.publisherId.length != 0) {
  59. const db = wx.cloud.database()
  60. db.collection("publisherInfoData").doc(this.data.publisherId[0]).get({
  61. success: function (res) {
  62. this.setData({
  63. publisherName: res.data.publisherName
  64. })
  65. wx.hideNavigationBarLoading()
  66. }.bind(this)
  67. })
  68. } else {
  69. wx.hideNavigationBarLoading()
  70. }
  71. } else {
  72. app.userInfoReadyCallback = res => {
  73. this.setData({
  74. userInfo: res.userInfo,
  75. hasUserInfo: true,
  76. publisherId: app.globalData.publisherId
  77. })
  78. if (this.data.publisherId.length != 0) {
  79. const db = wx.cloud.database()
  80. db.collection("publisherInfoData").doc(this.data.publisherId[0]).get({
  81. success: function (res) {
  82. this.setData({
  83. publisherName: res.data.publisherName
  84. })
  85. wx.hideNavigationBarLoading()
  86. }.bind(this)
  87. })
  88. } else {
  89. wx.hideNavigationBarLoading()
  90. }
  91. }
  92. }
  93. },
  94. /**
  95. * 生命周期函数--监听页面初次渲染完成
  96. */
  97. onReady: function () {
  98. },
  99. /**
  100. * 生命周期函数--监听页面显示
  101. */
  102. onShow: function () {
  103. const db = wx.cloud.database()
  104. db.collection("userInfoData").get({
  105. success: function (res) {
  106. if (res.data.length == 0) {
  107. db.collection("userInfoData").add({
  108. data: {
  109. publisherId: []
  110. },
  111. success: function (res) {
  112. app.globalData.publisherId = []
  113. this.setData({
  114. userInfo: app.globalData.userInfo,
  115. hasUserInfo: true,
  116. publisherId: app.globalData.publisherId
  117. })
  118. }.bind(this)
  119. })
  120. } else {
  121. app.globalData.publisherId = res.data[0].publisherId
  122. this.setData({
  123. userInfo: app.globalData.userInfo,
  124. hasUserInfo: true,
  125. publisherId: app.globalData.publisherId
  126. })
  127. if (this.data.publisherId.length != 0) {
  128. db.collection("publisherInfoData").doc(this.data.publisherId[0]).get({
  129. success: function (res) {
  130. this.setData({
  131. publisherName: res.data.publisherName
  132. })
  133. }.bind(this)
  134. })
  135. }
  136. }
  137. }.bind(this)
  138. })
  139. },
  140. /**
  141. * 生命周期函数--监听页面隐藏
  142. */
  143. onHide: function () {
  144. },
  145. /**
  146. * 生命周期函数--监听页面卸载
  147. */
  148. onUnload: function () {
  149. },
  150. /**
  151. * 页面相关事件处理函数--监听用户下拉动作
  152. */
  153. onPullDownRefresh: function () {
  154. },
  155. /**
  156. * 页面上拉触底事件的处理函数
  157. */
  158. onReachBottom: function () {
  159. },
  160. /**
  161. * 用户点击右上角分享
  162. */
  163. onShareAppMessage: function () {
  164. }
  165. })