index.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. pageSize: 20
  51. })
  52. },
  53. setSearch({
  54. detail
  55. }) {
  56. /* console.log(detail)
  57. if (!detail.value) {
  58. this.setData({
  59. nullList: false,
  60. list: []
  61. });
  62. }
  63. this.setData({
  64. text: detail.value
  65. }); */
  66. },
  67. async search() {
  68. if (!this.data.text) {
  69. this.setData({
  70. list: []
  71. });
  72. return;
  73. }
  74. this.setData({
  75. list,
  76. });
  77. },
  78. onLongPress(e) {
  79. console.log(e);
  80. let {
  81. currentTarget,
  82. detail,
  83. touches,
  84. target
  85. } = e
  86. let remainingW = app.globalData.windowWidth - touches[0].clientX
  87. let remainingH = app.globalData.windowHeight - touches[0].clientY
  88. let menuH = this.data.menuH
  89. let wFlag = remainingW - 145 > 0
  90. let hFlag = remainingH - menuH + 10 > 0
  91. let {
  92. receiverUid,
  93. senderUid
  94. } = currentTarget.dataset.item
  95. this.setData({
  96. targetId: receiverUid != this.data.uid ? receiverUid : senderUid,
  97. isTop: currentTarget.dataset.top,
  98. menu: {
  99. show: true,
  100. top: hFlag ? touches[0].clientY : touches[0].clientY - menuH,
  101. left: wFlag ? touches[0].clientX : touches[0].clientX - 135,
  102. }
  103. })
  104. },
  105. cancelMenu() {
  106. this.setData({
  107. 'menu.show': false
  108. })
  109. },
  110. async msgTopping() {
  111. await msgTopping({
  112. topUid: this.data.targetId
  113. })
  114. this.cancelMenu()
  115. this.getAuthorityMsg()
  116. this.resetData()
  117. },
  118. delMessage() {
  119. this.setData({
  120. 'menu.show': false
  121. })
  122. },
  123. jump({
  124. currentTarget
  125. }) {
  126. wx.navigateTo({
  127. url: `/pages/${currentTarget.dataset.url}/index`,
  128. })
  129. },
  130. jumpChat({
  131. currentTarget
  132. }) {
  133. let {
  134. nickName,
  135. eid,
  136. uid
  137. } = currentTarget.dataset.item.user
  138. wx.navigateTo({
  139. url: `/pages/chat/index?title=${nickName||eid}&uid=${uid}`,
  140. })
  141. },
  142. onReachBottom() {
  143. this.loadMore()
  144. }
  145. })