merChantSideIndex.vue 3.8 KB

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