问题修复
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -56,24 +56,36 @@
|
||||
|
||||
<script setup>
|
||||
import * as chatApi from "@/http/php/chat";
|
||||
import { ref, reactive,inject } from "vue";
|
||||
import { ref, reactive, inject, onMounted,onUnmounted } from "vue";
|
||||
import { onShow } from "@dcloudio/uni-app";
|
||||
import { useChatStore } from "@/store/chat";
|
||||
|
||||
|
||||
|
||||
|
||||
const chatStore = useChatStore();
|
||||
|
||||
onMounted(() => {
|
||||
chatStore.connectSocket();
|
||||
// 确保状态监听已初始化
|
||||
if (!chatStore._listenersInitialized) {
|
||||
chatStore.initStateListeners();
|
||||
chatStore._listenersInitialized = true;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
const startReciveMsg=ref(true)
|
||||
onUnmounted(() => {
|
||||
startReciveMsg.value=false
|
||||
})
|
||||
chatStore.onReceiveMsg = (msg) => {
|
||||
console.log("onReceiveMsg", msg);
|
||||
if(!startReciveMsg.value){
|
||||
return
|
||||
}
|
||||
if (msg.operate_type == "receive_msg" && msg.chat_type == 2) {
|
||||
const index = allList.value.findIndex((v) => v.group_id == msg.group_id);
|
||||
if (index != -1) {
|
||||
allList.value[index].unread_count += 1;
|
||||
allList.value[index].msg = returnMsg(msg);
|
||||
allList.value[index].send_time = msg.send_time;
|
||||
|
||||
|
||||
}
|
||||
const index1 = list.value.findIndex((v) => v.group_id == msg.group_id);
|
||||
if (index1 != -1) {
|
||||
@@ -83,19 +95,18 @@ chatStore.onReceiveMsg = (msg) => {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function returnMsg(msg) {
|
||||
if (msg.msg_type == 1) {
|
||||
return msg.nick+":"+msg.content;
|
||||
return msg.nick + ":" + msg.content;
|
||||
}
|
||||
if (msg.msg_type == 2) {
|
||||
return msg.nick+":"+"[图片]";
|
||||
return msg.nick + ":" + "[图片]";
|
||||
}
|
||||
if (msg.msg_type == 5) {
|
||||
return msg.nick+":"+"[视频]";
|
||||
return msg.nick + ":" + "[视频]";
|
||||
}
|
||||
if (msg.msg_type == 4) {
|
||||
return msg.nick+":"+"[优惠券]";
|
||||
return msg.nick + ":" + "[优惠券]";
|
||||
}
|
||||
}
|
||||
chatStore.connectSocket();
|
||||
@@ -213,6 +224,7 @@ function toDetail(item) {
|
||||
|
||||
const messageUnreadCount = ref(0);
|
||||
onShow(() => {
|
||||
startReciveMsg.value=true
|
||||
getList();
|
||||
// 获取未读消息总数
|
||||
chatApi.messageUnreadCount({}).then((res) => {
|
||||
|
||||
Reference in New Issue
Block a user