index.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <template>
  2. <div class="container">
  3. <van-search
  4. class="search-item"
  5. v-model="value"
  6. show-action
  7. placeholder="请输入搜索关键词"
  8. >
  9. <template #left-icon>
  10. <svg-icon class="search-icon" name="search" />
  11. </template>
  12. <template #action>
  13. <van-button type="default" class="action-btn" @click="onSearch"
  14. >搜索</van-button
  15. >
  16. </template>
  17. </van-search>
  18. <div class="content">
  19. <div class="list-ul">
  20. <div
  21. class="list-li"
  22. v-for="(item, index) in groupArrDic"
  23. :key="item.groupId"
  24. @click="goToPage(item)"
  25. >
  26. <groupAvatar
  27. class="li-img"
  28. :users="item.avatars"
  29. ></groupAvatar>
  30. <div
  31. class="li-cont"
  32. :class="{
  33. 'no-border': index === groupArrDic.length - 1
  34. }"
  35. >
  36. {{ item.sessionName || '群聊' }}
  37. </div>
  38. </div>
  39. <div v-if="!groupArrDic.length" class="empty">暂无搜索结果</div>
  40. </div>
  41. </div>
  42. </div>
  43. </template>
  44. <script setup>
  45. import { ref, onMounted, watch } from 'vue';
  46. import { useWebSocketStore } from '@/stores/modules/webSocketStore.js';
  47. import { userList } from '@/api/path/im.api';
  48. import { useRoute, useRouter } from 'vue-router';
  49. import groupAvatar from '../../components/groupAvatar/index.vue';
  50. import { useWalletStore } from "@/stores/modules/walletStore";
  51. const router = useRouter();
  52. const wsStore = useWebSocketStore();
  53. const walletStore = useWalletStore();
  54. const allGroupArr = ref([]); // 接口原始数据
  55. const groupArrDic = ref([]); // 搜索展示数据
  56. const value = ref(''); // 搜索关键字
  57. // 获取群列表接口
  58. const getuserList = async () => {
  59. const res = await userList({
  60. uuid: walletStore.account,
  61. category: 'group'
  62. });
  63. allGroupArr.value = res.data || [];
  64. groupArrDic.value = [...allGroupArr.value];
  65. };
  66. // 搜索监听
  67. watch(value, newVal => {
  68. const keyword = newVal.trim().toLowerCase();
  69. if (!keyword) {
  70. groupArrDic.value = [...allGroupArr.value];
  71. } else {
  72. groupArrDic.value = allGroupArr.value.filter(item =>
  73. (item.sessionName || '群聊').toLowerCase().includes(keyword)
  74. );
  75. }
  76. });
  77. // 点击搜索按钮
  78. const onSearch = () => {
  79. const keyword = value.value.trim().toLowerCase();
  80. if (!keyword) {
  81. groupArrDic.value = [...allGroupArr.value];
  82. return;
  83. }
  84. groupArrDic.value = allGroupArr.value.filter(item =>
  85. (item.sessionName || '群聊').toLowerCase().includes(keyword)
  86. );
  87. };
  88. // 点击进入聊天页
  89. const goToPage = item => {
  90. wsStore.toUserInfo = {
  91. ...item,
  92. // avatar: item.users,
  93. // id: item.groupId,
  94. // nickname: item.sessionName || '群聊',
  95. type: 'group'
  96. };
  97. router.push({
  98. path: '/chat',
  99. query: { uuid: item.uuid }
  100. });
  101. };
  102. onMounted(() => {
  103. getuserList();
  104. });
  105. </script>
  106. <style lang="less" scoped>
  107. .container {
  108. height: 100%;
  109. display: flex;
  110. flex-direction: column;
  111. :deep(.van-search) {
  112. padding: 4px 16px !important;
  113. }
  114. :deep(.van-field__control) {
  115. font-family:
  116. PingFang SC,
  117. PingFang SC;
  118. font-weight: 500;
  119. font-size: 15px;
  120. color: #95a9ed;
  121. }
  122. .search-item {
  123. :deep(.van-search__action) {
  124. padding: 0 0 0 12px !important;
  125. box-sizing: border-box !important;
  126. line-height: initial !important;
  127. }
  128. :deep(.van-search__content) {
  129. background: #f7f8fa !important;
  130. border-radius: 22px !important;
  131. padding-left: 10px !important;
  132. padding-right: 10px;
  133. }
  134. :deep(.van-field__left-icon) {
  135. margin-right: 0 !important;
  136. height: 24px;
  137. }
  138. :deep(.van-search__field) {
  139. padding: 4px 0 !important;
  140. line-height: initial !important;
  141. box-sizing: border-box;
  142. }
  143. :deep(.van-field__value) {
  144. height: 24px !important;
  145. line-height: 26px !important;
  146. }
  147. .search-icon {
  148. height: 24px;
  149. width: 24px;
  150. margin-right: 10px;
  151. color: #95a9ed;
  152. }
  153. .action-btn {
  154. padding: 0 22px;
  155. height: 34px;
  156. box-sizing: border-box;
  157. background: #4765dd;
  158. border-radius: 22px;
  159. font-family:
  160. PingFang SC,
  161. PingFang SC;
  162. font-weight: 500;
  163. font-size: 15px;
  164. color: #ffffff;
  165. border: none !important;
  166. }
  167. }
  168. .search-item :deep(input::placeholder) {
  169. font-family:
  170. PingFang SC,
  171. PingFang SC;
  172. font-weight: 500;
  173. font-size: 15px;
  174. color: #95a9ed;
  175. }
  176. .content {
  177. margin: 16px;
  178. overflow: auto;
  179. .list-ul {
  180. background: #fff;
  181. border-radius: 12px;
  182. padding: 0 16px;
  183. .list-li {
  184. display: flex;
  185. align-items: center;
  186. border-bottom: 1px solid #f2f2f2;
  187. padding: 10px 0;
  188. .li-img {
  189. width: 32px;
  190. height: 32px;
  191. }
  192. .li-cont {
  193. flex: 1;
  194. display: flex;
  195. align-items: center;
  196. font-family:
  197. PingFang SC,
  198. PingFang SC;
  199. font-weight: 400;
  200. font-size: 15px;
  201. color: #8d8d8d;
  202. }
  203. .no-border {
  204. border-bottom: none;
  205. }
  206. }
  207. .empty {
  208. padding: 20px 0;
  209. text-align: center;
  210. color: #aaa;
  211. font-size: 14px;
  212. }
  213. }
  214. }
  215. .content::-webkit-scrollbar{
  216. width: 0;
  217. }
  218. }
  219. </style>