index.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. import {
  2. getOtherUser,
  3. setFans
  4. } from '~/api/user';
  5. import reachBottom from '~/mixins/reachBottom';
  6. Page({
  7. behaviors: [reachBottom],
  8. data: {
  9. text: '',
  10. historySearch: [],
  11. localUid: wx.getStorageSync('uid')
  12. },
  13. onShow() {
  14. // isEachOther 是否互相关注 isFans是否被关注 isFansOther是否关注别人
  15. this.setData({
  16. historySearch: wx.getStorageSync('userSearch')
  17. });
  18. this.resetData();
  19. },
  20. setSearch({
  21. detail
  22. }) {
  23. if (!detail.value) {
  24. this.setData({
  25. nullList: false,
  26. list: []
  27. });
  28. }
  29. this.setData({
  30. text: detail.value
  31. });
  32. },
  33. searchUser({
  34. currentTarget
  35. }) {
  36. if (currentTarget.dataset.text) {
  37. this.setData({
  38. text: currentTarget.dataset.text
  39. });
  40. }
  41. if (!this.data.text) {
  42. this.setData({
  43. list: []
  44. });
  45. return;
  46. }
  47. this.resetData();
  48. if (!this.data.historySearch.includes(this.data.text)) {
  49. this.setData({
  50. historySearch: [this.data.text, ...this.data.historySearch].slice(0, 20)
  51. });
  52. }
  53. wx.setStorageSync('userSearch', this.data.historySearch);
  54. },
  55. deleteHistory({
  56. currentTarget
  57. }) {
  58. let newList = this.data.historySearch.filter(item => {
  59. return item != currentTarget.dataset.text;
  60. });
  61. this.setData({
  62. historySearch: newList.slice(0, 20)
  63. });
  64. wx.setStorageSync('userSearch', this.data.historySearch);
  65. },
  66. clearHistory() {
  67. wx.showModal({
  68. title: '温馨提示',
  69. content: '历史记录清除后无法恢复,是否清除全部记录',
  70. success: res => {
  71. if (res.confirm) {
  72. this.setData({
  73. historySearch: []
  74. });
  75. wx.setStorageSync('search', this.data.historySearch);
  76. }
  77. }
  78. });
  79. },
  80. loadMore() {
  81. if (!this.data.text) {
  82. return;
  83. }
  84. this.getData(getOtherUser, {
  85. query: this.data.text
  86. });
  87. },
  88. jumpUserInfo({
  89. currentTarget
  90. }) {
  91. let uid = currentTarget.dataset.uid;
  92. wx.navigateTo({
  93. url: `/pages/personal/index?uid=${uid}`
  94. });
  95. },
  96. async setFans({
  97. currentTarget
  98. }) {
  99. if (!currentTarget.dataset.iseachother) {
  100. await setFans({
  101. uid: currentTarget.dataset.uid
  102. });
  103. let listCopy = JSON.parse(JSON.stringify(this.data.list));
  104. listCopy.forEach(item => {
  105. if (item.uid == currentTarget.dataset.uid) {
  106. item.isEachOther = true;
  107. }
  108. });
  109. this.setData({
  110. list: listCopy
  111. });
  112. wx.showToast({
  113. title: '已关注',
  114. icon: 'none'
  115. });
  116. }
  117. },
  118. sendMsg({
  119. currentTarget
  120. }) {
  121. let user = currentTarget.dataset.user
  122. let {
  123. nickName,
  124. eid,
  125. uid
  126. } = user
  127. if (this.data.localUid == uid) {
  128. return wx.showToast({
  129. title: '不可以给自己发私信哦~',
  130. icon: 'none'
  131. })
  132. }
  133. wx.navigateTo({
  134. url: `/pages/chat/index?title=${nickName||eid}&uid=${uid}`,
  135. })
  136. },
  137. clipboar({
  138. currentTarget
  139. }) {
  140. wx.setClipboardData({
  141. data: currentTarget.dataset.eid,
  142. success: function (res) { //成功回调函数
  143. wx.showToast({
  144. title: '已复制',
  145. icon: "none"
  146. })
  147. }
  148. })
  149. },
  150. onReachBottom() {
  151. this.loadMore();
  152. }
  153. });