merChantSideIndex.vue 4.8 KB

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