|
@@ -8,7 +8,7 @@ import { ref, reactive, toRaw, toRefs, nextTick } from "vue";
|
|
|
import { useRouter, useRoute } from "vue-router";
|
|
|
import useUserStore from "@/store/modules/user";
|
|
|
import word from "@/assets/images/word2.png";
|
|
|
-import chat from "@/assets/images/profile.jpg";
|
|
|
+import chat from "@/assets/images/profile.png";
|
|
|
import cebian from "@/assets/images/cebian.png";
|
|
|
import send from "@/assets/images/send.png";
|
|
|
import downFile from "@/assets/images/down-file.png";
|
|
@@ -95,6 +95,7 @@ const getMsgList = async () => {
|
|
|
msgRecordEvent(sendCont.data.toId);
|
|
|
}
|
|
|
};
|
|
|
+const noMes = ref(false);
|
|
|
//获取用户的聊天记录
|
|
|
const msgRecordEvent = async (toIdValue) => {
|
|
|
const queryParams = {
|
|
@@ -104,6 +105,11 @@ const msgRecordEvent = async (toIdValue) => {
|
|
|
const resMsgData = await msgRecord(toIdValue, queryParams);
|
|
|
resMsgData.rows.map((i) => (i.isForward = false));
|
|
|
chatRecords.data = resMsgData.rows.reverse();
|
|
|
+ const PageNum = Math.ceil(chatRecords.data.length / 10) + 1;
|
|
|
+ if (PageNum * 10 >= resMsgData.total && !noMes.value) {
|
|
|
+ loading.value = false;
|
|
|
+ noMes.value = true;
|
|
|
+ }
|
|
|
const nowtime = parseTime(new Date().getTime(), "{y}-{m}-{d}");
|
|
|
chatRecords.data.map((i) => {
|
|
|
if (nowtime == i.createTime.substr(0, 10))
|
|
@@ -270,10 +276,11 @@ watchEffect(() => {
|
|
|
});
|
|
|
// 滚动翻页========
|
|
|
const mainContainer=ref(null)
|
|
|
-const noMes = ref(false);
|
|
|
+
|
|
|
const handleScroll = (event) => {
|
|
|
// 在滚动到顶部时,加载上一页的聊天记录
|
|
|
const mainContainer2 = document.querySelector(".right-container");
|
|
|
+ console.log(' event.deltaY', mainContainer2.scrollTop,noMes.value,loading.value)
|
|
|
if (
|
|
|
event.deltaY < 0 &&
|
|
|
mainContainer2.scrollTop <= 1 &&
|
|
@@ -290,7 +297,7 @@ const loadPreviousPage = async () => {
|
|
|
pageNum: currentPageNum,
|
|
|
pageSize: 10,
|
|
|
};
|
|
|
- setTimeout(async () => {
|
|
|
+ // setTimeout(async () => {
|
|
|
const resMsgData = await msgRecord(sendCont.data.toId, queryParams);
|
|
|
const previousPageData = resMsgData.rows.reverse();
|
|
|
chatRecords.data = [...previousPageData, ...chatRecords.data];
|
|
@@ -305,16 +312,16 @@ const loadPreviousPage = async () => {
|
|
|
noMes.value = true;
|
|
|
return;
|
|
|
}
|
|
|
- await nextTick();
|
|
|
- const mainContainer = document.querySelector(".right-container");
|
|
|
- const newMessages = document.querySelectorAll(".message-container");
|
|
|
- const firstNewMessage = newMessages[previousPageData.length];
|
|
|
- const firstNewMessageTop = mainContainer.offsetHeight + 100;
|
|
|
- console.log('firstNewMessageTop', firstNewMessageTop)
|
|
|
- mainContainer.scrollTop = firstNewMessageTop;
|
|
|
+ // await nextTick();
|
|
|
+ // const mainContainer = document.querySelector(".right-container");
|
|
|
+ // const newMessages = document.querySelectorAll(".message-container");
|
|
|
+ // const firstNewMessage = newMessages[previousPageData.length];
|
|
|
+ // const firstNewMessageTop = mainContainer.offsetHeight;
|
|
|
+ // console.log('firstNewMessageTop', firstNewMessageTop)
|
|
|
+ // mainContainer.scrollTop = firstNewMessageTop;
|
|
|
// 将加载的上一页聊天记录插入到 chatRecords.data 的前面
|
|
|
loading.value = false;
|
|
|
- }, 50);
|
|
|
+ // }, 50);
|
|
|
};
|
|
|
const transferFiles = (forwardVal, msgIds, indexs) => {
|
|
|
chatRecords.data.map((i, index) => {
|