merChantSideIndex.vue 3.5 KB

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