merChantSideIndex.vue 3.4 KB

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