fix: 私聊最新消息提醒

This commit is contained in:
kaizheng(郑凯) 2025-02-18 20:48:17 +08:00
parent ff2930fb25
commit d07bf4c950
3 changed files with 56 additions and 3 deletions

View File

@ -44,3 +44,12 @@ export function readMessage(data) {
data, data,
}); });
} }
// APP查询未读数量
export function msgUnreadCount(data) {
return request({
url: "/app/group/message/unreadCount",
method: "post",
data,
});
}

View File

@ -247,6 +247,18 @@ const {
const maskUserName = (value) => { const maskUserName = (value) => {
return value.charAt(0) + "**"; return value.charAt(0) + "**";
}; };
watch(
() => msgList.value,
() => {
msgList.value.length &&
localStorage.setItem(
`privateMsgUnreadCount-${route.query.id}-${store.state.userInfo.userId}`,
msgList.value[msgList.value.length - 1].id
);
},
{ deep: true }
);
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
.interact-scroll { .interact-scroll {

View File

@ -12,7 +12,7 @@
mode="closeable" mode="closeable"
:text="detail.notice" :text="detail.notice"
/> />
<van-tabs v-model:active="active" line-width="0.4rem"> <van-tabs v-model:active="active" line-width="0.4rem" @change="changeTab">
<van-tab title="互动" :name="0"> <van-tab title="互动" :name="0">
<ChatFrame <ChatFrame
:type="1" :type="1"
@ -31,7 +31,12 @@
:stompClient="stompClient" :stompClient="stompClient"
/> />
</van-tab> </van-tab>
<van-tab title="私聊" :name="2"> <van-tab
title="私聊"
:name="2"
:badge="privateMsgUnreadCount"
:show-zero-badge="false"
>
<ChatFrame <ChatFrame
:type="5" :type="5"
:bsRefresh="active === 2" :bsRefresh="active === 2"
@ -80,7 +85,7 @@ import Nav from "@/components/NavBar.vue";
import ChatFrame from "./components/ChatFrame.vue"; import ChatFrame from "./components/ChatFrame.vue";
import { useRouter, useRoute } from "vue-router"; import { useRouter, useRoute } from "vue-router";
import { sendMessage } from "@/api/circle"; import { sendMessage } from "@/api/circle";
import { getCircleDetail } from "@/api/circle"; import { getCircleDetail, msgUnreadCount } from "@/api/circle";
import useWebSocket from "./hooks/useWebSocket"; import useWebSocket from "./hooks/useWebSocket";
import { useStore } from "vuex"; import { useStore } from "vuex";
@ -121,6 +126,9 @@ const privateMessage = (msg) => {
// interactiveType :1;2;3 // interactiveType :1;2;3
if ([1].includes(body.type)) { if ([1].includes(body.type)) {
privateNewMsg.value = data; privateNewMsg.value = data;
if (active.value !== 2) {
privateMsgUnreadCount.value++;
}
} }
}; };
@ -158,6 +166,30 @@ const sendMsg = async () => {
content.value = ""; content.value = "";
} }
}; };
//
const privateMsgUnreadCount = ref();
const getMsgUnreadCount = async () => {
const lastId = localStorage.getItem(
`privateMsgUnreadCount-${route.query.id}-${store.state.userInfo.userId}`
);
if (!lastId) return;
let ret = await msgUnreadCount({
groupId: route.query.id,
type: 5,
lastId,
});
if (ret && ret.code === 0) {
privateMsgUnreadCount.value = ret.data;
}
};
getMsgUnreadCount();
const changeTab = (tabName) => {
if (tabName === 2) {
privateMsgUnreadCount.value = 0;
}
};
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.set { .set {