index.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. <template>
  2. <div class="container">
  3. <div class="head-bg"/>
  4. <div class="message-header">
  5. <div class="header-lf">
  6. <div
  7. class="msg"
  8. :class="{ 'active-color': activeTab === 0 }"
  9. @click="activeTab = 0"
  10. >
  11. 消息
  12. <span v-if="showDot&&activeTab == 0" class="red-dot"></span>
  13. </div>
  14. <div
  15. class="discover"
  16. :class="{ 'active-color': activeTab === 1 }"
  17. @click="activeTab = 1"
  18. >
  19. 发现
  20. <span v-if="showDot&&activeTab == 1" class="red-dot"></span>
  21. </div>
  22. </div>
  23. <div class="header-ri">
  24. <svg-icon style="width: 25px; height: 25px;margin-right: 8px;" name="person" @click="goToPage('contact')"/>
  25. <svg-icon style="width: 25px; height: 25px;" name="add" @click="showSheet = true;"/>
  26. </div>
  27. </div>
  28. <template v-if="activeTab === 0">
  29. <div class="search">
  30. <svg-icon class="search-icon" name="search" />
  31. <span>请输入关键词</span>
  32. </div>
  33. <div class="message-list">
  34. <div class="list-item" v-for="(item,i) in list" :key="i" @click="goToChat(item.uuid)">
  35. <van-image class="item-img" round :src="item.avatar"/>
  36. <div class="item-content">
  37. <div class="item-top">
  38. <div>{{item.nickname}}</div>
  39. <div class="col">{{item.createAt}}</div>
  40. </div>
  41. <div class="item-bottom">
  42. <div class="col m-ellipsis">我们已经相互关注,开始聊天吧</div>
  43. <div class="notice" v-if="notice">1</div>
  44. </div>
  45. </div>
  46. </div>
  47. </div>
  48. </template>
  49. <template v-else>
  50. <Discover />
  51. </template>
  52. <van-action-sheet
  53. v-model:show="showSheet"
  54. cancel-text="取消"
  55. close-on-click-action
  56. @cancel="showSheet = false"
  57. >
  58. <div class="sheet-content">
  59. <div class="sheet-li" @click="goToPage('search')">
  60. <svg-icon class="sheet-icon" name="add-friend" />
  61. <div class="sheet-text">添加朋友</div>
  62. </div>
  63. <div class="sheet-li" @click="goToPage('createGroupChat')">
  64. <svg-icon class="sheet-icon" name="group-chat" />
  65. <div class="sheet-text">创建群聊</div>
  66. </div>
  67. <div class="sheet-li no-border">
  68. <svg-icon class="sheet-icon" name="sm1"/>
  69. <div class="sheet-text">扫一扫</div>
  70. </div>
  71. </div>
  72. </van-action-sheet>
  73. </div>
  74. </template>
  75. <script setup>
  76. import { useWalletStore } from "@/stores/modules/walletStore";
  77. import { userList } from "@/api/path/im.api";
  78. import { ref } from 'vue'
  79. import { useRouter } from 'vue-router'
  80. import Discover from './components/Discover/Discover.vue'
  81. import { useWebSocketStore } from "@/stores/modules/webSocketStore.js"
  82. const walletStore = useWalletStore();
  83. const router = useRouter();
  84. const wsStore = useWebSocketStore()
  85. const activeTab = ref(0)
  86. const showDot = ref(true)
  87. const showSheet = ref(false);
  88. const list = ref([]);
  89. const notice = ref(false)
  90. const getuserList = async () => {
  91. const res = await userList({uuid:walletStore.account});
  92. list.value = res.data;
  93. }
  94. const goToChat = (uuid) => {
  95. router.push({
  96. path: 'chat',
  97. query:{uuid}
  98. })
  99. }
  100. const goToPage = (url) => {
  101. router.push(url)
  102. }
  103. onMounted(()=>{
  104. getuserList();
  105. wsStore.connect(walletStore.getAccount)
  106. })
  107. onUnmounted(() => {
  108. wsStore.close()
  109. })
  110. </script>
  111. <style lang="less" scoped>
  112. .container{
  113. height: calc(100vh - 60px);
  114. display: flex;
  115. flex-direction: column;
  116. .head-bg {
  117. .fn-head-bg()
  118. }
  119. .message-header{
  120. margin: 52px 16px 18px;
  121. display: flex;
  122. justify-content: space-between;
  123. align-items: center;
  124. .header-lf{
  125. display: flex;
  126. align-items: center;
  127. font-family: PingFang SC, PingFang SC;
  128. font-weight: 400;
  129. font-size: 15px;
  130. color: #4F4F4F;
  131. .msg, .discover {
  132. margin-right: 12px;
  133. position: relative;
  134. cursor: pointer;
  135. color: #4F4F4F;
  136. }
  137. .active-color {
  138. font-size: 19px;
  139. font-weight: 500;
  140. color: #000;
  141. }
  142. .red-dot {
  143. position: absolute;
  144. top: 0px;
  145. right: -4px;
  146. width: 6px;
  147. height: 6px;
  148. background: #FF6C6C;
  149. border-radius: 50%;
  150. display: inline-block;
  151. }
  152. }
  153. .header-ri{
  154. display: flex;
  155. align-items: center;
  156. }
  157. }
  158. .search{
  159. margin-bottom: 16px;
  160. height: 33px;
  161. background: #FFFFFF;
  162. border-radius: 23px;
  163. opacity: 0.5;
  164. padding: 6px;
  165. box-sizing: border-box;
  166. margin: 0 16px;
  167. font-family: PingFang SC, PingFang SC;
  168. font-weight: 500;
  169. font-size: 15px;
  170. color: #95A9ED;
  171. display: flex;
  172. align-items: center;
  173. .search-icon{
  174. height: 25px;
  175. width: 25px;
  176. margin-right: 6px;
  177. }
  178. }
  179. .message-list{
  180. background: #F7F8FA;
  181. border-radius: 30px 30px 0 0;
  182. flex: 1;
  183. overflow: auto;
  184. margin-top: 16px;
  185. padding: 26px 16px 0;
  186. .list-item{
  187. margin-bottom: 26px;
  188. display: flex;
  189. align-items: center;
  190. .item-img{
  191. width:42px;
  192. height:42px;
  193. flex-shrink: 0;
  194. margin-right: 12px;
  195. }
  196. .item-content{
  197. flex: 1;
  198. overflow: hidden;
  199. .item-top,.item-bottom{
  200. display: flex;
  201. align-items: center;
  202. justify-content: space-between;
  203. font-family: PingFang SC, PingFang SC;
  204. font-weight: 400;
  205. font-size: 15px;
  206. color: #000000;
  207. .col{
  208. font-size: 12px;
  209. color: #8D8D8D;
  210. }
  211. }
  212. .item-top{
  213. margin-bottom: 2px;
  214. }
  215. .item-bottom{
  216. .notice{
  217. min-width: 15px;
  218. height: 15px;
  219. line-height: 15px;
  220. background-color: #FF6C6C;
  221. font-size: 10px;
  222. color: #FFFFFF;
  223. text-align: center;
  224. border-radius: 50px;
  225. margin-left: 5px;
  226. }
  227. .m-ellipsis{
  228. overflow: hidden;
  229. white-space: nowrap;
  230. text-overflow: ellipsis;
  231. }
  232. }
  233. }
  234. }
  235. }
  236. .message-list::-webkit-scrollbar{
  237. width: 0;
  238. }
  239. .discover-list {
  240. flex: 1;
  241. display: flex;
  242. justify-content: center;
  243. align-items: center;
  244. background: #F7F8FA;
  245. border-radius: 30px 30px 0 0;
  246. margin-top: 16px;
  247. padding: 26px 16px 0;
  248. }
  249. .sheet-content{
  250. font-family: PingFang SC, PingFang SC;
  251. font-weight: 500;
  252. font-size: 15px;
  253. color: #000000;
  254. padding: 12px 16px 0;
  255. .sheet-li{
  256. display: flex;
  257. align-items: center;
  258. justify-content: center;
  259. border-bottom: 1px solid #F2F2F2;
  260. padding: 10px 0;
  261. .sheet-icon{
  262. width:20px;
  263. height:20px;
  264. }
  265. .sheet-text{
  266. text-align: center;
  267. width: 70px;
  268. }
  269. }
  270. .no-border{
  271. border-bottom:none;
  272. }
  273. }
  274. :deep(.van-action-sheet__cancel){
  275. font-family: PingFang SC, PingFang SC;
  276. font-weight: 500 !important;
  277. font-size: 15px !important;
  278. color: #FF0000 !important;
  279. }
  280. }
  281. </style>