index.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <div
  3. class="tui-conversation"
  4. @click="handleClickConv"
  5. @touchstart="handleTouchStart"
  6. @touchend="handleTouchEnd"
  7. >
  8. <TUISearch searchType="global" />
  9. <!-- <ConversationHeader
  10. v-if="isShowConversationHeader"
  11. ref="headerRef"
  12. /> -->
  13. <ConversationNetwork />
  14. <ConversationList
  15. ref="conversationListDomRef"
  16. class="tui-conversation-list"
  17. @handleSwitchConversation="handleSwitchConversation"
  18. @getPassingRef="getPassingRef"
  19. />
  20. </div>
  21. </template>
  22. <script lang="ts" setup>
  23. import { TUIStore, StoreName } from "@tencentcloud/chat-uikit-engine";
  24. import { TUIGlobal } from "@tencentcloud/universal-api";
  25. import { ref } from "../../adapter-vue";
  26. import TUISearch from "../TUISearch/index.vue";
  27. import ConversationList from "./conversation-list/index.vue";
  28. import ConversationHeader from "./conversation-header/index.vue";
  29. import ConversationNetwork from "./conversation-network/index.vue";
  30. import { onHide } from "@dcloudio/uni-app"; // 该方法只能用在父组件内,子组件内不生效
  31. const emits = defineEmits(["handleSwitchConversation"]);
  32. const totalUnreadCount = ref(0);
  33. const headerRef = ref<typeof ConversationHeader>();
  34. const conversationListDomRef = ref<typeof ConversationList>();
  35. const touchX = ref<number>(0);
  36. const touchY = ref<number>(0);
  37. const isShowConversationHeader = ref<boolean>(true);
  38. TUIStore.watch(StoreName.CONV, {
  39. totalUnreadCount: (count: number) => {
  40. totalUnreadCount.value = count;
  41. },
  42. });
  43. TUIStore.watch(StoreName.CUSTOM, {
  44. isShowConversationHeader: (showStatus: boolean) => {
  45. isShowConversationHeader.value = showStatus !== false;
  46. },
  47. });
  48. const handleSwitchConversation = (conversationID: string) => {
  49. let companyUserId =
  50. conversationID.indexOf("A") > -1
  51. ? conversationID.substring(4)
  52. : conversationID.substring(3);
  53. TUIGlobal?.navigateTo({
  54. url:
  55. "/TUIKit/components/TUIChat/index?companyUserId=" +
  56. companyUserId +
  57. "&recruitUserId=" +
  58. uni.getStorageSync("userId"),
  59. });
  60. emits("handleSwitchConversation", conversationID);
  61. };
  62. const closeChildren = () => {
  63. headerRef?.value?.closeChildren();
  64. conversationListDomRef?.value?.closeChildren();
  65. };
  66. const handleClickConv = () => {
  67. closeChildren();
  68. };
  69. onHide(closeChildren);
  70. const handleTouchStart = (e: any) => {
  71. touchX.value = e.changedTouches[0].clientX;
  72. touchY.value = e.changedTouches[0].clientY;
  73. };
  74. const handleTouchEnd = (e: any) => {
  75. const x = e.changedTouches[0].clientX;
  76. const y = e.changedTouches[0].clientY;
  77. let turn = "";
  78. if (x - touchX.value > 50 && Math.abs(y - touchY.value) < 50) {
  79. // 右滑
  80. turn = "right";
  81. } else if (x - touchX.value < -50 && Math.abs(y - touchY.value) < 50) {
  82. // 左滑
  83. turn = "left";
  84. }
  85. if (y - touchY.value > 50 && Math.abs(x - touchX.value) < 50) {
  86. // 下滑
  87. turn = "down";
  88. } else if (y - touchY.value < -50 && Math.abs(x - touchX.value) < 50) {
  89. // 上滑
  90. turn = "up";
  91. }
  92. // 根据方向进行操作
  93. if (turn === "down" || turn === "up") {
  94. closeChildren();
  95. }
  96. };
  97. const getPassingRef = (ref) => {
  98. ref.value = conversationListDomRef.value;
  99. };
  100. </script>
  101. <style lang="scss" scoped src="./style/index.scss"></style>