index.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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: 3
  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. console.log(authorityMsg);
  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. console.log(e);
  83. let {
  84. currentTarget,
  85. detail,
  86. touches,
  87. target
  88. } = e
  89. let remainingW = app.globalData.windowWidth - touches[0].clientX
  90. let remainingH = app.globalData.windowHeight - touches[0].clientY
  91. let menuH = this.data.menuH
  92. let wFlag = remainingW - 145 > 0
  93. let hFlag = remainingH - menuH + 10 > 0
  94. let {
  95. receiverUid,
  96. senderUid
  97. } = currentTarget.dataset.item
  98. this.setData({
  99. targetId: receiverUid != this.data.uid ? receiverUid : senderUid,
  100. isTop: currentTarget.dataset.top,
  101. menu: {
  102. show: true,
  103. top: hFlag ? touches[0].clientY : touches[0].clientY - menuH,
  104. left: wFlag ? touches[0].clientX : touches[0].clientX - 135,
  105. }
  106. })
  107. },
  108. cancelMenu() {
  109. this.setData({
  110. 'menu.show': false
  111. })
  112. },
  113. async msgTopping() {
  114. await msgTopping({
  115. topUid: this.data.targetId
  116. })
  117. this.cancelMenu()
  118. this.getAuthorityMsg()
  119. this.resetData()
  120. },
  121. delMessage() {
  122. this.setData({
  123. 'menu.show': false
  124. })
  125. },
  126. jump({
  127. currentTarget
  128. }) {
  129. wx.navigateTo({
  130. url: `/pages/${currentTarget.dataset.url}/index`,
  131. })
  132. },
  133. jumpChat({
  134. currentTarget
  135. }) {
  136. let {
  137. nickName,
  138. eid,
  139. uid
  140. } = currentTarget.dataset.item.user
  141. wx.navigateTo({
  142. url: `/pages/chat/index?title=${nickName||eid}&uid=${uid}`,
  143. })
  144. },
  145. onReachBottom() {
  146. this.loadMore()
  147. }
  148. })