index.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. if (conversationID.includes("C")) {
  51. companyUserId = conversationID.replace("C2C", "");
  52. } else {
  53. companyUserId = conversationID.replace("C2C", "");
  54. }
  55. TUIGlobal?.navigateTo({
  56. url:
  57. "/TUIKit-House/components/TUIChat/index?shopUserId=" +
  58. companyUserId +
  59. "&userId=" +
  60. uni.getStorageSync("userId"),
  61. });
  62. emits("handleSwitchConversation", conversationID);
  63. };
  64. const closeChildren = () => {
  65. headerRef?.value?.closeChildren();
  66. conversationListDomRef?.value?.closeChildren();
  67. };
  68. const handleClickConv = () => {
  69. closeChildren();
  70. };
  71. onHide(closeChildren);
  72. const handleTouchStart = (e: any) => {
  73. touchX.value = e.changedTouches[0].clientX;
  74. touchY.value = e.changedTouches[0].clientY;
  75. };
  76. const handleTouchEnd = (e: any) => {
  77. const x = e.changedTouches[0].clientX;
  78. const y = e.changedTouches[0].clientY;
  79. let turn = "";
  80. if (x - touchX.value > 50 && Math.abs(y - touchY.value) < 50) {
  81. // 右滑
  82. turn = "right";
  83. } else if (x - touchX.value < -50 && Math.abs(y - touchY.value) < 50) {
  84. // 左滑
  85. turn = "left";
  86. }
  87. if (y - touchY.value > 50 && Math.abs(x - touchX.value) < 50) {
  88. // 下滑
  89. turn = "down";
  90. } else if (y - touchY.value < -50 && Math.abs(x - touchX.value) < 50) {
  91. // 上滑
  92. turn = "up";
  93. }
  94. // 根据方向进行操作
  95. if (turn === "down" || turn === "up") {
  96. closeChildren();
  97. }
  98. };
  99. const getPassingRef = (ref) => {
  100. ref.value = conversationListDomRef.value;
  101. };
  102. </script>
  103. <style lang="scss" scoped src="./style/index.scss"></style>