merChantSideIndex.vue 3.3 KB

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