index.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <template>
  2. <!-- <view class="chat_content" @touchmove.stop.prevent> -->
  3. <view>
  4. <cu-custom bgImage="/static/barBG.png" :isBack="false">
  5. <template v-slot:content>
  6. <text style="letter-spacing: 4rpx;font-style: italic;color:black;font-weight: bold;">通讯录</text>
  7. </template>
  8. <template v-slot:right>
  9. <text class="cuIcon cuIcon-add text-black text-bold" @tap="newFriend"></text>
  10. </template>
  11. </cu-custom>
  12. <view class="cu-bar bg-white solid-bottom margin-top" @tap="toValidateFriend">
  13. <view class="action">
  14. <text class="cuIcon-title text-orange"></text>
  15. <text class="text-black text-bold">新的朋友</text>
  16. </view>
  17. <view class="action">
  18. <view class="cu-tag bg-cyan" v-if="friendStore.waitValidateList.length>0">{{ friendStore.waitValidateList.length }}</view>
  19. </view>
  20. </view>
  21. <!-- <index-bar :index-map="map" :bottom="true" class="tab-bar-mar"> -->
  22. <view v-for="(item,key) in map.keys()" :key="key">
  23. <view :class="'indexItem-' + item" :id="'indexes-' + item" :data-index="item">
  24. <view class="padding">{{ item }}</view>
  25. <view class="cu-list menu-avatar no-padding">
  26. <view class="cu-item" v-for="(user) in map.get(item)" :key="user.id" @touchmove="handleListTouchMove"
  27. @touchstart="handleListTouchStart" @touchend="handleListTouchEnd" :data-target="'move-box-' + user.id"
  28. :class="modalName==='move-box-'+ user.id?'move-cur':''" @tap="showFriend(user.id)">
  29. <vim-avatar :img="user.avatar" :name="user.name" />
  30. <view class="content">
  31. <view class="text-black text-jiachu">{{ user.name }}</view>
  32. <view class="text-black text-sm">
  33. {{ user.name }}
  34. </view>
  35. </view>
  36. <view class="move">
  37. <view class="bg-red" @tap.stop="delFriend(user.id)">删除</view>
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. </view>
  43. <view style="height: 150rpx;"></view>
  44. <!-- </index-bar> -->
  45. <view class="cu-modal" :class="show?'show':''">
  46. <view class="cu-dialog">
  47. <view class="cu-bar bg-white justify-end">
  48. <view class="content text-black text-bold">添加好友</view>
  49. <view class="action" @tap="hideModal">
  50. <text class="cuIcon-close text-red text-bold"></text>
  51. </view>
  52. </view>
  53. <view class="bg-white">
  54. <view class="cu-bar search bg-white">
  55. <view class="search-form">
  56. <text class="cuIcon-search"></text>
  57. <input type="text" v-model="mobile" placeholder="搜索用户名或手机号" confirm-type="search"/>
  58. </view>
  59. <view class="action">
  60. <button class="cu-btn bg-green text-bold" @tap="search">搜索</button>
  61. </view>
  62. </view>
  63. <view class="cu-list menu-avatar" style='max-height: 20vh;overflow-y: scroll'>
  64. <view @click="check(user)" class="cu-item no-padding" v-for="(user) in users" :key="user.id">
  65. <vim-avatar :img="user.avatar" :name="user.name" />
  66. <view class="content">
  67. <view class="text-grey">{{ user.name }}</view>
  68. </view>
  69. <view class="action">
  70. <text class="cuIcon text-cyan" :class="user.id === checkedUserId?'cuIcon-check':''"></text>
  71. </view>
  72. </view>
  73. </view>
  74. </view>
  75. <view class='padding'>
  76. <textarea placeholder='验证消息' class='solid padding text-sm textarea bg-white' v-model='message'></textarea>
  77. </view>
  78. <view class="cu-bar bg-white">
  79. <view class="action margin-0 flex-sub text-green solid-left text-bold" @tap="hideModal">取消</view>
  80. <view class="action margin-0 flex-sub text-bold solid-left" @tap="addFriend">确定</view>
  81. </view>
  82. </view>
  83. </view>
  84. </view>
  85. </template>
  86. <script setup lang="ts">
  87. import {getCurrentInstance, ref} from "vue";
  88. import FriendApi from "@/api/FriendApi";
  89. import UserApi from "@/api/UserApi";
  90. import Tools from "@/utils/Tools";
  91. import MessageUtils from "@/utils/MessageUtils";
  92. import CuCustom from '@/colorui/components/cu-custom.vue'
  93. import IndexBar from '@/components/IndexBar.vue'
  94. import type User from "@/mode/User";
  95. import {useUserStore} from "@/store/userStore";
  96. import {useFriendStore} from "@/store/friendStore";
  97. import {handleListTouchEnd, handleListTouchMove, handleListTouchStart, modalName} from "@/hooks/useMoveMenu";
  98. import VimAvatar from "@/components/VimAvatar.vue";
  99. const friendStore = useFriendStore();
  100. //@ts-ignore
  101. const {proxy} = getCurrentInstance();
  102. const map = ref(new Map());
  103. const show = ref(false);
  104. const message = ref<string>("");
  105. const mobile = ref('');
  106. const checkedUserId = ref('');
  107. const userStore = useUserStore()
  108. const users = ref<User[]>([]);
  109. const check = (user: User) => {
  110. checkedUserId.value = user.id
  111. }
  112. const loadFriends = () => {
  113. FriendApi.friends().then(res => {
  114. console.log(res);
  115. map.value = Tools.listToMap(res.data);
  116. })
  117. UserApi.currentUser()
  118. .then((res) => {
  119. console.log('currentUser',res);
  120. userStore.setUser(res.data);
  121. uni.setStorageSync('userId', res.data.id)
  122. });
  123. }
  124. const search = () => {
  125. UserApi.search(mobile.value.trim()).then((res) => {
  126. users.value = res.data;
  127. });
  128. }
  129. const addFriend = () => {
  130. if (checkedUserId.value) {
  131. FriendApi.add({ friendId: checkedUserId.value, message: message.value })
  132. .then((res) => {
  133. loadFriends();
  134. MessageUtils.message(res.msg);
  135. friendStore.notifyFlushFriendStore(checkedUserId.value)
  136. show.value = false;
  137. })
  138. .catch((res) => {
  139. MessageUtils.message(res.msg);
  140. });
  141. }else {
  142. MessageUtils.message('请选择好友');
  143. }
  144. }
  145. /**
  146. * 删除好友
  147. */
  148. const delFriend = (friendId: string) => {
  149. uni.showModal({
  150. title: '提示',
  151. content: '是否删除好友?',
  152. cancelText: '取消',
  153. confirmText: '确定',
  154. success: res => {
  155. if (res.confirm) {
  156. FriendApi.delete(friendId).then(() => {
  157. loadFriends();
  158. });
  159. }
  160. }
  161. })
  162. };
  163. const showFriend = (id: string) => {
  164. console.log('currentUser',useUserStore().getUser())
  165. uni.navigateTo({
  166. url: '/pages/pub/user?id=' + id
  167. })
  168. };
  169. const newFriend = () => {
  170. message.value = '';
  171. show.value = true;
  172. }
  173. const toValidateFriend = () => {
  174. uni.navigateTo({
  175. url: '/pages/friend/validate'
  176. })
  177. }
  178. const hideModal = () => {
  179. show.value = false;
  180. }
  181. loadFriends();
  182. </script>
  183. <style scoped>
  184. .chat_content {
  185. position: fixed;
  186. top: 0;
  187. bottom: 0;
  188. left: 0;
  189. right: 0;
  190. overflow: hidden;
  191. }
  192. .cu-modal {
  193. z-index: 999;
  194. }
  195. .textarea{
  196. height: 10vh;
  197. width: 100%;
  198. }
  199. </style>