index.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <template>
  2. <view style="display: none;" />
  3. </template>
  4. <script setup lang="ts">
  5. import {
  6. TUIStore,
  7. StoreName,
  8. IConversationModel,
  9. TUITranslateService,
  10. } from '@tencentcloud/chat-uikit-engine';
  11. import { TUIGlobal } from '@tencentcloud/universal-api';
  12. import { onLoad } from '@dcloudio/uni-app';
  13. import { onMounted, onUnmounted, ref } from '../../../adapter-vue';
  14. const currentConversation = ref<IConversationModel>();
  15. const typingStatus = ref(false);
  16. const setChatHeaderContent = (content: string) => {
  17. TUIGlobal?.setNavigationBarTitle({
  18. title: content || '云通信 IM',
  19. });
  20. };
  21. onMounted(() => {
  22. TUIStore.watch(StoreName.CONV, {
  23. currentConversation: onCurrentConversationUpdated,
  24. });
  25. TUIStore.watch(StoreName.CHAT, {
  26. typingStatus: onTypingStatusUpdated,
  27. });
  28. });
  29. onUnmounted(() => {
  30. TUIStore.unwatch(StoreName.CONV, {
  31. currentConversation: onCurrentConversationUpdated,
  32. });
  33. TUIStore.unwatch(StoreName.CHAT, {
  34. typingStatus: onTypingStatusUpdated,
  35. });
  36. });
  37. onLoad(() => {
  38. setChatHeaderContent(currentConversation.value?.getShowName());
  39. });
  40. function onCurrentConversationUpdated(conversation: IConversationModel) {
  41. currentConversation.value = conversation;
  42. if (!typingStatus.value) {
  43. setChatHeaderContent(currentConversation?.value?.getShowName());
  44. }
  45. }
  46. function onTypingStatusUpdated(status: boolean) {
  47. typingStatus.value = status;
  48. if (typingStatus.value) {
  49. setChatHeaderContent(TUITranslateService.t('TUIChat.对方正在输入'));
  50. } else {
  51. setChatHeaderContent(currentConversation.value?.getShowName());
  52. }
  53. }
  54. </script>