From 67474d73a498f80f416da1222bf20c75ef50c2df Mon Sep 17 00:00:00 2001 From: zoujing Date: Sat, 20 Sep 2025 15:24:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=80=80=E5=87=BA=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- constant/constant.js | 9 ++++++--- pages/chat/ChatMainList.vue | 27 ++++++++++++++++++++------- pages/drawer/DrawerHome.vue | 3 ++- pages/drawer/MineSetting.vue | 21 +++++++++++++++------ 4 files changed, 43 insertions(+), 17 deletions(-) diff --git a/constant/constant.js b/constant/constant.js index 95d8eb5..01199d5 100644 --- a/constant/constant.js +++ b/constant/constant.js @@ -1,8 +1,11 @@ +// 退出登录 +export const NOTICE_EVENT_LOGOUT = "NOTICE_EVENT_LOGOUT"; + // 滚动到底部 -export const SCROLL_TO_BOTTOM = 'SCROLL_TO_BOTTOM' +export const SCROLL_TO_BOTTOM = "SCROLL_TO_BOTTOM"; // 推荐帖子 -export const RECOMMEND_POSTS_TITLE = 'RECOMMEND_POSTS_TITLE' +export const RECOMMEND_POSTS_TITLE = "RECOMMEND_POSTS_TITLE"; // 发送命令 -export const SEND_COMMAND_TEXT = 'SEND_COMMAND_TEXT' \ No newline at end of file +export const SEND_COMMAND_TEXT = "SEND_COMMAND_TEXT"; diff --git a/pages/chat/ChatMainList.vue b/pages/chat/ChatMainList.vue index 0b5a3d6..7b514d8 100644 --- a/pages/chat/ChatMainList.vue +++ b/pages/chat/ChatMainList.vue @@ -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; } -}); +};