index.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <template>
  2. <div class="container">
  3. <div class="content">
  4. <div class="tab-box">
  5. <div class="tab-text" :class="type == 1?'active-color':''" @click="changeTab(1)">我收到的</div>
  6. <div class="tab-text" :class="type == 2?'active-color':''" @click="changeTab(2)">我发起的</div>
  7. </div>
  8. <div class="list-box">
  9. <van-loading class="load-box" size="24px" v-if="loading">加载中...</van-loading>
  10. <template v-else-if="list.length > 0">
  11. <div class="box-item" :class="{ 'no-border': i === 9 }" v-for="(item,i) in list">
  12. <van-image class="item-img" round src="https://fastly.jsdelivr.net/npm/@vant/assets/cat.jpeg"/>
  13. <div class="item-ri-cont">
  14. <div>
  15. <div v-if="type == 1">
  16. <span class="name">{{ item.nickname }}</span>申请添加您为好友
  17. </div>
  18. <div v-else-if="type == 2">
  19. 请求添加<span class="name">{{ item.nickname }}</span>为好友
  20. </div>
  21. </div>
  22. <!-- 左边操作按钮或文字 -->
  23. <div v-if="type == 1 && item.status == 1" class="item-btn" @click="changeBtn(item)">同意</div>
  24. <div v-else-if="type == 2 && item.status == 1" class="fs12 fs90">待同意</div>
  25. <!-- 右边状态展示(仅 status ≠ 1 时) -->
  26. <div
  27. v-if="item.status !== 1"
  28. class="fs12"
  29. :class="item.status == 2 ? '' : 'fscolor'"
  30. >
  31. {{ item.status == 2 ? '已添加' : '已拒绝' }}
  32. </div>
  33. </div>
  34. </div>
  35. </template>
  36. <template v-else>
  37. <div class="no-more">
  38. <svg-icon class="no-more-img" name="no-more" />
  39. <div>暂无数据</div>
  40. </div>
  41. </template>
  42. </div>
  43. <!-- <div class="foot-page">
  44. <van-button class="foot-btn" size="mini">上一页</van-button>
  45. <div class="foot-total">1/1</div>
  46. <van-button class="foot-btn" size="mini">下一页</van-button>
  47. </div> -->
  48. </div>
  49. <!-- 同意好友弹框 -->
  50. <van-popup v-model:show="showAgree" :style="{ borderRadius:'25px' }">
  51. <div class="pop-content-password">
  52. <div class="pop-title-password">你确定同意该好友的请求吗?</div>
  53. <div class="pop-btn-password" style="margin-top: 50px;">
  54. <van-button type="default" class="btn-password cancel" @click="changeFun(3)">拒绝</van-button>
  55. <van-button type="default" class="btn-password confirm" @click="changeFun(2)">同意</van-button>
  56. </div>
  57. </div>
  58. </van-popup>
  59. </div>
  60. </template>
  61. <script setup>
  62. import { friendRequest,friendAudit } from "@/api/path/im.api";
  63. import { showToast } from 'vant';
  64. import { useWalletStore } from "@/stores/modules/walletStore";
  65. const walletStore = useWalletStore();
  66. const type = ref(1);
  67. const showAgree = ref(false);
  68. const list = ref([]);
  69. const activeItem = ref({});
  70. const loading = ref(false);
  71. const getfriendRequest = async () => {
  72. loading.value = true;
  73. try {
  74. const res = await friendRequest({ uuid: walletStore.account, status: type.value });
  75. list.value = res.data || [];
  76. } finally {
  77. loading.value = false;
  78. }
  79. }
  80. const changeBtn = (item) => {
  81. showAgree.value = true;
  82. activeItem.value = item;
  83. }
  84. const changeTab = (val) => {
  85. type.value = val;
  86. list.value = [];
  87. getfriendRequest();
  88. }
  89. //他弹框是否同意
  90. const changeFun = async (val) => {
  91. const res = await friendAudit({uuid:walletStore.account,status:val,friendUsername:activeItem.value.uuid});
  92. if(res.code == 200){
  93. let text = val == 2?'添加成功':'已拒绝'
  94. showToast(text);
  95. list.value = [];
  96. getfriendRequest();
  97. }
  98. showAgree.value = false;
  99. }
  100. onMounted(()=>{
  101. getfriendRequest();
  102. })
  103. </script>
  104. <style lang="less" scoped>
  105. .load-box{
  106. text-align: center !important;
  107. margin-top: 50px !important;
  108. }
  109. .container{
  110. height: 100%;
  111. display: flex;
  112. flex-direction: column;
  113. .content{
  114. display: flex;
  115. flex-direction: column;
  116. height: 100%;
  117. .tab-box{
  118. display: flex;
  119. align-items: center;
  120. font-family: PingFang SC, PingFang SC;
  121. font-weight: 400;
  122. font-size: 15px;
  123. color: #4F4F4F;
  124. height: 42px;
  125. line-height: 42px;
  126. background-color: #fff;
  127. .tab-text{
  128. width: 50%;
  129. text-align: center;
  130. }
  131. .active-color{
  132. font-weight: 500;
  133. color: #4765DD;
  134. }
  135. }
  136. .list-box{
  137. background: #fff;
  138. margin: 8px 16px;
  139. border-radius: 12px;
  140. padding: 0 16px;
  141. flex: 1;
  142. overflow: auto;
  143. .box-item{
  144. padding: 12px 0 10px;
  145. border-bottom: 1px solid #F2F2F2;
  146. display: flex;
  147. align-items: center;
  148. font-family: PingFang SC, PingFang SC;
  149. font-weight: 400;
  150. font-size: 15px;
  151. color: #8D8D8D;
  152. .item-img{
  153. width: 32px;
  154. height: 32px;
  155. flex-shrink: 0;
  156. margin-right: 12px;
  157. }
  158. .item-ri-cont{
  159. flex: 1;
  160. display: flex;
  161. align-items: center;
  162. justify-content: space-between;
  163. .name{
  164. color: #4765DD;
  165. }
  166. .item-btn{
  167. background: #4765DD;
  168. border-radius: 6px;
  169. padding: 4px 8px;
  170. box-sizing: border-box;
  171. font-family: PingFang SC, PingFang SC;
  172. font-weight: 400;
  173. font-size: 12px;
  174. color: #FFFFFF;
  175. }
  176. .fs12{
  177. font-size: 12px;
  178. }
  179. .fscolor{
  180. color: #FF0000;
  181. }
  182. .fs90{
  183. color: #FF9000;
  184. }
  185. }
  186. }
  187. .no-border{
  188. border-bottom: none;
  189. }
  190. }
  191. .list-box::-webkit-scrollbar{
  192. width: 0;
  193. }
  194. .foot-page{
  195. display: flex;
  196. align-items: center;
  197. height: 44px;
  198. background: #FFFFFF;
  199. padding: 10px 16px;
  200. box-sizing: border-box;
  201. .foot-btn{
  202. box-sizing: border-box;
  203. width: 50px;
  204. border-radius: 4px;
  205. padding: 4px 6px;
  206. background: #F2F2F2;
  207. font-family: PingFang SC, PingFang SC;
  208. font-weight: 400;
  209. font-size: 12px;
  210. color: #4F4F4F;
  211. }
  212. .foot-total{
  213. flex: 1;
  214. text-align: center;
  215. font-family: PingFang SC, PingFang SC;
  216. font-weight: 400;
  217. font-size: 12px;
  218. color: #4F4F4F;
  219. }
  220. }
  221. }
  222. .pop-content-password{
  223. padding: 27px 35px 25px 34px;
  224. .pop-title-password{
  225. font-family: PingFang SC, PingFang SC;
  226. font-weight: 500;
  227. font-size: 17px;
  228. color: #000000;
  229. text-align: center;
  230. }
  231. .pop-input{
  232. background: #F2F2F2;
  233. border-radius: 8px;
  234. height: 40px;
  235. margin: 21px 0 31px;
  236. }
  237. .pop-btn-password{
  238. display: flex;
  239. justify-content: center;
  240. .btn-password{
  241. width: 83px;
  242. height: 29px;
  243. line-height: 29px;
  244. padding: 5px 0 !important;
  245. border-radius: 6px;
  246. font-family: PingFang SC, PingFang SC;
  247. font-weight: 400;
  248. font-size: 15px;
  249. box-sizing:border-box;
  250. }
  251. .cancel{
  252. margin-right: 17px !important;
  253. border: 1px solid #D8D8D8;
  254. color: #000 !important;
  255. }
  256. .confirm{
  257. background: @theme-color1;
  258. color: #FFF;
  259. font-weight: 500;
  260. border: none !important;
  261. }
  262. }
  263. }
  264. :deep(.van-popup--center) {
  265. margin: 0 40px !important;
  266. width: auto !important;
  267. }
  268. .no-more{
  269. margin-top: 178px;
  270. text-align: center;
  271. font-family: PingFang SC, PingFang SC;
  272. font-weight: 400;
  273. font-size: 15px;
  274. color: #8D8D8D;
  275. .no-more-img{
  276. width: 302px;
  277. height: 222px;
  278. }
  279. }
  280. }
  281. </style>