index.js 2.7 KB

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