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