merChantSideIndex.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. <div class="header" @click="createGroup">创建粉丝群</div>
  15. <ConversationNetwork />
  16. <ConversationList
  17. ref="conversationListDomRef"
  18. class="tui-conversation-list"
  19. @handleSwitchConversation="handleSwitchConversation"
  20. @handleSwitchConversationObj="handleSwitchConversationObj"
  21. @getPassingRef="getPassingRef"
  22. />
  23. </div>
  24. </div>
  25. </template>
  26. <script lang="ts" setup>
  27. import * as MesApi from "../../../api/message";
  28. import {
  29. TUIStore,
  30. StoreName,
  31. TUIConversationService,
  32. } from "@tencentcloud/chat-uikit-engine";
  33. import { TUIGlobal } from "@tencentcloud/universal-api";
  34. import { ref } from "../../adapter-vue";
  35. import TUISearch from "../TUISearch/index.vue";
  36. import ConversationList from "./conversation-list/index.vue";
  37. import ConversationHeader from "./conversation-header/index.vue";
  38. import ConversationNetwork from "./conversation-network/index.vue";
  39. import { onHide } from "@dcloudio/uni-app"; // 该方法只能用在父组件内,子组件内不生效
  40. const emits = defineEmits(["handleSwitchConversation"]);
  41. const totalUnreadCount = ref(0);
  42. const headerRef = ref<typeof ConversationHeader>();
  43. const conversationListDomRef = ref<typeof ConversationList>();
  44. const touchX = ref<number>(0);
  45. const touchY = ref<number>(0);
  46. const isShowConversationHeader = ref<boolean>(true);
  47. TUIStore.watch(StoreName.CONV, {
  48. totalUnreadCount: (count: number) => {
  49. totalUnreadCount.value = count;
  50. },
  51. });
  52. TUIStore.watch(StoreName.CUSTOM, {
  53. isShowConversationHeader: (showStatus: boolean) => {
  54. isShowConversationHeader.value = showStatus !== false;
  55. },
  56. });
  57. const handleSwitchConversation = (conversationID: string) => {
  58. // TUIGlobal?.navigateTo({
  59. // url: "/TUIKit/components/TUIChat/index",
  60. // });
  61. let companyUserId =
  62. conversationID[3] === "E"
  63. ? conversationID.substring(4)
  64. : conversationID.substring(3);
  65. // let loginType = uni.getStorageSync("loginType");
  66. // if (loginType == 1) {
  67. TUIGlobal?.navigateTo({
  68. url:
  69. "/TUIKit/components/TUIChat/index?shopUserId=" +
  70. uni.getStorageSync("userId") +
  71. "&recruitUserId=" +
  72. companyUserId,
  73. });
  74. // } else {
  75. // TUIGlobal?.navigateTo({
  76. // url:
  77. // "/TUIKit/components/TUIChat/index?companyUserId=" +
  78. // companyUserId +
  79. // "&recruitUserId=" +
  80. // uni.getStorageSync("userId"),
  81. // });
  82. // }
  83. emits("handleSwitchConversation", conversationID);
  84. };
  85. const shopInfo = ref({});
  86. const createGroup = async () => {
  87. const ownerAccount = uni.getStorageSync("id");
  88. let res = await MesApi.default.getInfoByUserId();
  89. if (res.code == 200) {
  90. shopInfo.value = res.data;
  91. let create = await MesApi.default.createGroup({
  92. shopId: res.data.id,
  93. ownerAccount: ownerAccount,
  94. agentType: uni.getStorageSync("agentType"),
  95. });
  96. if (create.code == 200) {
  97. TUIConversationService.switchConversation(`GROUP${create.data.groupId}`);
  98. uni.$u.toast(create.msg);
  99. } else {
  100. uni.$u.toast(create.msg);
  101. }
  102. }
  103. };
  104. const closeChildren = () => {
  105. headerRef?.value?.closeChildren();
  106. conversationListDomRef?.value?.closeChildren();
  107. };
  108. const handleClickConv = () => {
  109. closeChildren();
  110. };
  111. onHide(closeChildren);
  112. const handleTouchStart = (e: any) => {
  113. touchX.value = e.changedTouches[0].clientX;
  114. touchY.value = e.changedTouches[0].clientY;
  115. };
  116. const handleTouchEnd = (e: any) => {
  117. const x = e.changedTouches[0].clientX;
  118. const y = e.changedTouches[0].clientY;
  119. let turn = "";
  120. if (x - touchX.value > 50 && Math.abs(y - touchY.value) < 50) {
  121. // 右滑
  122. turn = "right";
  123. } else if (x - touchX.value < -50 && Math.abs(y - touchY.value) < 50) {
  124. // 左滑
  125. turn = "left";
  126. }
  127. if (y - touchY.value > 50 && Math.abs(x - touchX.value) < 50) {
  128. // 下滑
  129. turn = "down";
  130. } else if (y - touchY.value < -50 && Math.abs(x - touchX.value) < 50) {
  131. // 上滑
  132. turn = "up";
  133. }
  134. // 根据方向进行操作
  135. if (turn === "down" || turn === "up") {
  136. closeChildren();
  137. }
  138. };
  139. const getPassingRef = (ref) => {
  140. ref.value = conversationListDomRef.value;
  141. };
  142. </script>
  143. <style lang="scss" scoped src="./style/index.scss"></style>