feat: 退出登录

This commit is contained in:
2025-09-20 15:24:40 +08:00
parent dc8b939ff3
commit 67474d73a4
4 changed files with 43 additions and 17 deletions

View File

@@ -151,6 +151,7 @@ import {
SCROLL_TO_BOTTOM,
RECOMMEND_POSTS_TITLE,
SEND_COMMAND_TEXT,
NOTICE_EVENT_LOGOUT,
} from "@/constant/constant";
import { WSS_URL } from "@/request/base/baseUrl";
import { MessageRole, MessageType, CompName } from "../../model/ChatModel";
@@ -189,7 +190,7 @@ const statusBarHeight = ref(20);
/// 输入框组件引用
const inputAreaRef = ref(null);
const timer = ref(null);
const holdKeyboardTimer = ref(null);
/// focus时点击页面的时候不收起键盘
const holdKeyboard = ref(false);
/// 是否在键盘弹出,点击界面时关闭键盘
@@ -235,8 +236,8 @@ const openDrawer = () => emits("openDrawer");
/// =============事件函数↓================
const handleTouchEnd = () => {
clearTimeout(timer.value);
timer.value = setTimeout(() => {
clearTimeout(holdKeyboardTimer.value);
holdKeyboardTimer.value = setTimeout(() => {
// 键盘弹出时点击界面则关闭键盘
if (holdKeyboardFlag.value && isKeyboardShow.value) {
uni.hideKeyboard();
@@ -338,6 +339,13 @@ const sendMessageAction = (inputText) => {
/// 添加通知
const addNoticeListener = () => {
uni.$on(NOTICE_EVENT_LOGOUT, () => {
resetConfig();
uni.showToast({
title: "退出登录成功",
});
});
uni.$on(SCROLL_TO_BOTTOM, () => {
setTimeout(() => {
scrollToBottom();
@@ -773,7 +781,12 @@ onUnmounted(() => {
uni.$off(SCROLL_TO_BOTTOM);
uni.$off(RECOMMEND_POSTS_TITLE);
uni.$off(SEND_COMMAND_TEXT);
uni.$off(NOTICE_EVENT_LOGOUT);
resetConfig();
});
const resetConfig = () => {
// 清理WebSocket连接
if (webSocketManager) {
webSocketManager.destroy();
@@ -790,11 +803,11 @@ onUnmounted(() => {
resetMessageState();
// 清理定时器
if (timer.value) {
clearTimeout(timer.value);
timer.value = null;
if (holdKeyboardTimer.value) {
clearTimeout(holdKeyboardTimer.value);
holdKeyboardTimer.value = null;
}
});
};
</script>
<style lang="scss" scoped>