merChantSideIndex.vue 3.6 KB

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