feat: 登录与websocket 初始化相关的调整

This commit is contained in:
2025-09-23 20:00:30 +08:00
parent 96746df7c9
commit 8720c43570
4 changed files with 24 additions and 12 deletions

View File

@@ -152,6 +152,7 @@ import {
RECOMMEND_POSTS_TITLE,
SEND_COMMAND_TEXT,
NOTICE_EVENT_LOGOUT,
NOTICE_EVENT_LOGIN_SUCCESS,
} from "@/constant/constant";
import { WSS_URL } from "@/request/base/baseUrl";
import { MessageRole, MessageType, CompName } from "@/model/ChatModel";
@@ -336,6 +337,12 @@ const sendMessageAction = (inputText) => {
/// 添加通知
const addNoticeListener = () => {
uni.$on(NOTICE_EVENT_LOGIN_SUCCESS, () => {
if (!webSocketConnectStatus) {
initHandler();
}
});
uni.$on(NOTICE_EVENT_LOGOUT, () => {
resetConfig();
uni.showToast({
@@ -384,18 +391,6 @@ const initHandler = () => {
initWebSocket();
};
// 绑定成功监听token变化,初始化
watch(
() => appStore.hasToken,
(newValue) => {
if (newValue) {
console.log("token存在初始化数据");
initHandler();
}
}
);
onMounted(() => {
try {
getMainPageData();
@@ -772,6 +767,7 @@ const stopRequest = () => {
// 组件销毁时清理资源
onUnmounted(() => {
uni.$off(NOTICE_EVENT_LOGIN_SUCCESS);
uni.$off(SCROLL_TO_BOTTOM);
uni.$off(RECOMMEND_POSTS_TITLE);
uni.$off(SEND_COMMAND_TEXT);
@@ -785,6 +781,7 @@ const resetConfig = () => {
if (webSocketManager) {
webSocketManager.destroy();
webSocketManager = null;
webSocketConnectStatus = false;
}
// 清理打字机管理器