fix: 🐛 解决WebSocket模块导入冲突问题

This commit is contained in:
Ray.Hao
2025-06-11 23:44:31 +08:00
parent ec4b4e0aa3
commit 7abfa0ec4b
2 changed files with 4 additions and 34 deletions

View File

@@ -1,7 +1,6 @@
import { useDictSync } from "@/composables/useDictSync";
import { Auth } from "@/utils/auth";
import { useUserStore } from "@/store";
import { watch } from "vue";
// 不直接导入 store 或 userStore
// 全局 WebSocket 实例管理
const websocketInstances = new Map<string, any>();
@@ -73,9 +72,6 @@ export function setupWebSocket() {
// 在窗口关闭前断开WebSocket连接
window.addEventListener("beforeunload", handleWindowClose);
// 监听用户注销事件
watchUserLogout();
console.log("[WebSocketPlugin] WebSocket服务初始化完成");
isInitialized = true;
}, 1000); // 延迟1秒初始化
@@ -92,26 +88,6 @@ function handleWindowClose() {
cleanupWebSocket();
}
/**
* 监听用户注销
*/
function watchUserLogout() {
const userStore = useUserStore();
// 监听用户信息变化,当用户信息被清空时断开连接
watch(
() => userStore.userInfo,
(newUserInfo, oldUserInfo) => {
// 从有用户信息变为无用户信息,说明用户注销了
if (oldUserInfo?.username && !newUserInfo?.username) {
console.log("[WebSocketPlugin] 检测到用户注销断开WebSocket连接");
cleanupWebSocket();
}
},
{ deep: true }
);
}
/**
* 清理WebSocket连接
*/