index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 addSVG from "../../assets/icon/add.svg";
  24. import Icon from "../common/Icon.vue";
  25. import SelectFriend from "./select-friend/index.vue";
  26. import ContactSearch from "./contact-search/index.vue";
  27. import ContactList from "./contact-list/index.vue";
  28. import ContactInfo from "./contact-info/index.vue";
  29. import { onLoad, onShow, onPullDownRefresh } from "@dcloudio/uni-app";
  30. const emits = defineEmits(["switchConversation"]);
  31. const dataList = ref([
  32. {
  33. text: "测试一",
  34. iconSrc:
  35. "https://i-1.lanrentuku.com/2020/9/15/752b7419-0de1-4515-8d2c-63e7b7df007c.png?imageView2/2/w/500",
  36. },
  37. {
  38. text: "测试二",
  39. iconSrc: "https://bpic.51yuansu.com/pic2/cover/00/38/01/58122c53d1ca5_610.jpg",
  40. },
  41. {
  42. text: "测试三",
  43. iconSrc:
  44. "https://i-1.lanrentuku.com/2020/10/27/73be0f11-4027-4e5c-8f8f-be31fa4d2834.png?imageView2/2/w/500",
  45. },
  46. ]);
  47. const props = defineProps({
  48. // web/h5 single page application display format, uniapp please ignore
  49. displayType: {
  50. type: String,
  51. default: "contactList", // "contactList" / "selectFriend"
  52. require: false,
  53. },
  54. });
  55. const displayTypeRef = ref<string>(props.displayType || "contactList");
  56. const isShowSelectFriend = ref(false);
  57. const isShowContactList = ref(true);
  58. const isShowContactInfo = ref(true);
  59. watchEffect(() => {
  60. isShowContactList.value = props?.displayType !== "selectFriend";
  61. });
  62. TUIStore.watch(StoreName.CUSTOM, {
  63. isShowSelectFriendComponent: (data: any) => {
  64. if (!isUniFrameWork && props?.displayType === "selectFriend") {
  65. isShowSelectFriend.value = data;
  66. isShowContactList.value = false;
  67. return;
  68. }
  69. if (data) {
  70. isShowSelectFriend.value = true;
  71. if (isUniFrameWork) {
  72. displayTypeRef.value = "selectFriend";
  73. TUIGlobal?.hideTabBar();
  74. }
  75. } else {
  76. isShowSelectFriend.value = false;
  77. if (isUniFrameWork) {
  78. displayTypeRef.value = props.displayType;
  79. TUIGlobal?.showTabBar()?.catch(() => {
  80. /* ignore */
  81. });
  82. }
  83. }
  84. },
  85. currentContactInfo: (contactInfo: any) => {
  86. isShowContactInfo.value =
  87. isPC ||
  88. (contactInfo &&
  89. typeof contactInfo === "object" &&
  90. Object.keys(contactInfo)?.length > 0);
  91. },
  92. });
  93. const switchConversation = (data: any) => {
  94. isUniFrameWork &&
  95. TUIGlobal?.navigateTo({
  96. url: "/TUIKit/components/TUIChat/index",
  97. });
  98. emits("switchConversation", data);
  99. };
  100. </script>
  101. <style lang="scss" scoped>
  102. @import "../../assets/styles/common";
  103. .tui-contact {
  104. width: 100%;
  105. height: 100%;
  106. box-sizing: border-box;
  107. display: flex;
  108. overflow: hidden;
  109. &-left {
  110. min-width: 285px;
  111. flex: 0 0 24%;
  112. overflow: hidden;
  113. display: flex;
  114. flex-direction: column;
  115. }
  116. &-right {
  117. border-left: 1px solid #f4f5f9;
  118. flex: 1;
  119. overflow: hidden;
  120. }
  121. }
  122. .tui-contact-h5 {
  123. position: relative;
  124. &-left,
  125. &-right {
  126. width: 100%;
  127. height: 100%;
  128. flex: 1;
  129. }
  130. &-right {
  131. position: absolute;
  132. z-index: 100;
  133. }
  134. &-left {
  135. &-list {
  136. overflow-y: auto;
  137. }
  138. }
  139. }
  140. </style>