invite.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <page-meta :page-font-size="fontValue+'px'" :root-font-size="fontValue+'px'"></page-meta>
  3. <cu-custom bgImage="/static/bg.png" :isBack="true">
  4. <template v-slot:content>
  5. <text class="text-black">入群审核</text>
  6. </template>
  7. </cu-custom>
  8. <view class="cu-list menu">
  9. <view class="cu-item" v-for="(item) in list" :key="item.id">
  10. <view class="content">
  11. <text class="cuIcon-circlefill text-black"></text>
  12. <text class="text-black"><user-name-tag :id="item.fromId" /></text>
  13. <text class="text-black">-邀请了-</text>
  14. <text class="text-black"><user-name-tag :id="item.userId" /></text>
  15. </view>
  16. <view class="action">
  17. <button class="cu-btn round bg-red shadow sm" @tap="refuse(item.id)">拒绝</button>
  18. <button class="cu-btn round bg-green shadow sm margin-left" @tap="agree(item.id,item.userId)">同意</button>
  19. </view>
  20. </view>
  21. </view>
  22. <no-data v-if="list.length === 0"/>
  23. </template>
  24. <script setup lang="ts">
  25. import CuCustom from '@/colorui/components/cu-custom.vue'
  26. import UserNameTag from '@/components/UserNameTag.vue'
  27. import GroupInviteApi from "@/api/GroupInviteApi";
  28. import {ref} from "vue";
  29. import {onLoad} from "@dcloudio/uni-app";
  30. import {useUserStore} from "@/store/userStore";
  31. import type Message from "@/mode/Message";
  32. import MessageType from "@/utils/MessageType";
  33. import ChatType from "@/utils/ChatType";
  34. import {useWsStore} from "@/store/WsStore";
  35. import {useGroupStore} from "@/store/groupStore";
  36. import NoData from "@/components/NoData.vue";
  37. import Auth from "@/api/Auth";
  38. const fontValue=ref(Auth.getfontSize());
  39. const userStore = useUserStore();
  40. const wsStore = useWsStore();
  41. const user = userStore.getUser();
  42. const list = ref([]);
  43. const groupId = ref("");
  44. onLoad((opt) => {
  45. groupId.value = opt?.id;
  46. loadData();
  47. })
  48. /**
  49. * 获取邀请列表
  50. */
  51. const loadData = () => {
  52. GroupInviteApi.list(groupId.value).then((res) => {
  53. list.value = res?.data;
  54. });
  55. }
  56. /**
  57. * 同意邀请
  58. * @param id 邀请id
  59. * @param userId userId
  60. */
  61. const agree = (id: string, userId: string) => {
  62. GroupInviteApi.agree(id).then(() => {
  63. list.value = list.value.filter((item) => item.id !== id);
  64. if (user) {
  65. const content = "新用户 " + userStore.userMap.get(userId)?.name + " 入群";
  66. let msg: Message = {
  67. messageType: MessageType.text,
  68. chatId: groupId.value,
  69. fromId: user.id,
  70. mine: true,
  71. content: content,
  72. timestamp: new Date().getTime(),
  73. type: ChatType.GROUP,
  74. };
  75. wsStore.sendMessage(msg);
  76. useGroupStore().loadWaitCheckList()
  77. }
  78. });
  79. };
  80. /**
  81. * 拒绝邀请
  82. * @param id 邀请id
  83. */
  84. const refuse = (id: string) => {
  85. GroupInviteApi.refuse(id).then(() => {
  86. list.value = list.value.filter((item) => item.id !== id);
  87. });
  88. };
  89. </script>
  90. <style scoped>
  91. </style>