merChantSideIndex.vue 3.2 KB

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