From 383a7762e36fc8ec819bdf49018a5d69b3230eda Mon Sep 17 00:00:00 2001 From: Dawn <2439646234@qq.com> Date: Tue, 18 Feb 2025 20:34:06 +0800 Subject: [PATCH] =?UTF-8?q?fix(common):=20:bug:=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E7=99=BB=E5=87=BA=E8=B4=A6=E5=8F=B7=E6=97=B6=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E6=B8=85=E7=A9=BA=E7=B3=BB=E7=BB=9F=E6=89=98=E7=9B=98=E5=9B=BE?= =?UTF-8?q?=E6=A0=87=E4=B8=8A=E7=9A=84=E6=9C=AA=E8=AF=BB=E6=95=B0(MacOS)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useLogin.ts | 7 +++++++ src/layout/index.vue | 5 +++++ src/layout/left/config.tsx | 6 ++++++ src/stores/chat.ts | 13 ++++++++++++- 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/hooks/useLogin.ts b/src/hooks/useLogin.ts index 9fa7cc7..57d5d6a 100644 --- a/src/hooks/useLogin.ts +++ b/src/hooks/useLogin.ts @@ -3,12 +3,15 @@ import { EventEnum } from '@/enums' import { useWindow } from '@/hooks/useWindow.ts' import { useGlobalStore } from '@/stores/global.ts' import { type } from '@tauri-apps/plugin-os' +import { useChatStore } from '@/stores/chat.ts' +import { invoke } from '@tauri-apps/api/core' const isMobile = computed(() => type() === 'android' || type() === 'ios') export const useLogin = () => { const { resizeWindow } = useWindow() const globalStore = useGlobalStore() const { isTrayMenuShow } = storeToRefs(globalStore) + const chatStore = useChatStore() /** * 设置登录状态(系统托盘图标,系统托盘菜单选项) */ @@ -36,6 +39,10 @@ export const useLogin = () => { await resizeWindow('tray', 130, 44) // 发送登出事件 await emit(EventEnum.LOGOUT) + // 清除未读数 + chatStore.clearUnreadCount() + // 清除系统托盘图标上的未读数 + await invoke('set_badge_count', { count: null }) } catch (error) { console.error('创建登录窗口失败:', error) } diff --git a/src/layout/index.vue b/src/layout/index.vue index 58e007e..52f9069 100644 --- a/src/layout/index.vue +++ b/src/layout/index.vue @@ -56,6 +56,7 @@ import { emitTo } from '@tauri-apps/api/event' import { useThrottleFn } from '@vueuse/core' import apis from '@/services/apis.ts' import { confirm } from '@tauri-apps/plugin-dialog' +import { invoke } from '@tauri-apps/api/core' // 异步加载组件时增加缓存配置 const AsyncLeft = defineAsyncComponent({ @@ -138,6 +139,10 @@ useMitt.on(WsResponseMessageType.TOKEN_EXPIRED, async (wsTokenExpire: WsTokenExp // token已在后端清空,只需要返回登录页 await logout() await apis.logout() + // 清除未读数 + chatStore.clearUnreadCount() + // 清除系统托盘图标上的未读数 + await invoke('set_badge_count', { count: null }) userStore.isSign = false userStore.userInfo = {} localStorage.removeItem('user') diff --git a/src/layout/left/config.tsx b/src/layout/left/config.tsx index 819ef09..374317f 100644 --- a/src/layout/left/config.tsx +++ b/src/layout/left/config.tsx @@ -6,11 +6,13 @@ import apis from '@/services/apis.ts' import { LoginStatus, useWsLoginStore } from '@/stores/ws.ts' import { useUserStore } from '@/stores/user.ts' import { invoke } from '@tauri-apps/api/core' +import { useChatStore } from '@/stores/chat' const { createWebviewWindow } = useWindow() const { logout } = useLogin() const loginStore = useWsLoginStore() const userStore = useUserStore() +const chatStore = useChatStore() /** * 这里的顶部的操作栏使用pinia写入了localstorage中 */ @@ -111,6 +113,10 @@ const moreList = ref([ userStore.isSign = false userStore.userInfo = {} loginStore.loginStatus = LoginStatus.Init + // 清除未读数 + chatStore.clearUnreadCount() + // 清除系统托盘图标上的未读数 + await invoke('set_badge_count', { count: null }) // 5. 最后调用登出方法(这会创建登录窗口) await logout() } catch (error) { diff --git a/src/stores/chat.ts b/src/stores/chat.ts index 3dddc17..78a5d90 100644 --- a/src/stores/chat.ts +++ b/src/stores/chat.ts @@ -602,6 +602,16 @@ export const useChatStore = defineStore( invoke('set_badge_count', { count: totalUnread > 0 ? totalUnread : null }) } + // 在 useChatStore 中添加新方法 + const clearUnreadCount = () => { + // 清空所有会话的未读数 + sessionList.forEach((session) => { + session.unreadCount = 0 + }) + // 更新全局未读数 + updateTotalUnreadCount() + } + return { getMsgIndex, chatMessageList, @@ -635,7 +645,8 @@ export const useChatStore = defineStore( getRecalledMessage, recalledMessages, clearAllExpirationTimers, - updateTotalUnreadCount + updateTotalUnreadCount, + clearUnreadCount } }, {