merChantSideIndex.vue 4.7 KB

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