diff --git a/pageChat/chat.vue b/pageChat/chat.vue index 586cd8b..b7971f7 100644 --- a/pageChat/chat.vue +++ b/pageChat/chat.vue @@ -174,7 +174,7 @@ import { onReady, onReachBottom, - onLoad, + onLoad,onShow, onPageScroll, } from "@dcloudio/uni-app"; import { @@ -243,7 +243,6 @@ chatStore.onReceiveMsg = (msg) => { scrollView.intoView = "msg-0"; }); }; -chatStore.connectSocket(); const msg = ref(""); const shopInfo = uni.getStorageSync("shopInfo"); @@ -477,6 +476,18 @@ onLoad((opt) => { // #endif }); +onMounted(() => { + chatStore.connectSocket(); + // 确保状态监听已初始化 + if (!chatStore._listenersInitialized) { + chatStore.initStateListeners(); + chatStore._listenersInitialized = true; + } +}); + +onShow(() => { +}); + function toMore() { go.to("PAGES_CHAT_GROUP_INFO", { group_id: groupInfo.value.id, diff --git a/pageChat/index.vue b/pageChat/index.vue index b0583b8..557c449 100644 --- a/pageChat/index.vue +++ b/pageChat/index.vue @@ -56,24 +56,36 @@