index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. <template>
  2. <Overlay
  3. :maskColor="'transparent'"
  4. @onOverlayClick="closeReadReceiptPanel"
  5. >
  6. <div
  7. :class="{
  8. 'read-receipt-panel': true,
  9. 'read-receipt-panel-mobile': isMobile,
  10. 'read-receipt-panel-close-mobile': isMobile && isPanelClose,
  11. }"
  12. >
  13. <div class="header">
  14. <div class="header-text">
  15. {{ TUITranslateService.t("TUIChat.消息详情") }}
  16. </div>
  17. <div class="header-close-icon">
  18. <Icon
  19. size="12px"
  20. hotAreaSize="8"
  21. :file="closeIcon"
  22. @onClick="closeReadReceiptPanel"
  23. />
  24. </div>
  25. </div>
  26. <div class="read-status-counter-container">
  27. <div
  28. v-for="tabName in tabNameList"
  29. :key="tabName"
  30. :class="{
  31. 'read-status-counter': true,
  32. 'active': tabName === currentTabName,
  33. }"
  34. @click="toggleTabName(tabName)"
  35. >
  36. <div class="status-text">
  37. {{ tabInfo[tabName].tabName }}
  38. </div>
  39. <div class="status-count">
  40. {{ tabInfo[tabName].count === undefined ? "" : tabInfo[tabName].count }}
  41. </div>
  42. </div>
  43. </div>
  44. <div class="read-status-member-list">
  45. <div
  46. v-if="tabInfo[currentTabName].count === 0 && isFirstLoadFinished"
  47. class="empty-list-tip"
  48. >
  49. - {{ TUITranslateService.t('TUIChat.空') }} -
  50. </div>
  51. <template v-else-if="isFirstLoadFinished">
  52. <template v-if="currentTabName === 'unread'">
  53. <div
  54. v-for="item in tabInfo[currentTabName].memberList"
  55. :key="item.userID"
  56. class="read-status-member-container"
  57. >
  58. <Avatar
  59. class="read-status-avatar"
  60. useSkeletonAnimation
  61. :url="item.avatar || ''"
  62. />
  63. <div class="username">
  64. {{ item.nick || item.userID }}
  65. </div>
  66. </div>
  67. </template>
  68. <template v-if="currentTabName === 'read'">
  69. <div
  70. v-for="item in tabInfo[currentTabName].memberList"
  71. :key="item.userID"
  72. class="read-status-member-container"
  73. >
  74. <Avatar
  75. class="read-status-avatar"
  76. useSkeletonAnimation
  77. :url="item.avatar"
  78. />
  79. <div class="username">
  80. {{ item.nick || item.userID }}
  81. </div>
  82. </div>
  83. </template>
  84. </template>
  85. <div
  86. v-if="isFirstLoadFinished"
  87. class="fetch-more-container"
  88. >
  89. <FetchMore
  90. :isFetching="isPullDownFetching"
  91. :isTerminateObserve="isStopFetchMore"
  92. @onExposed="pullDownFetchMoreData"
  93. />
  94. </div>
  95. </div>
  96. </div>
  97. </Overlay>
  98. </template>
  99. <script setup lang="ts">
  100. import { ref, onMounted, watch, nextTick } from '../../../../adapter-vue';
  101. import { IMessageModel, TUIStore, TUIChatService, TUITranslateService } from '@tencentcloud/chat-uikit-engine';
  102. import closeIcon from '../../../../assets/icon/icon-close.svg';
  103. import Icon from '../../../common/Icon.vue';
  104. import Overlay from '../../../common/Overlay/index.vue';
  105. import Avatar from '../../../common/Avatar/index.vue';
  106. import FetchMore from '../../../common/FetchMore/index.vue';
  107. import type { IGroupMessageReadMemberData, IMemberData, ITabInfo, TabName } from './interface';
  108. import { isMobile } from '../../../../utils/env';
  109. type ReadType = 'unread' | 'read' | 'all';
  110. interface IProps {
  111. message: IMessageModel;
  112. }
  113. interface IEmits {
  114. (key: 'setReadReceiptPanelVisible', visible: boolean, message?: IMessageModel): void;
  115. }
  116. const emits = defineEmits<IEmits>();
  117. const props = withDefaults(defineProps<IProps>(), {
  118. message: () => ({}) as IMessageModel,
  119. });
  120. let lastUnreadCursor: string = '';
  121. let lastReadCursor: string = '';
  122. const tabNameList: TabName[] = ['unread', 'read'];
  123. const isListFetchCompleted: Record<TabName, boolean> = {
  124. unread: false,
  125. read: false,
  126. close: false,
  127. };
  128. const isPullDownFetching = ref<boolean>(false);
  129. const isPanelClose = ref<boolean>(false);
  130. const isFirstLoadFinished = ref<boolean>(false);
  131. const isStopFetchMore = ref<boolean>(false);
  132. const currentTabName = ref<TabName>('unread');
  133. const tabInfo = ref<ITabInfo>(generateInitalTabInfo());
  134. onMounted(async () => {
  135. await initAndRefetchReceiptInfomation();
  136. nextTick(() => {
  137. isFirstLoadFinished.value = true;
  138. });
  139. });
  140. watch(
  141. () => props.message.readReceiptInfo.readCount,
  142. () => {
  143. initAndRefetchReceiptInfomation();
  144. },
  145. );
  146. async function fetchGroupMessageRecriptMemberListByType(readType: ReadType = 'all') {
  147. const message = TUIStore.getMessageModel(props.message.ID);
  148. let unreadResult = {} as IGroupMessageReadMemberData;
  149. let readResult = {} as IGroupMessageReadMemberData;
  150. if (readType === 'all' || readType === 'unread') {
  151. unreadResult = await TUIChatService.getGroupMessageReadMemberList({
  152. message,
  153. filter: 1,
  154. cursor: lastUnreadCursor,
  155. count: 100,
  156. });
  157. if (unreadResult) {
  158. lastUnreadCursor = unreadResult.data.cursor;
  159. if (unreadResult.data.isCompleted) {
  160. isListFetchCompleted.unread = true;
  161. }
  162. }
  163. }
  164. if (readType === 'all' || readType === 'read') {
  165. readResult = await TUIChatService.getGroupMessageReadMemberList({
  166. message,
  167. filter: 0,
  168. cursor: lastReadCursor,
  169. count: 100,
  170. });
  171. if (readResult) {
  172. lastReadCursor = readResult.data.cursor;
  173. if (readResult.data.isCompleted) {
  174. isListFetchCompleted.read = true;
  175. }
  176. }
  177. }
  178. // Fetch the total number of read and unread users
  179. const { unreadCount: totalUnreadCount, readCount: totalReadCount } = message.readReceiptInfo;
  180. return {
  181. unreadResult: {
  182. count: totalUnreadCount,
  183. ...unreadResult.data,
  184. },
  185. readResult: {
  186. count: totalReadCount,
  187. ...readResult.data,
  188. },
  189. };
  190. }
  191. async function pullDownFetchMoreData() {
  192. /**
  193. * Use isPullDownFetching to control the state of the FetchMore component
  194. * Also, implement locking for intersectionObserver under uniapp
  195. * Because there is no isIntersecting in uniapp, it is impossible to determine whether the observed element has entered or exited the observation area
  196. */
  197. if (isListFetchCompleted[currentTabName.value] || isPullDownFetching.value) {
  198. return;
  199. }
  200. isPullDownFetching.value = true;
  201. if (currentTabName.value === 'unread' || currentTabName.value === 'read') {
  202. const { unreadResult, readResult } = await fetchGroupMessageRecriptMemberListByType(currentTabName.value);
  203. checkStopFetchMore();
  204. try {
  205. tabInfo.value.unread.memberList = tabInfo.value.unread.memberList.concat(unreadResult.unreadUserInfoList || []);
  206. tabInfo.value.read.memberList = tabInfo.value.read.memberList.concat(readResult.readUserInfoList || []);
  207. } finally {
  208. isPullDownFetching.value = false;
  209. }
  210. }
  211. }
  212. /**
  213. * Initializes and refetches receipt information.
  214. *
  215. * @return {Promise<void>} A promise that resolves when the function has completed.
  216. */
  217. async function initAndRefetchReceiptInfomation(): Promise<void> {
  218. lastUnreadCursor = '';
  219. lastReadCursor = '';
  220. isStopFetchMore.value = false;
  221. isListFetchCompleted.unread = false;
  222. isListFetchCompleted.read = false;
  223. const { unreadResult, readResult } = await fetchGroupMessageRecriptMemberListByType('all');
  224. checkStopFetchMore();
  225. resetTabInfo('read', readResult.count, readResult.readUserInfoList);
  226. resetTabInfo('unread', unreadResult.count, unreadResult.unreadUserInfoList);
  227. resetTabInfo('close');
  228. }
  229. /**
  230. * Checks if the fetch more operation should be stopped
  231. * by IntersetctionObserver.disconnect().
  232. *
  233. * @return {void}
  234. */
  235. function checkStopFetchMore(): void {
  236. if (isListFetchCompleted.read && isListFetchCompleted.unread) {
  237. isStopFetchMore.value = true;
  238. }
  239. }
  240. /**
  241. * Resets the information of a specific tab.
  242. *
  243. * @param {TabName} tabName - The name of the tab to reset.
  244. * @param {number} [count] - The count to assign to the tab. Optional.
  245. * @param {IMemberData[]} [memberList] - The list of members to assign to the tab. Optional.
  246. * @return {void} - This function does not return anything.
  247. */
  248. function resetTabInfo(tabName: TabName, count?: number, memberList?: IMemberData[]): void {
  249. tabInfo.value[tabName].count = count;
  250. tabInfo.value[tabName].memberList = memberList || [];
  251. }
  252. /**
  253. * Generates the initial tab information.
  254. *
  255. * @return {ITabInfo} The initial tab information.
  256. */
  257. function generateInitalTabInfo(): ITabInfo {
  258. return {
  259. read: {
  260. tabName: TUITranslateService.t('TUIChat.已读'),
  261. count: undefined,
  262. memberList: [],
  263. },
  264. unread: {
  265. tabName: TUITranslateService.t('TUIChat.未读'),
  266. count: undefined,
  267. memberList: [],
  268. },
  269. close: {
  270. tabName: TUITranslateService.t('TUIChat.关闭'),
  271. count: undefined,
  272. memberList: [],
  273. },
  274. };
  275. }
  276. /**
  277. * Toggles the tab name.
  278. *
  279. * @param {TabName} tabName - The name of the tab to toggle.
  280. * @return {void} This function does not return anything.
  281. */
  282. function toggleTabName(tabName: TabName): void {
  283. currentTabName.value = tabName;
  284. }
  285. function closeReadReceiptPanel(): void {
  286. isPanelClose.value = true;
  287. setTimeout(() => {
  288. emits('setReadReceiptPanelVisible', false);
  289. }, 200);
  290. }
  291. </script>
  292. <style scoped lang="scss">
  293. :not(not) {
  294. display: flex;
  295. flex-direction: column;
  296. box-sizing: border-box;
  297. min-width: 0;
  298. }
  299. .read-receipt-panel {
  300. background-color: #fff;
  301. box-shadow: 0 7px 20px rgba(0, 0, 0, 0.1);
  302. width: 368px;
  303. height: 510px;
  304. padding: 30px 20px;
  305. display: flex;
  306. flex-direction: column;
  307. border-radius: 8px;
  308. overflow: hidden;
  309. .header {
  310. flex-direction: row;
  311. justify-content: center;
  312. align-items: center;
  313. position: relative;
  314. .header-text {
  315. font-weight: bold;
  316. font-size: 16px;
  317. line-height: 30px;
  318. color: #333;
  319. }
  320. .header-close-icon {
  321. position: absolute;
  322. right: 0;
  323. margin-right: 10px;
  324. }
  325. }
  326. .read-status-counter-container {
  327. flex-direction: row;
  328. justify-content: space-between;
  329. align-items: flex-start;
  330. min-height: 59px;
  331. margin: 20px 40px 17.5px;
  332. .read-status-counter {
  333. justify-content: flex-start;
  334. align-items: center;
  335. cursor: pointer;
  336. -webkit-tap-highlight-color: transparent;
  337. .status-text {
  338. font-size: 14px;
  339. line-height: 20px;
  340. }
  341. .status-count {
  342. margin-top: 2px;
  343. font-size: 30px;
  344. font-weight: bolder;
  345. line-height: 37px;
  346. }
  347. &.active {
  348. color: #679ce1;
  349. }
  350. }
  351. }
  352. .read-status-member-list {
  353. flex: 1 1 auto;
  354. overflow: hidden auto;
  355. padding: 20px 0 0;
  356. border-top: 0.5px solid #e8e8e9;
  357. font-size: 14px;
  358. .empty-list-tip {
  359. align-self: center;
  360. color: #b3b3b3;
  361. }
  362. .read-status-member-container {
  363. flex-direction: row;
  364. align-items: center;
  365. .read-status-avatar {
  366. flex: 0 0 auto;
  367. }
  368. .username {
  369. margin-left: 8px;
  370. line-height: 20px;
  371. flex: 0 1 auto;
  372. display: block;
  373. overflow: hidden;
  374. text-overflow: ellipsis;
  375. word-break: break-all;
  376. white-space: nowrap;
  377. }
  378. & + .read-status-member-container {
  379. margin-top: 20px;
  380. }
  381. }
  382. .fetch-more-container {
  383. justify-content: center;
  384. align-items: center;
  385. margin-top: auto;
  386. }
  387. }
  388. }
  389. .read-receipt-panel-mobile {
  390. @extend .read-receipt-panel;
  391. box-shadow: none;
  392. width: 100vw;
  393. height: 100vh;
  394. border-radius: 0;
  395. animation: slide-in-from-right 0.3s ease-out;
  396. transition: transform 0.2s ease-out;
  397. @keyframes slide-in-from-right {
  398. from {
  399. transform: translateX(100%);
  400. }
  401. }
  402. }
  403. .read-receipt-panel-close-mobile {
  404. transform: translateX(100%);
  405. }
  406. </style>