index.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <template>
  2. <div class="container">
  3. <div class="content">
  4. <div class="list-ul">
  5. <div class="list-li" @click="router.push('invitation')">
  6. <svg-icon class="li-img" name="yq" />
  7. <div class="li-cont">新邀请</div>
  8. </div>
  9. <div class="list-li" @click="router.push('group')">
  10. <svg-icon class="li-img" name="ql" />
  11. <div class="li-cont no-border">群聊</div>
  12. </div>
  13. <!-- <div class="list-li">
  14. <svg-icon class="li-img" name="tz" />
  15. <div class="li-cont no-border">系统通知</div>
  16. </div> -->
  17. </div>
  18. <van-index-bar>
  19. <template v-for="(group, groupIndex) in memberGroups" :key="group.index">
  20. <van-index-anchor :index="group.index" />
  21. <van-cell-group inset>
  22. <van-cell v-for="(item, index) in group.members">
  23. <template #title>
  24. <div class="cell-item">
  25. <van-image
  26. class="cell-img"
  27. round
  28. :src="item.avatar"
  29. />
  30. <div>{{ item.nickname }}</div>
  31. </div>
  32. </template>
  33. </van-cell>
  34. </van-cell-group>
  35. </template>
  36. </van-index-bar>
  37. <div class="total">{{memberGroups.length}}个朋友</div>
  38. </div>
  39. </div>
  40. </template>
  41. <script setup>
  42. import { userList } from "@/api/path/im.api";
  43. import {getFirstLetter} from "@/utils/utils";
  44. import { useWalletStore } from "@/stores/modules/walletStore";
  45. const router = useRouter();
  46. const walletStore = useWalletStore();
  47. const memberGroups = ref([]);
  48. const getuserList = async () => {
  49. const res = await userList({ uuid: walletStore.account });
  50. const groupedMap = {};
  51. res.data.forEach(user => {
  52. const name = user.nickname || '';
  53. const firstLetter = getFirstLetter(name); // 获取首字母
  54. if (!groupedMap[firstLetter]) {
  55. groupedMap[firstLetter] = [];
  56. }
  57. groupedMap[firstLetter].push({...user});
  58. });
  59. // 转为数组并按 index 排序
  60. const groupedList = Object.keys(groupedMap)
  61. .sort()
  62. .map(letter => ({
  63. index: letter,
  64. members: groupedMap[letter]
  65. }));
  66. memberGroups.value = groupedList;
  67. console.log(memberGroups.value)
  68. };
  69. onMounted(() => {
  70. getuserList();
  71. });
  72. </script>
  73. <style lang="less" scoped>
  74. .container{
  75. height: 100%;
  76. display: flex;
  77. flex-direction: column;
  78. .content{
  79. padding: 16px;
  80. overflow: auto;
  81. .list-ul{
  82. background: #fff;
  83. border-radius: 12px;
  84. padding: 12px 16px;
  85. .list-li{
  86. display: flex;
  87. align-items: center;
  88. .li-img{
  89. width: 32px;
  90. height: 32px;
  91. flex-shrink: 0;
  92. margin-right: 12px;
  93. }
  94. .li-cont{
  95. flex: 1;
  96. border-bottom: 1px solid #F2F2F2;
  97. padding-top:10px;
  98. padding-bottom: 10px;
  99. font-family: PingFang SC, PingFang SC;
  100. font-weight: 500;
  101. font-size: 15px;
  102. color: #000000;
  103. }
  104. .no-border {
  105. border-bottom: none;
  106. }
  107. }
  108. }
  109. :deep(.van-cell-group--inset){
  110. border-radius:12px !important;
  111. margin: 0 !important;
  112. }
  113. :deep(.van-cell){
  114. padding: 12px 16px !important;
  115. }
  116. :deep(.van-cell:after){
  117. left: 60px;
  118. }
  119. :deep(.van-index-anchor--sticky){
  120. background: #F7F8FA !important;
  121. color: #4765DD !important;
  122. }
  123. :deep(.van-index-bar__index){
  124. font-weight: 400 !important;
  125. font-size: 10px !important;
  126. color: #1D2129 !important;
  127. margin-bottom: 8px !important;
  128. }
  129. :deep(.van-index-bar__index--active){
  130. color: #4765DD !important;
  131. }
  132. .cell-item{
  133. display: flex;
  134. align-items: center;
  135. font-family: PingFang SC, PingFang SC;
  136. font-weight: 500;
  137. font-size: 15px;
  138. color: #000000;
  139. .cell-img{
  140. width: 32px;
  141. height: 32px;
  142. flex-shrink: 0;
  143. margin-right: 12px;
  144. }
  145. }
  146. .total{
  147. text-align: center;
  148. font-family: PingFang SC, PingFang SC;
  149. font-weight: 400;
  150. font-size: 12px;
  151. color: #8D8D8D;
  152. margin-top: 22px;
  153. }
  154. }
  155. .content::-webkit-scrollbar{
  156. width: 0;
  157. }
  158. }
  159. </style>