fix: 消息已读上报
This commit is contained in:
parent
4c93f9a3c2
commit
1e6102b49a
@ -4,7 +4,7 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"serve": "vue-cli-service serve",
|
"serve": "vue-cli-service serve",
|
||||||
"build": "vue-cli-service build",
|
"build": "vue-cli-service build && sh ./build/deploy.sh",
|
||||||
"lint": "vue-cli-service lint"
|
"lint": "vue-cli-service lint"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@ -35,3 +35,12 @@ export function sendMessage(data) {
|
|||||||
data,
|
data,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// APP保存消息已读
|
||||||
|
export function readMessage(data) {
|
||||||
|
return request({
|
||||||
|
url: "/app/group/message/readMessage",
|
||||||
|
method: "post",
|
||||||
|
data,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
62
src/views/Circle/hooks/storage.js
Normal file
62
src/views/Circle/hooks/storage.js
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
import { readMessage } from "@/api/circle";
|
||||||
|
|
||||||
|
// type 1 公共互动 2私聊
|
||||||
|
function getStorageTeacherMsg({
|
||||||
|
productId,
|
||||||
|
productType = 41,
|
||||||
|
type = 1,
|
||||||
|
userId,
|
||||||
|
}) {
|
||||||
|
const getMsgIds = localStorage.getItem(
|
||||||
|
`read-msg-${productType}-${productId}-${userId}-${type}`
|
||||||
|
);
|
||||||
|
if (getMsgIds) {
|
||||||
|
return JSON.parse(getMsgIds);
|
||||||
|
} else {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 老师发的言,并且已经上报的缓存起来
|
||||||
|
export function setStorageTeacherMsg({
|
||||||
|
productId,
|
||||||
|
productType = 41,
|
||||||
|
userId,
|
||||||
|
type = 1, // type 1 公共互动 2私聊
|
||||||
|
msg, // 单条消息
|
||||||
|
msgArr, // 多条消息
|
||||||
|
}) {
|
||||||
|
const storageMsgIds = getStorageTeacherMsg({
|
||||||
|
productId,
|
||||||
|
productType,
|
||||||
|
type,
|
||||||
|
userId,
|
||||||
|
});
|
||||||
|
|
||||||
|
let messageIds = [];
|
||||||
|
// userType用户类型:1投顾;2用户;3助教;4运营人员
|
||||||
|
if (msg) {
|
||||||
|
if (!storageMsgIds.includes(msg.id) && msg.userType !== 2) {
|
||||||
|
messageIds = [msg.id];
|
||||||
|
}
|
||||||
|
} else if (msgArr && msgArr.length) {
|
||||||
|
msgArr.forEach((msg) => {
|
||||||
|
if (msg.userType !== 2 && !storageMsgIds.includes(msg.id)) {
|
||||||
|
messageIds.push(msg.id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (messageIds.length) {
|
||||||
|
setTimeout(async () => {
|
||||||
|
let ret = await readMessage({ messageIds }).catch(() => {});
|
||||||
|
if (ret && ret.code === 0) {
|
||||||
|
localStorage.setItem(
|
||||||
|
`read-msg-${productType}-${productId}-${userId}-${type}`,
|
||||||
|
JSON.stringify(messageIds.concat(storageMsgIds))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}, Math.random() * 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -4,6 +4,8 @@ import BScroll from "@better-scroll/core";
|
|||||||
import PullDown from "@better-scroll/pull-down";
|
import PullDown from "@better-scroll/pull-down";
|
||||||
import MouseWheel from "@better-scroll/mouse-wheel";
|
import MouseWheel from "@better-scroll/mouse-wheel";
|
||||||
import useDisableScroll from "@/hooks/useDisableScroll";
|
import useDisableScroll from "@/hooks/useDisableScroll";
|
||||||
|
import { setStorageTeacherMsg } from "./storage";
|
||||||
|
import store from "@/store/index";
|
||||||
|
|
||||||
BScroll.use(PullDown);
|
BScroll.use(PullDown);
|
||||||
BScroll.use(MouseWheel);
|
BScroll.use(MouseWheel);
|
||||||
@ -27,7 +29,7 @@ export default function useChatData({ id, className, type }) {
|
|||||||
groupId: id,
|
groupId: id,
|
||||||
lastId: msgList.value[0]?.id,
|
lastId: msgList.value[0]?.id,
|
||||||
size: 10,
|
size: 10,
|
||||||
type,
|
type, // 查询类型:1全部;2投顾;3用户;4精选;5私聊
|
||||||
});
|
});
|
||||||
if (ret.code === 0) {
|
if (ret.code === 0) {
|
||||||
let list = ret.data.list.reverse() || [];
|
let list = ret.data.list.reverse() || [];
|
||||||
@ -40,6 +42,12 @@ export default function useChatData({ id, className, type }) {
|
|||||||
if (!hasNext.value) {
|
if (!hasNext.value) {
|
||||||
bs.value && bs.value.closePullDown();
|
bs.value && bs.value.closePullDown();
|
||||||
}
|
}
|
||||||
|
setStorageTeacherMsg({
|
||||||
|
productId: id,
|
||||||
|
userId: store.state.userInfo.account,
|
||||||
|
msgArr: list,
|
||||||
|
type: type === 5 ? 2 : 1,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
isPullingDown.value = false;
|
isPullingDown.value = false;
|
||||||
finishPullDown(preHisHeight);
|
finishPullDown(preHisHeight);
|
||||||
@ -67,6 +75,12 @@ export default function useChatData({ id, className, type }) {
|
|||||||
bs.value && bs.value.scrollTo(0, bs.value.maxScrollY, 0);
|
bs.value && bs.value.scrollTo(0, bs.value.maxScrollY, 0);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
setStorageTeacherMsg({
|
||||||
|
productId: id,
|
||||||
|
userId: store.state.userInfo.account,
|
||||||
|
msg,
|
||||||
|
type: type === 5 ? 2 : 1,
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// 刷新消息
|
// 刷新消息
|
||||||
|
|||||||
@ -70,10 +70,16 @@ export default function ({ id, privateMessage, chatMessage }) {
|
|||||||
emitter.emit("cancelGetNewMsg");
|
emitter.emit("cancelGetNewMsg");
|
||||||
// 接收群聊接收消息路径
|
// 接收群聊接收消息路径
|
||||||
chatMessage &&
|
chatMessage &&
|
||||||
(await stompClient.value.subscribe(`/app/group/topic/${id}`, chatMessage));
|
(await stompClient.value.subscribe(
|
||||||
|
`/app/group/topic/${id}`,
|
||||||
|
chatMessage
|
||||||
|
));
|
||||||
// APP端私聊消息
|
// APP端私聊消息
|
||||||
privateMessage &&
|
privateMessage &&
|
||||||
(await stompClient.value.subscribe(`/app/private/topic/${id}/${store.state.userInfo.account}`, privateMessage));
|
(await stompClient.value.subscribe(
|
||||||
|
`/app/private/topic/${id}/${store.state.userInfo.account}`,
|
||||||
|
privateMessage
|
||||||
|
));
|
||||||
};
|
};
|
||||||
stompClient.value.onStompError = (error) => {
|
stompClient.value.onStompError = (error) => {
|
||||||
console.log(error.body);
|
console.log(error.body);
|
||||||
@ -115,7 +121,7 @@ export default function ({ id, privateMessage, chatMessage }) {
|
|||||||
stompClient.value.activate();
|
stompClient.value.activate();
|
||||||
};
|
};
|
||||||
|
|
||||||
connect()
|
connect();
|
||||||
|
|
||||||
window.addEventListener("unload", function (event) {
|
window.addEventListener("unload", function (event) {
|
||||||
stompClient.value && stompClient.value.deactivate();
|
stompClient.value && stompClient.value.deactivate();
|
||||||
|
|||||||
@ -141,7 +141,8 @@ import { useRoute } from "vue-router";
|
|||||||
import { showToast } from "vant";
|
import { showToast } from "vant";
|
||||||
|
|
||||||
import Share from "@/components/Share";
|
import Share from "@/components/Share";
|
||||||
import { likeVideo, queryLiveCoupon } from "@/api/video";
|
// import { likeVideo, queryLiveCoupon } from "@/api/video";
|
||||||
|
import { likeVideo } from "@/api/video";
|
||||||
import emitter from "@/utils/emitter";
|
import emitter from "@/utils/emitter";
|
||||||
import useGetLiveStatusObj from "@/hooks/useGetLiveStatusObj";
|
import useGetLiveStatusObj from "@/hooks/useGetLiveStatusObj";
|
||||||
import QuestionnairePopup from "../components/QuestionnairePopup.vue";
|
import QuestionnairePopup from "../components/QuestionnairePopup.vue";
|
||||||
@ -392,19 +393,19 @@ const showDiscountCoupon = () => {
|
|||||||
emitter.emit("showDiscountCoupon", couponDetail.value);
|
emitter.emit("showDiscountCoupon", couponDetail.value);
|
||||||
};
|
};
|
||||||
|
|
||||||
const getLiveCoupon = async () => {
|
// const getLiveCoupon = async () => {
|
||||||
let ret = await queryLiveCoupon({
|
// let ret = await queryLiveCoupon({
|
||||||
liveId: props.detail.id,
|
// liveId: props.detail.id,
|
||||||
});
|
// });
|
||||||
if (ret.code === 0 && ret.data && ret.data.length) {
|
// if (ret.code === 0 && ret.data && ret.data.length) {
|
||||||
couponDetail.value = ret.data[0];
|
// couponDetail.value = ret.data[0];
|
||||||
couponDetail.value.couponType = Number(couponDetail.value.couponType);
|
// couponDetail.value.couponType = Number(couponDetail.value.couponType);
|
||||||
couponDetail.value.sendCouponId = couponDetail.value.id;
|
// couponDetail.value.sendCouponId = couponDetail.value.id;
|
||||||
}
|
// }
|
||||||
};
|
// };
|
||||||
|
|
||||||
// 获取优惠券
|
// 获取优惠券
|
||||||
getLiveCoupon();
|
// getLiveCoupon();
|
||||||
|
|
||||||
let tipLook = false;
|
let tipLook = false;
|
||||||
const userInTip = (name) => {
|
const userInTip = (name) => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user