index.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. import {
  2. getAuthorityMsg,
  3. getMessageRecord,
  4. msgTopping
  5. } from '~/api/message'
  6. import {
  7. getMyInfo,
  8. } from '~/api/user'
  9. import {
  10. createStoreBindings
  11. } from 'mobx-miniprogram-bindings'
  12. import {
  13. store
  14. } from '~/store/index'
  15. import reachBottom from '~/mixins/reachBottom'
  16. const app = getApp()
  17. Page({
  18. behaviors: [reachBottom],
  19. data: {
  20. targetId: "",
  21. menu: {
  22. show: false,
  23. top: 0,
  24. left: 0
  25. },
  26. menuH: 0,
  27. authorityMsg: {},
  28. uid: '',
  29. userInfo: {},
  30. isTop: false
  31. },
  32. onLoad(options) {
  33. this.setData({
  34. uid: wx.getStorageSync('uid')
  35. })
  36. this.storeBindings = createStoreBindings(this, {
  37. store,
  38. actions: {
  39. setUser: 'setUser'
  40. }
  41. })
  42. },
  43. async onShow() {
  44. if (typeof this.getTabBar === 'function') {
  45. this.getTabBar().setData({
  46. selected: 0
  47. })
  48. }
  49. this.getAuthorityMsg()
  50. this.resetData()
  51. let userInfo = await getMyInfo()
  52. this.setData({
  53. userInfo
  54. })
  55. this.setUser(userInfo.user)
  56. wx.createSelectorQuery().select('.menu').boundingClientRect((rect) => {
  57. this.setData({
  58. menuH: rect.height
  59. })
  60. }).exec()
  61. },
  62. async getAuthorityMsg() {
  63. let authorityMsg = await getAuthorityMsg()
  64. this.setData({
  65. authorityMsg
  66. })
  67. },
  68. loadMore() {
  69. this.getData(getMessageRecord, {
  70. pageSize: 20
  71. })
  72. },
  73. setSearch({
  74. detail
  75. }) {
  76. wx.navigateTo({
  77. url: '/pages/searchFriend/index',
  78. })
  79. },
  80. onLongPress(e) {
  81. let {
  82. currentTarget,
  83. detail,
  84. touches,
  85. target
  86. } = e
  87. let remainingW = app.globalData.windowWidth - touches[0].clientX
  88. let remainingH = app.globalData.windowHeight - touches[0].clientY
  89. let menuH = this.data.menuH
  90. let wFlag = remainingW - 145 > 0
  91. let hFlag = remainingH - menuH + 10 > 0
  92. let {
  93. receiverUid,
  94. senderUid
  95. } = currentTarget.dataset.item
  96. this.setData({
  97. targetId: receiverUid != this.data.uid ? receiverUid : senderUid,
  98. isTop: currentTarget.dataset.top,
  99. menu: {
  100. show: true,
  101. top: hFlag ? touches[0].clientY : touches[0].clientY - menuH,
  102. left: wFlag ? touches[0].clientX : touches[0].clientX - 135,
  103. }
  104. })
  105. },
  106. cancelMenu() {
  107. this.setData({
  108. 'menu.show': false
  109. })
  110. },
  111. async msgTopping() {
  112. await msgTopping({
  113. topUid: this.data.targetId
  114. })
  115. this.cancelMenu()
  116. this.getAuthorityMsg()
  117. this.resetData()
  118. },
  119. delMessage() {
  120. this.setData({
  121. 'menu.show': false
  122. })
  123. },
  124. jump({
  125. currentTarget
  126. }) {
  127. wx.navigateTo({
  128. url: `/pages/${currentTarget.dataset.url}/index`,
  129. })
  130. },
  131. jumpChat({
  132. currentTarget
  133. }) {
  134. let {
  135. nickName,
  136. eid,
  137. uid
  138. } = currentTarget.dataset.item.user
  139. wx.navigateTo({
  140. url: `/pages/chat/index?title=${nickName||eid}&uid=${uid}`,
  141. })
  142. },
  143. onReachBottom() {
  144. this.loadMore()
  145. }
  146. })