|
@@ -4,7 +4,7 @@ export default {
|
|
|
};
|
|
|
</script>
|
|
|
<script setup>
|
|
|
-import { ref, reactive, toRaw, toRefs, nextTick, computed, watchEffect } from "vue";
|
|
|
+import { ref, reactive, toRaw, toRefs, nextTick, computed, watchEffect,onMounted } from "vue";
|
|
|
import { useRouter, useRoute } from "vue-router";
|
|
|
import useUserStore from "@/store/modules/user";
|
|
|
import word from "@/assets/images/word2.png";
|
|
@@ -35,12 +35,13 @@ import forwordTree from "@/components/forwordTree/index.vue"; //选择文件发
|
|
|
//websocket连接====
|
|
|
import useWebsoctStore from "@/store/modules/websocket";
|
|
|
import { ElMessage } from "element-plus";
|
|
|
-const route = useRoute();
|
|
|
+const router = useRouter(); //注册路由
|
|
|
const websoctStore = useWebsoctStore();
|
|
|
//====
|
|
|
const { proxy } = getCurrentInstance();
|
|
|
const userIds = useUserStore();
|
|
|
-const height = ref(document.documentElement.clientHeight - 74 + "px;");
|
|
|
+// main元素的初始高度,在onMounted时需要重新计算
|
|
|
+let height = ref(document.documentElement.clientHeight - 16 + "px;");
|
|
|
const messageText = ref(""); //发送的内容
|
|
|
const headerName = ref("");
|
|
|
const total = ref(0);
|
|
@@ -75,12 +76,17 @@ const getMsgList = async () => {
|
|
|
// );
|
|
|
|
|
|
searchData.value = personList.data;
|
|
|
+ if (clickPersonId.value ==0 && personList.data.length>0) {
|
|
|
+ clickPersonId.value = personList.data[0].fromId
|
|
|
+ }
|
|
|
//圆点======
|
|
|
+ /*
|
|
|
searchData.value.map((i) => {
|
|
|
if (i.fromId == websoctStore.messOne?.fromId) {
|
|
|
i.showCircel = true;
|
|
|
}
|
|
|
});
|
|
|
+ */
|
|
|
//圆点======
|
|
|
sendCont.data.toId =
|
|
|
personList.data[0]?.toId == userIds.uid
|
|
@@ -99,6 +105,7 @@ const noMes = ref(false);
|
|
|
const boottmScroll = () => {
|
|
|
//发送消息后滚动到最底部显示最新消息
|
|
|
const chatContainer = document.querySelector(".right-container");
|
|
|
+ if(chatContainer==null) return
|
|
|
// 计算滚动的目标位置
|
|
|
const targetScrollTop = chatContainer.scrollHeight;
|
|
|
// 设置滚动位置
|
|
@@ -126,7 +133,16 @@ const msgRecordEvent = async (toIdValue) => {
|
|
|
i.createTime = i.createTime.substring(11);
|
|
|
});
|
|
|
total.value = resMsgData.total;
|
|
|
- boottmScroll();
|
|
|
+ boottmScroll();
|
|
|
+ setTimeout(() => {
|
|
|
+ if(websoctStore.noReadList==null) return;
|
|
|
+ if(websoctStore.noReadList[sendCont.data.toId]!=null) delete websoctStore.noReadList[sendCont.data.toId]
|
|
|
+ let i=0
|
|
|
+ for(let k in websoctStore.noReadList){
|
|
|
+ i++
|
|
|
+ }
|
|
|
+ if(i==0) websoctStore.noReadList = null;
|
|
|
+ }, 1000);
|
|
|
};
|
|
|
//点击左侧新建聊天
|
|
|
const open = ref(false);
|
|
@@ -139,6 +155,7 @@ const clickNewPerson = async () => {
|
|
|
};
|
|
|
//点击左侧聊天列表
|
|
|
const clickPersonIndex = ref("");
|
|
|
+const clickPersonId = ref(0);
|
|
|
const clickPerson = (index, item) => {
|
|
|
sendCont.data.toId = item.userId
|
|
|
? item.userId
|
|
@@ -152,6 +169,7 @@ const clickPerson = (index, item) => {
|
|
|
: item.toName;
|
|
|
noMes.value = false;
|
|
|
clickPersonIndex.value = index;
|
|
|
+ clickPersonId.value = sendCont.data.toId;
|
|
|
//点击某个人就不显示红点
|
|
|
searchData.value.map((i) => {
|
|
|
if (i.fromId == item.fromId) {
|
|
@@ -163,7 +181,7 @@ const clickPerson = (index, item) => {
|
|
|
const targetScrollTop = chatContainer.scrollHeight;
|
|
|
// 设置滚动位置
|
|
|
chatContainer.scrollTop = targetScrollTop;
|
|
|
- msgRecordEvent(sendCont.data.toId);
|
|
|
+ msgRecordEvent(sendCont.data.toId);
|
|
|
};
|
|
|
//删除聊天
|
|
|
const delClick = (msgId) => {
|
|
@@ -270,9 +288,24 @@ const handleNewMessage = async () => {
|
|
|
};
|
|
|
|
|
|
watchEffect(async() => {
|
|
|
- if (websoctStore.messOne?.fromId) {
|
|
|
+ console.log("===============有新消息了:",websoctStore.messOne)
|
|
|
+ console.log(router.currentRoute.value.path)
|
|
|
+ if(router.currentRoute.value.path!='/index') return;
|
|
|
+ console.log("clickPersonId:",clickPersonId.value)
|
|
|
+ if(websoctStore.noReadList!=null) {
|
|
|
+ if(clickPersonId.value!=websoctStore.messOne.fromId){
|
|
|
+ for(let i=0;i<searchData.value.length;i++){
|
|
|
+ if(searchData.value[i].fromId==websoctStore.messOne.fromId){
|
|
|
+ searchData.value[i].showCircel = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
msgRecordEvent(websoctStore.messOne.fromId);
|
|
|
- // getYuan()
|
|
|
+ setTimeout(() => {
|
|
|
+ websoctStore.messOne={}
|
|
|
+ }, 1000);
|
|
|
+ // getYuan()
|
|
|
getMsgList();
|
|
|
}
|
|
|
});
|
|
@@ -411,6 +444,7 @@ const formatText = (text) => {
|
|
|
}
|
|
|
// 滚动翻页========
|
|
|
onMounted(() => {
|
|
|
+ height.value = document.documentElement.clientHeight - document.getElementsByClassName("tab_box")[0].offsetHeight-8-document.getElementsByClassName("nav")[0].offsetHeight -26 + "px";
|
|
|
getMsgList();
|
|
|
websoctStore.connect();
|
|
|
setInterval(handleNewMessage, 1000); // 每秒钟检查是否有新消息
|
|
@@ -508,7 +542,7 @@ onMounted(() => {
|
|
|
</div>
|
|
|
<span
|
|
|
class="yuandian"
|
|
|
- v-if="item.showCircel && $route.path == '/index'"
|
|
|
+ v-if="item.showCircel && $route.path == '/index' && clickPersonId!==item.fromId"
|
|
|
></span>
|
|
|
</div>
|
|
|
</div>
|