index.js 2.7 KB

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