Files
tk-mini-program/TUIKit/components/TUIConversation/index.vue

156 lines
4.0 KiB
Vue
Raw Normal View History

2025-05-13 19:39:53 +08:00
<template>
2025-05-14 16:09:14 +08:00
<div class="Navigation">
<image
2025-06-10 23:06:51 +08:00
src="https://vv-1317974657.cos.ap-shanghai.myqcloud.com/util/Navigationimg.png"
2025-05-14 16:09:14 +08:00
mode="scaleToFill"
class="Navigationimg"
/>
2025-06-06 22:36:41 +08:00
<div class="Return">消息</div>
2025-05-14 16:09:14 +08:00
</div>
2025-05-13 19:39:53 +08:00
<div
class="tui-conversation"
@click="handleClickConv"
@touchstart="handleTouchStart"
@touchend="handleTouchEnd"
>
<TUISearch searchType="global" />
2025-05-14 16:09:14 +08:00
<ConversationHeader v-if="isShowConversationHeader" ref="headerRef" />
2025-05-13 19:39:53 +08:00
<ConversationNetwork />
<ConversationList
ref="conversationListDomRef"
class="tui-conversation-list"
@handleSwitchConversation="handleSwitchConversation"
@getPassingRef="getPassingRef"
/>
</div>
2025-05-14 16:09:14 +08:00
<div>
2025-06-11 22:16:44 +08:00
<tabBar :tabIndex="3"></tabBar>
2025-05-14 16:09:14 +08:00
</div>
2025-05-13 19:39:53 +08:00
</template>
<script lang="ts" setup>
2025-05-14 16:09:14 +08:00
import { TUIStore, StoreName } from "@tencentcloud/chat-uikit-engine";
import { TUIGlobal } from "@tencentcloud/universal-api";
import { ref } from "../../adapter-vue";
import TUISearch from "../TUISearch/index.vue";
import ConversationList from "./conversation-list/index.vue";
import ConversationHeader from "./conversation-header/index.vue";
import ConversationNetwork from "./conversation-network/index.vue";
import { onHide } from "@dcloudio/uni-app";
import tabBar from "../../../components/tabBar/tabBar.vue";
2025-05-13 19:39:53 +08:00
// #ifdef MP-WEIXIN
// uniapp packaged mini-programs are integrated by default, and the default initialization entry file is imported here
// TUIChatKit init needs to be encapsulated because uni vue2 will report an error when compiling H5 directly through conditional compilation
2025-05-14 16:09:14 +08:00
import "./entry.ts";
2025-05-13 19:39:53 +08:00
// #endif
2025-05-14 16:09:14 +08:00
const emits = defineEmits(["handleSwitchConversation"]);
2025-05-13 19:39:53 +08:00
const totalUnreadCount = ref(0);
const headerRef = ref<typeof ConversationHeader>();
const conversationListDomRef = ref<typeof ConversationList>();
const touchX = ref<number>(0);
const touchY = ref<number>(0);
const isShowConversationHeader = ref<boolean>(true);
TUIStore.watch(StoreName.CONV, {
totalUnreadCount: (count: number) => {
totalUnreadCount.value = count;
},
});
TUIStore.watch(StoreName.CUSTOM, {
isShowConversationHeader: (showStatus: boolean) => {
isShowConversationHeader.value = showStatus !== false;
},
});
const handleSwitchConversation = (conversationID: string) => {
TUIGlobal?.navigateTo({
2025-05-14 16:09:14 +08:00
url: "/TUIKit/components/TUIChat/index",
2025-05-13 19:39:53 +08:00
});
2025-05-14 16:09:14 +08:00
emits("handleSwitchConversation", conversationID);
2025-05-13 19:39:53 +08:00
};
const closeChildren = () => {
headerRef?.value?.closeChildren();
conversationListDomRef?.value?.closeChildren();
};
const handleClickConv = () => {
closeChildren();
};
onHide(closeChildren);
const handleTouchStart = (e: any) => {
touchX.value = e.changedTouches[0].clientX;
touchY.value = e.changedTouches[0].clientY;
};
const handleTouchEnd = (e: any) => {
const x = e.changedTouches[0].clientX;
const y = e.changedTouches[0].clientY;
2025-05-14 16:09:14 +08:00
let turn = "";
2025-05-13 19:39:53 +08:00
if (x - touchX.value > 50 && Math.abs(y - touchY.value) < 50) {
// Swipe right
2025-05-14 16:09:14 +08:00
turn = "right";
2025-05-13 19:39:53 +08:00
} else if (x - touchX.value < -50 && Math.abs(y - touchY.value) < 50) {
// Swipe left
2025-05-14 16:09:14 +08:00
turn = "left";
2025-05-13 19:39:53 +08:00
}
if (y - touchY.value > 50 && Math.abs(x - touchX.value) < 50) {
// Swipe down
2025-05-14 16:09:14 +08:00
turn = "down";
2025-05-13 19:39:53 +08:00
} else if (y - touchY.value < -50 && Math.abs(x - touchX.value) < 50) {
// Swipe up
2025-05-14 16:09:14 +08:00
turn = "up";
2025-05-13 19:39:53 +08:00
}
// Operate according to the direction
2025-05-14 16:09:14 +08:00
if (turn === "down" || turn === "up") {
2025-05-13 19:39:53 +08:00
closeChildren();
}
};
const getPassingRef = (ref) => {
ref.value = conversationListDomRef.value;
};
</script>
2025-05-14 16:09:14 +08:00
<style>
.Navigation {
width: 100%;
height: 100rpx;
z-index: 999;
}
.Navigationimg {
width: 100%;
height: 200rpx;
position: absolute;
top: 0;
left: 0;
z-index: -1;
}
.Navigation {
width: 100%;
height: 200rpx;
z-index: 999;
display: flex;
justify-content: center;
align-items: center;
}
2025-05-16 21:53:47 +08:00
.Navigation-left{
width: 100%;
height: 200rpx;
z-index: 998;
}
2025-06-06 22:36:41 +08:00
.Return {
width: 70rpx;
height: 70rpx;
2025-05-14 16:09:14 +08:00
position: absolute;
2025-06-06 22:36:41 +08:00
top: 120rpx;
left: 360rpx;
2025-05-14 16:09:14 +08:00
z-index: 999;
2025-06-06 22:36:41 +08:00
font-weight: bold;
}
2025-05-14 16:09:14 +08:00
</style>
2025-05-13 19:39:53 +08:00
<style lang="scss" scoped src="./style/index.scss"></style>