index.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <template>
  2. <SelectFriend v-if="isShowSelectFriend" />
  3. <div v-else-if="isShowContactList" :class="['tui-contact', !isPC && 'tui-contact-h5']">
  4. <div :class="['tui-contact-left', !isPC && 'tui-contact-h5-left']">
  5. <ContactSearch />
  6. <ContactList
  7. :class="['tui-contact-left-list', !isPC && 'tui-contact-h5-left-list']"
  8. />
  9. </div>
  10. <div
  11. v-if="isShowContactInfo"
  12. :class="['tui-contact-right', !isPC && 'tui-contact-h5-right']"
  13. >
  14. <ContactInfo @switchConversation="switchConversation" />
  15. </div>
  16. </div>
  17. </template>
  18. <script lang="ts" setup>
  19. import { TUIStore, StoreName } from "@tencentcloud/chat-uikit-engine";
  20. import { TUIGlobal } from "@tencentcloud/universal-api";
  21. import { ref, watchEffect } from "../../adapter-vue";
  22. import { isPC, isUniFrameWork } from "../../utils/env";
  23. import SelectFriend from "./select-friend/index.vue";
  24. import ContactSearch from "./contact-search/index.vue";
  25. import ContactList from "./contact-list/index.vue";
  26. import ContactInfo from "./contact-info/index.vue";
  27. const emits = defineEmits(["switchConversation"]);
  28. const props = defineProps({
  29. // web/h5 单页面应用展示形式,uniapp 请忽略
  30. displayType: {
  31. type: String,
  32. default: "contactList", // "contactList" 关系链列表(默认) / "selectFriend" 好友选择列表
  33. require: false,
  34. },
  35. });
  36. const displayTypeRef = ref<string>(props.displayType || "contactList");
  37. const isShowSelectFriend = ref(false);
  38. const isShowContactList = ref(true);
  39. const isShowContactInfo = ref(true);
  40. watchEffect(() => {
  41. isShowContactList.value = props?.displayType !== "selectFriend";
  42. });
  43. TUIStore.watch(StoreName.CUSTOM, {
  44. isShowSelectFriendComponent: (data: any) => {
  45. if (!isUniFrameWork && props?.displayType === "selectFriend") {
  46. isShowSelectFriend.value = data;
  47. isShowContactList.value = false;
  48. return;
  49. }
  50. if (data) {
  51. isShowSelectFriend.value = true;
  52. if (isUniFrameWork) {
  53. displayTypeRef.value = "selectFriend";
  54. TUIGlobal?.hideTabBar();
  55. }
  56. } else {
  57. isShowSelectFriend.value = false;
  58. if (isUniFrameWork) {
  59. displayTypeRef.value = props.displayType;
  60. TUIGlobal?.showTabBar()?.catch(() => {
  61. /* ignore */
  62. });
  63. }
  64. }
  65. },
  66. currentContactInfo: (contactInfo: any) => {
  67. isShowContactInfo.value =
  68. isPC ||
  69. (contactInfo &&
  70. typeof contactInfo === "object" &&
  71. Object.keys(contactInfo)?.length > 0);
  72. },
  73. });
  74. const switchConversation = (data: any) => {
  75. isUniFrameWork &&
  76. TUIGlobal?.navigateTo({
  77. url: "/TUIKit/components/TUIChat/index",
  78. });
  79. emits("switchConversation", data);
  80. };
  81. </script>
  82. <style lang="scss" scoped>
  83. @import "../../assets/styles/common";
  84. .tui-contact {
  85. width: 100%;
  86. height: 100%;
  87. box-sizing: border-box;
  88. display: flex;
  89. overflow: hidden;
  90. &-left {
  91. min-width: 285px;
  92. flex: 0 0 24%;
  93. overflow: hidden;
  94. display: flex;
  95. flex-direction: column;
  96. }
  97. &-right {
  98. border-left: 1px solid #f4f5f9;
  99. flex: 1;
  100. overflow: hidden;
  101. }
  102. }
  103. .tui-contact-h5 {
  104. position: relative;
  105. &-left,
  106. &-right {
  107. width: 100%;
  108. height: 100%;
  109. flex: 1;
  110. }
  111. &-right {
  112. position: absolute;
  113. z-index: 100;
  114. }
  115. &-left {
  116. &-list {
  117. overflow-y: auto;
  118. }
  119. }
  120. }
  121. </style>