fix: 交易圈互动消息展示发送时间
This commit is contained in:
parent
6201973ca4
commit
ff2930fb25
@ -6,6 +6,7 @@ import MouseWheel from "@better-scroll/mouse-wheel";
|
||||
import useDisableScroll from "@/hooks/useDisableScroll";
|
||||
import useReadMessage from "./useReadMessage";
|
||||
import store from "@/store/index";
|
||||
import dayjs from "dayjs";
|
||||
|
||||
BScroll.use(PullDown);
|
||||
BScroll.use(MouseWheel);
|
||||
@ -22,6 +23,41 @@ export default function useChatData({ id, className, type, stompClient }) {
|
||||
|
||||
const { setStorageTeacherMsg } = useReadMessage();
|
||||
|
||||
const msgTimeList = [];
|
||||
const msgTimeObj = {};
|
||||
const disposeMsg = (msgData, isHis) => {
|
||||
// isHis true历史消息 false最新消息
|
||||
let msgArr = Array.isArray(msgData) ? msgData : [msgData];
|
||||
msgArr.forEach((item) => {
|
||||
msgIdsObj.value[item.id] = item;
|
||||
let chatTime = dayjs(item.createTime).format("MM-DD HH:mm");
|
||||
item.show =
|
||||
item.status === 2 ||
|
||||
(item.userType === 2 && item.userId === store.state.userInfo.userId);
|
||||
if (isHis) {
|
||||
// 将全部评论按1分钟为维度进行汇总
|
||||
if (!msgTimeList.includes(chatTime) && item.show) {
|
||||
msgTimeList.push(chatTime);
|
||||
item.chatTime = chatTime;
|
||||
msgTimeObj[chatTime] = item;
|
||||
} else if (msgTimeList.includes(chatTime) && item.show) {
|
||||
item.chatTime = chatTime;
|
||||
delete msgTimeObj[chatTime].chatTime;
|
||||
msgTimeObj[chatTime] = item;
|
||||
}
|
||||
} else {
|
||||
// 将全部评论按1s为维度进行汇总
|
||||
if (!msgTimeList.includes(chatTime) && item.show) {
|
||||
msgTimeList.push(chatTime);
|
||||
item.chatTime = chatTime;
|
||||
msgTimeObj[chatTime] = item;
|
||||
} else {
|
||||
delete item.chatTime;
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const getLiveHisMsg = async () => {
|
||||
loading.value = true;
|
||||
if (isPullingDown.value) return;
|
||||
@ -34,13 +70,11 @@ export default function useChatData({ id, className, type, stompClient }) {
|
||||
type, // 查询类型:1全部;2投顾;3用户;4精选;5私聊
|
||||
});
|
||||
if (ret.code === 0) {
|
||||
disposeMsg(ret.data.list, true);
|
||||
let list = ret.data.list.reverse() || [];
|
||||
hasNext.value = ret.data.hasNext;
|
||||
preHisHeight = msgListRef.value.clientHeight;
|
||||
msgList.value = list.concat(msgList.value);
|
||||
list.forEach((msg) => {
|
||||
msgIdsObj.value[msg.id] = msg;
|
||||
});
|
||||
if (!hasNext.value) {
|
||||
bs.value && bs.value.closePullDown();
|
||||
}
|
||||
@ -69,8 +103,8 @@ export default function useChatData({ id, className, type, stompClient }) {
|
||||
|
||||
// WebSocket推送的消息
|
||||
const pushNewMsg = (msg) => {
|
||||
disposeMsg(msg);
|
||||
msgList.value.push(msg);
|
||||
msgIdsObj.value[msg.id] = msg;
|
||||
nextTick(() => {
|
||||
let isBottom = bs.value.maxScrollY + 20 >= bs.value.y;
|
||||
bs.value && bs.value.refresh();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user