index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <template>
  2. <div>
  3. <div
  4. class="tui-conversation"
  5. @click="handleClickConv"
  6. @touchstart="handleTouchStart"
  7. @touchend="handleTouchEnd"
  8. >
  9. <div class="header">
  10. <div class="item" @click="group">
  11. <img
  12. src="https://directpurchase-oss-dev.oss-cn-chengdu.aliyuncs.com/wx/static/img/jhq.png"
  13. style="width: 60px; height: 60px"
  14. />
  15. <span class="title">资源聚合群</span>
  16. </div>
  17. <div class="item" @click="book">
  18. <img
  19. src="https://directpurchase-oss-dev.oss-cn-chengdu.aliyuncs.com/wx/static/img/txl.png"
  20. style="width: 60px; height: 60px"
  21. />
  22. <span class="title">通讯录</span>
  23. </div>
  24. <div class="item" @click="interactive">
  25. <div class="count" v-if="hdxsCount > 0">{{ hdxsCount }}</div>
  26. <img
  27. src="https://directpurchase-oss-dev.oss-cn-chengdu.aliyuncs.com/wx/static/img/hdxx.png"
  28. style="width: 60px; height: 60px"
  29. />
  30. <span class="title">互动消息</span>
  31. </div>
  32. <div class="item" @click="serviceNotice">
  33. <div class="count" v-if="fwCount > 0">{{ fwCount }}</div>
  34. <img
  35. src="https://directpurchase-oss-dev.oss-cn-chengdu.aliyuncs.com/wx/static/img/fwtz.png"
  36. style="width: 60px; height: 60px"
  37. />
  38. <span class="title">服务通知</span>
  39. </div>
  40. </div>
  41. <!--
  42. <TUISearch searchType="global" />
  43. <ConversationHeader v-if="isShowConversationHeader" ref="headerRef" />
  44. <ConversationNetwork /> -->
  45. <ConversationList
  46. ref="conversationListDomRef"
  47. class="tui-conversation-list"
  48. @handleSwitchConversation="handleSwitchConversation"
  49. @getPassingRef="getPassingRef"
  50. />
  51. </div>
  52. </div>
  53. </template>
  54. <script lang="ts" setup>
  55. import { TUIStore, StoreName } from "@tencentcloud/chat-uikit-engine";
  56. import { TUIGlobal } from "@tencentcloud/universal-api";
  57. import { ref, onMounted } from "../../adapter-vue";
  58. // import TUISearch from "../TUISearch/index.vue";
  59. import ConversationList from "./conversation-list/index.vue";
  60. import * as msgApi from "@/api/message/index";
  61. // import ConversationHeader from "./conversation-header/index.vue";
  62. import ConversationNetwork from "./conversation-network/index.vue";
  63. import { onHide, onShow, onLoad } from "@dcloudio/uni-app";
  64. // #ifdef MP-WEIXIN
  65. // uniapp packaged mini-programs are integrated by default, and the default initialization entry file is imported here
  66. // TUIChatKit init needs to be encapsulated because uni vue2 will report an error when compiling H5 directly through conditional compilation
  67. import "./entry.ts";
  68. // #endif
  69. const emits = defineEmits(["handleSwitchConversation"]);
  70. const totalUnreadCount = ref(0);
  71. const headerRef = ref<typeof ConversationHeader>();
  72. const conversationListDomRef = ref<typeof ConversationList>();
  73. const touchX = ref<number>(0);
  74. const touchY = ref<number>(0);
  75. const isShowConversationHeader = ref<boolean>(true);
  76. onLoad((option) => {
  77. initCount();
  78. initCountServer();
  79. });
  80. const hdxsCount = ref("");
  81. const fwCount = ref("");
  82. async function initCount() {
  83. let res = await msgApi.default.nuRead(1);
  84. hdxsCount.value = res.data;
  85. }
  86. async function initCountServer() {
  87. let res = await msgApi.default.nuRead(3);
  88. fwCount.value = res.data;
  89. }
  90. TUIStore.watch(StoreName.CONV, {
  91. totalUnreadCount: (count: number) => {
  92. totalUnreadCount.value = count;
  93. },
  94. });
  95. TUIStore.watch(StoreName.CUSTOM, {
  96. isShowConversationHeader: (showStatus: boolean) => {
  97. isShowConversationHeader.value = showStatus !== false;
  98. },
  99. });
  100. const interactive = () => {
  101. TUIGlobal?.navigateTo({
  102. url: "/pages/message/interactive",
  103. });
  104. };
  105. const serviceNotice = () => {
  106. TUIGlobal?.navigateTo({
  107. url: "/pages/message/serviceNotice",
  108. });
  109. };
  110. const group = () => {
  111. TUIGlobal?.navigateTo({
  112. url: "/pages/group/index",
  113. });
  114. };
  115. const book = () => {
  116. TUIGlobal?.navigateTo({
  117. url: "/TUIKit/components/TUIContact/index",
  118. });
  119. };
  120. const handleSwitchConversation = (conversationID: string) => {
  121. TUIGlobal?.navigateTo({
  122. url: "/TUIKit/components/TUIChat/index",
  123. });
  124. emits("handleSwitchConversation", conversationID);
  125. };
  126. const closeChildren = () => {
  127. headerRef?.value?.closeChildren();
  128. conversationListDomRef?.value?.closeChildren();
  129. };
  130. const handleClickConv = () => {
  131. closeChildren();
  132. };
  133. onHide(closeChildren);
  134. const handleTouchStart = (e: any) => {
  135. touchX.value = e.changedTouches[0].clientX;
  136. touchY.value = e.changedTouches[0].clientY;
  137. };
  138. const handleTouchEnd = (e: any) => {
  139. const x = e.changedTouches[0].clientX;
  140. const y = e.changedTouches[0].clientY;
  141. let turn = "";
  142. if (x - touchX.value > 50 && Math.abs(y - touchY.value) < 50) {
  143. // Swipe right
  144. turn = "right";
  145. } else if (x - touchX.value < -50 && Math.abs(y - touchY.value) < 50) {
  146. // Swipe left
  147. turn = "left";
  148. }
  149. if (y - touchY.value > 50 && Math.abs(x - touchX.value) < 50) {
  150. // Swipe down
  151. turn = "down";
  152. } else if (y - touchY.value < -50 && Math.abs(x - touchX.value) < 50) {
  153. // Swipe up
  154. turn = "up";
  155. }
  156. // Operate according to the direction
  157. if (turn === "down" || turn === "up") {
  158. closeChildren();
  159. }
  160. };
  161. const getPassingRef = (ref) => {
  162. ref.value = conversationListDomRef.value;
  163. };
  164. </script>
  165. <style lang="less" scoped>
  166. .title {
  167. font-family: PingFangSC, PingFang SC;
  168. font-weight: 500;
  169. font-size: 24rpx;
  170. color: #333333;
  171. margin-top: 10rpx;
  172. }
  173. .count {
  174. position: absolute;
  175. right: 0px;
  176. top: -4px;
  177. width: 18px;
  178. height: 18px;
  179. background: red;
  180. text-align: center;
  181. color: white;
  182. border-radius: 50%;
  183. display: flex;
  184. flex-direction: row;
  185. justify-content: center;
  186. align-items: center;
  187. font-size: 10px;
  188. }
  189. </style>
  190. <style lang="scss" scoped src="./style/index.scss"></style>