index.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. <template>
  2. <div>
  3. <div v-if="groupApplicationCount > 0" class="application-tips">
  4. <div>
  5. {{ groupApplicationCount
  6. }}{{ TUITranslateService.t("TUIChat.条入群申请") }}
  7. </div>
  8. <div
  9. class="application-tips-btn"
  10. @click="toggleGroupApplicationDrawerShow"
  11. >
  12. {{ TUITranslateService.t("TUIChat.点击处理") }}
  13. </div>
  14. </div>
  15. <Drawer
  16. ref="drawerDomInstanceRef"
  17. :visible="isGroupApplicationDrawerShow"
  18. :zIndex="998"
  19. :popDirection="isMobile ? 'bottom' : 'right'"
  20. :isFullScreen="isMobile"
  21. :overlayColor="isMobile ? undefined : 'transparent'"
  22. :drawerStyle="{
  23. bottom: {
  24. minHeight: '60vh',
  25. maxHeight: '80vh',
  26. borderRadius: '12px 12px 0 0',
  27. },
  28. right: {
  29. width: '360px',
  30. borderRadius: '12px 0 0 12px',
  31. boxShadow: '0 0 10px 0 #d0d0d0',
  32. },
  33. }"
  34. @onOverlayClick="toggleGroupApplicationDrawerShow"
  35. >
  36. <div
  37. :class="{
  38. 'application-contaienr': true,
  39. }"
  40. >
  41. <header class="application-header">
  42. <div @click="toggleGroupApplicationDrawerShow">
  43. <Icon v-if="isPC" :file="closeIcon" :size="'16px'" />
  44. <div v-else>
  45. {{ TUITranslateService.t("关闭") }}
  46. </div>
  47. </div>
  48. </header>
  49. <main>
  50. <div
  51. v-for="(item, index) in customGroupApplicationList"
  52. :key="item.nick"
  53. :class="{
  54. 'application-item': true,
  55. removed: item.isRemoved,
  56. }"
  57. >
  58. <Avatar
  59. :style="{
  60. flex: '0 0 auto',
  61. }"
  62. :url="item.avatar"
  63. :useSkeletonAnimation="true"
  64. />
  65. <div class="application-item-info">
  66. <div class="application-item-nick">
  67. {{ item.nick }}
  68. </div>
  69. <div class="application-item-note">
  70. {{ TUITranslateService.t("TUIChat.申请加入") }}
  71. </div>
  72. </div>
  73. <div class="application-item-operation">
  74. <div
  75. class="agree"
  76. @click="handleApplication(item, 'Agree', index)"
  77. >
  78. {{ TUITranslateService.t("TUIChat.同意") }}
  79. </div>
  80. <div
  81. class="reject"
  82. @click="handleApplication(item, 'Reject', index)"
  83. >
  84. {{ TUITranslateService.t("TUIChat.拒绝") }}
  85. </div>
  86. </div>
  87. </div>
  88. </main>
  89. </div>
  90. </Drawer>
  91. </div>
  92. </template>
  93. <script setup lang="ts">
  94. import { ref, onMounted, onUnmounted, watch } from "../../../../adapter-vue";
  95. import {
  96. TUIStore,
  97. StoreName,
  98. TUITranslateService,
  99. TUIUserService,
  100. TUIGroupService,
  101. } from "@tencentcloud/chat-uikit-engine";
  102. import Icon from "../../../common/Icon.vue";
  103. import Avatar from "../../../common/Avatar/index.vue";
  104. import Drawer from "../../../common/Drawer/index.vue";
  105. import closeIcon from "../../../../assets/icon/close-dark.svg";
  106. import { isPC, isMobile } from "../../../../utils/env";
  107. import {
  108. IGroupApplication,
  109. IUserProfile,
  110. IChatResponese,
  111. } from "../../../../interface";
  112. interface IProps {
  113. groupID: string;
  114. }
  115. interface ICustomGroupApplication {
  116. nick: string;
  117. avatar: string;
  118. isRemoved: boolean;
  119. application: IGroupApplication;
  120. }
  121. const props = withDefaults(defineProps<IProps>(), {
  122. groupID: "",
  123. });
  124. const drawerDomInstanceRef = ref<InstanceType<typeof Drawer>>();
  125. const groupApplicationCount = ref(0);
  126. const isGroupApplicationDrawerShow = ref(false);
  127. const customGroupApplicationList = ref<ICustomGroupApplication[]>([]);
  128. watch(isGroupApplicationDrawerShow, (newVal) => {
  129. if (newVal) {
  130. generateCustomGroupApplicationList().then((list) => {
  131. customGroupApplicationList.value = list;
  132. groupApplicationCount.value = list.length;
  133. });
  134. }
  135. });
  136. watch(
  137. () => customGroupApplicationList.value.length,
  138. (newVal, oldVal) => {
  139. if (oldVal > 0 && newVal === 0) {
  140. isGroupApplicationDrawerShow.value = false;
  141. }
  142. }
  143. );
  144. /**
  145. * Retrieves the current group application list based on the provided groupID.
  146. *
  147. * @return {Promise<IGroupApplication[]>} The list of group applications for the current group.
  148. */
  149. async function getCurrentGroupApplicationList(): Promise<IGroupApplication[]> {
  150. const result: IChatResponese<{ applicationList: IGroupApplication[] }> =
  151. await TUIGroupService.getGroupApplicationList();
  152. const currentGroupApplicationList = result.data.applicationList.filter(
  153. (application) => application.groupID === props.groupID
  154. );
  155. return currentGroupApplicationList;
  156. }
  157. function toggleGroupApplicationDrawerShow() {
  158. isGroupApplicationDrawerShow.value = !isGroupApplicationDrawerShow.value;
  159. }
  160. async function generateCustomGroupApplicationList(): Promise<
  161. ICustomGroupApplication[]
  162. > {
  163. const applicationList = await getCurrentGroupApplicationList();
  164. if (applicationList.length === 0) {
  165. return [];
  166. }
  167. const userIDList = applicationList.map((application) =>
  168. application.applicationType === 0
  169. ? application.applicant
  170. : application.userID
  171. );
  172. const { data: userProfileList } = (await TUIUserService.getUserProfile({
  173. userIDList,
  174. })) as IChatResponese<IUserProfile[]>;
  175. const mappingFromUserID2Profile: Record<string, IUserProfile> = {};
  176. userProfileList.forEach((profile: IUserProfile) => {
  177. mappingFromUserID2Profile[profile.userID] = profile;
  178. });
  179. const groupApplicationList: ICustomGroupApplication[] = applicationList.map(
  180. (application) => {
  181. const profile =
  182. mappingFromUserID2Profile[
  183. application.applicationType === 0
  184. ? application.applicant
  185. : application.userID
  186. ];
  187. return {
  188. nick: profile.nick || profile.userID || "anonymous",
  189. avatar: profile.avatar || "",
  190. isRemoved: false,
  191. application: application,
  192. };
  193. }
  194. );
  195. return groupApplicationList;
  196. }
  197. function handleApplication(
  198. customApplication: ICustomGroupApplication,
  199. action: "Agree" | "Reject",
  200. index: number
  201. ) {
  202. TUIGroupService.handleGroupApplication({
  203. handleAction: action,
  204. application: customApplication.application,
  205. })
  206. .then(() => {
  207. customGroupApplicationList.value[index].isRemoved = true;
  208. setTimeout(() => {
  209. customGroupApplicationList.value.splice(index, 1);
  210. groupApplicationCount.value -= 1;
  211. }, 150);
  212. })
  213. .catch(() => {
  214. // TODO: handle error
  215. });
  216. }
  217. // --------------- mounted function ---------------
  218. onMounted(() => {
  219. // get current group application number on the first time entering the group
  220. getCurrentGroupApplicationList().then((applicationList) => {
  221. groupApplicationCount.value = applicationList.length;
  222. });
  223. // 群未决消息列表
  224. TUIStore.watch(StoreName.GRP, {
  225. groupSystemNoticeList: onGroupSystemNoticeListUpdated,
  226. });
  227. });
  228. onUnmounted(() => {
  229. TUIStore.unwatch(StoreName.GRP, {
  230. groupSystemNoticeList: onGroupSystemNoticeListUpdated,
  231. });
  232. });
  233. function onGroupSystemNoticeListUpdated() {
  234. // Approving or rejecting existing applications will not trigger this callback, but new applications can trigger it.
  235. generateCustomGroupApplicationList().then((list) => {
  236. customGroupApplicationList.value = list;
  237. groupApplicationCount.value = list.length;
  238. });
  239. }
  240. </script>
  241. <style scoped lang="scss">
  242. :not(not) {
  243. display: flex;
  244. flex-direction: column;
  245. box-sizing: border-box;
  246. min-width: 0;
  247. }
  248. .flex-row {
  249. flex-direction: row;
  250. }
  251. .application-tips {
  252. display: flex;
  253. flex-direction: row;
  254. justify-content: center;
  255. width: 100%;
  256. padding: 5px 0;
  257. font-size: 14px;
  258. background-color: #fce4d3;
  259. .application-tips-btn {
  260. color: #006eff;
  261. cursor: pointer;
  262. margin-left: 12px;
  263. }
  264. }
  265. .application-contaienr {
  266. padding: 50px 18px 10px;
  267. background-color: #fff;
  268. height: 100%;
  269. overflow: hidden auto;
  270. font-size: 14px;
  271. .application-header {
  272. position: absolute;
  273. top: 0;
  274. left: 0;
  275. right: 0;
  276. padding: 10px 20px;
  277. flex-direction: row-reverse;
  278. color: #00b693;
  279. font-size: 14px;
  280. }
  281. .application-item {
  282. display: flex;
  283. flex-direction: row;
  284. align-items: center;
  285. padding: 10px 0;
  286. transition: transform 0.15s ease-out;
  287. & + .application-item {
  288. border-top: 0.5px solid #d0d0d0;
  289. }
  290. .application-item-info {
  291. margin-left: 8px;
  292. margin-right: 8px;
  293. font-size: 14px;
  294. .application-item-nick {
  295. display: block;
  296. overflow: hidden;
  297. text-overflow: ellipsis;
  298. white-space: nowrap;
  299. }
  300. .application-item-note {
  301. color: #989191;
  302. font-size: 12px;
  303. }
  304. }
  305. .application-item-operation {
  306. flex-direction: row;
  307. margin-left: auto;
  308. padding: 8px;
  309. flex: 0 0 auto;
  310. font-size: 14px;
  311. .agree {
  312. color: #00b693;
  313. cursor: pointer;
  314. }
  315. .reject {
  316. margin-left: 12px;
  317. color: #fb355d;
  318. cursor: pointer;
  319. }
  320. }
  321. }
  322. .removed {
  323. transform: translateX(-100%);
  324. }
  325. }
  326. </style>