index.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. console.log("xxxxx", content);
  18. TUIGlobal?.setNavigationBarTitle({
  19. title: content || "云通信 IM",
  20. });
  21. };
  22. onMounted(() => {
  23. TUIStore.watch(StoreName.CONV, {
  24. currentConversation: onCurrentConversationUpdated,
  25. });
  26. TUIStore.watch(StoreName.CHAT, {
  27. typingStatus: onTypingStatusUpdated,
  28. });
  29. });
  30. onUnmounted(() => {
  31. TUIStore.unwatch(StoreName.CONV, {
  32. currentConversation: onCurrentConversationUpdated,
  33. });
  34. TUIStore.unwatch(StoreName.CHAT, {
  35. typingStatus: onTypingStatusUpdated,
  36. });
  37. });
  38. onLoad(() => {
  39. setChatHeaderContent(currentConversation.value?.getShowName());
  40. });
  41. function onCurrentConversationUpdated(conversation: IConversationModel) {
  42. currentConversation.value = conversation;
  43. if (!typingStatus.value) {
  44. setChatHeaderContent(currentConversation?.value?.getShowName());
  45. }
  46. }
  47. function onTypingStatusUpdated(status: boolean) {
  48. typingStatus.value = status;
  49. if (typingStatus.value) {
  50. setChatHeaderContent(TUITranslateService.t("TUIChat.对方正在输入"));
  51. } else {
  52. setChatHeaderContent(currentConversation.value?.getShowName());
  53. }
  54. }
  55. </script>