merChantSideIndex.vue 3.8 KB

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