merChantSideIndex.vue 3.7 KB

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