|
@@ -4,8 +4,9 @@ export default {
|
|
|
};
|
|
|
</script>
|
|
|
<script setup>
|
|
|
-import { ref, reactive, toRaw } from "vue";
|
|
|
+import { ref, reactive, toRaw, toRefs } from "vue";
|
|
|
import useUserStore from "@/store/modules/user";
|
|
|
+import word from "@/assets/images/word.png";
|
|
|
import chat from "@/assets/images/profile.jpg";
|
|
|
import cebian from "@/assets/images/cebian.png";
|
|
|
import send from "@/assets/images/send.png";
|
|
@@ -18,8 +19,12 @@ import {
|
|
|
msgSend,
|
|
|
msgRecord,
|
|
|
delMsg,
|
|
|
+ dirTree,
|
|
|
+ fileTree,
|
|
|
+ getConfigKeys,
|
|
|
} from "@/api/chat/msg";
|
|
|
import Addperson from "@/components/AddPerson/index.vue"; //添加人员的弹框
|
|
|
+import FileTreeChoice from "@/components/FileTreeChoice/index.vue"; //选择文件发送的列表
|
|
|
//websocket连接====
|
|
|
import useWebsoctStore from "@/store/modules/websocket";
|
|
|
import { ElMessage } from "element-plus";
|
|
@@ -30,6 +35,9 @@ const userIds = useUserStore();
|
|
|
const height = ref(document.documentElement.clientHeight - 74 + "px;");
|
|
|
const messageText = ref(""); //发送的内容
|
|
|
const headerName = ref("");
|
|
|
+const total = ref(0);
|
|
|
+const sendId = ref(""); //选择发送的文件id
|
|
|
+const openFile = ref(false); //文件目录
|
|
|
const chatRecords = reactive({ data: [] });
|
|
|
const sendCont = reactive({
|
|
|
//发送聊天内容数据组装
|
|
@@ -77,8 +85,31 @@ const getMsgList = async () => {
|
|
|
};
|
|
|
//获取用户的聊天记录
|
|
|
const msgRecordEvent = async (toIdValue) => {
|
|
|
- const resMsgData = await msgRecord(toIdValue);
|
|
|
+ const queryParams = {
|
|
|
+ pageNum: 1,
|
|
|
+ pageSize: 10,
|
|
|
+ };
|
|
|
+ const resMsgData = await msgRecord(toIdValue, queryParams);
|
|
|
chatRecords.data = resMsgData.rows.reverse();
|
|
|
+ total.value = resMsgData.total;
|
|
|
+ console.log('sendId.value',sendId.value)
|
|
|
+ if (sendId.value) {
|
|
|
+ //转换文件名称
|
|
|
+ const res = await getConfigKeys(sendId.value);
|
|
|
+
|
|
|
+ chatRecords.data.forEach((i) => {
|
|
|
+ console.log('i.content', i.content,res.docId)
|
|
|
+ if (i.content == res.docId) {
|
|
|
+ console.log("res.docId======", res.docId);
|
|
|
+ i.content = res.fileName;
|
|
|
+ i.fileType = res.fileType;
|
|
|
+ i.dirId = res.dirId;
|
|
|
+ i.fileSize = res.fileSize;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ sendId.value = "";
|
|
|
+ }
|
|
|
+
|
|
|
};
|
|
|
//点击左侧新建聊天
|
|
|
const open = ref(false);
|
|
@@ -102,6 +133,7 @@ const clickPerson = (index, item) => {
|
|
|
: item.toId == userIds.uid
|
|
|
? item.fromName
|
|
|
: item.toName;
|
|
|
+ noMes.value = false;
|
|
|
clickPersonIndex.value = index;
|
|
|
msgRecordEvent(sendCont.data.toId);
|
|
|
};
|
|
@@ -118,6 +150,7 @@ const delClick = (msgId) => {
|
|
|
proxy.$modal.msgSuccess("删除成功");
|
|
|
});
|
|
|
};
|
|
|
+
|
|
|
//树选中的人传过来的选中人的信息,push进入列表中
|
|
|
const changeMsg = async (val) => {
|
|
|
const resInfo = await userInfo(val.id);
|
|
@@ -141,50 +174,82 @@ const changeMsg = async (val) => {
|
|
|
msgRecordEvent(sendCont.data.toId);
|
|
|
headerName.value = resInfo.nickName;
|
|
|
};
|
|
|
+
|
|
|
//发送聊天
|
|
|
const msgSendClick = () => {
|
|
|
- const message = { content: messageText.value, msgType: "2",fileList: [],toId: sendCont.data.toId, };
|
|
|
- // commonSendMsg(messageText.value, "2");
|
|
|
+ const message = {
|
|
|
+ content: messageText.value,
|
|
|
+ msgType: "2",
|
|
|
+ fileList: [],
|
|
|
+ toId: sendCont.data.toId,
|
|
|
+ }
|
|
|
websoctStore.sendMessage(message);
|
|
|
messageText.value = "";
|
|
|
};
|
|
|
-//发送文件
|
|
|
-const openFile = ref(false);
|
|
|
-const sendFileClick = () => {
|
|
|
- openFile.value = true;
|
|
|
+//发送文件确认按钮
|
|
|
+const fileChangeMsg = async (val) => {
|
|
|
+ const ids=toRefs(val)
|
|
|
+ const message = {
|
|
|
+ content: ids.value,
|
|
|
+ msgType: "1",
|
|
|
+ fileList: [],
|
|
|
+ toId: sendCont.data.toId,
|
|
|
+ };
|
|
|
+ sendId.value =ids.value;
|
|
|
+ websoctStore.sendMessage(message);
|
|
|
+ console.log('sendId.value',sendId.value)
|
|
|
};
|
|
|
-//文件和信息共用的调用
|
|
|
-const commonSendMsg = async (cont, type) => {
|
|
|
- sendCont.data.content = cont;
|
|
|
- sendCont.data.msgType = type;
|
|
|
- const mysendmsg = await msgSend(sendCont.data);
|
|
|
+//点击发送文件图标
|
|
|
+const fileUserTreeData = reactive({ data: {} });
|
|
|
+const sendFileClick = async () => {
|
|
|
+ const resDir = await fileTree(3);
|
|
|
+ fileUserTreeData.data = resDir;
|
|
|
+ toRaw(fileUserTreeData.data);
|
|
|
+ openFile.value = true;
|
|
|
};
|
|
|
-// const confirmFile = () => {
|
|
|
-// // commonSendMsg(messageText.value,"1")
|
|
|
-// };
|
|
|
-// // const handleFileUpdate = (value) => {
|
|
|
-// // // 在这里处理子组件传递过来的文件
|
|
|
-// // console.log(value, "valuevaluevalue"); // 打印子组件传递的数据
|
|
|
-// // };
|
|
|
-// 监听新消息通知
|
|
|
+//获取用户聊天记录
|
|
|
const handleNewMessage = () => {
|
|
|
if (websoctStore.newMessage) {
|
|
|
- msgRecordEvent(sendCont.data.toId);
|
|
|
- ElMessage.success("You have a new message");
|
|
|
+ msgRecordEvent(sendCont.data.toId); //获取用户的聊天记录
|
|
|
websoctStore.newMessage = false; // 重置新消息标记
|
|
|
}
|
|
|
};
|
|
|
+watchEffect(() => {
|
|
|
+ console.log("first", websoctStore.messOne);
|
|
|
+ if (websoctStore.messOne?.fromId) {
|
|
|
+ msgRecordEvent(websoctStore.messOne.fromId);
|
|
|
+ }
|
|
|
+});
|
|
|
+// 滚动翻页========
|
|
|
+const noMes = ref(false);
|
|
|
+const handleScroll = (event) => {
|
|
|
+ // 在滚动到顶部时,加载上一页的聊天记录
|
|
|
+ const mainContainer = document.querySelector(".right-container");
|
|
|
+ if (event.deltaY < 0 && mainContainer.scrollTop <= 1) {
|
|
|
+ loadPreviousPage();
|
|
|
+ }
|
|
|
+};
|
|
|
+const loadPreviousPage = async () => {
|
|
|
+ const currentPageNum = Math.ceil(chatRecords.data.length / 10) + 1;
|
|
|
+ const queryParams = {
|
|
|
+ pageNum: currentPageNum,
|
|
|
+ pageSize: 10,
|
|
|
+ };
|
|
|
+ const resMsgData = await msgRecord(sendCont.data.toId, queryParams);
|
|
|
+ const previousPageData = resMsgData.rows.reverse();
|
|
|
+ if (currentPageNum * 10 >= resMsgData.total && !noMes.value) {
|
|
|
+ noMes.value = true;
|
|
|
+ return ElMessage("无更多聊天记录");
|
|
|
+ }
|
|
|
+ // 将加载的上一页聊天记录插入到 chatRecords.data 的前面
|
|
|
+ chatRecords.data = [...previousPageData, ...chatRecords.data];
|
|
|
+};
|
|
|
+// 滚动翻页========
|
|
|
onMounted(() => {
|
|
|
getMsgList();
|
|
|
websoctStore.connect();
|
|
|
setInterval(handleNewMessage, 1000); // 每秒钟检查是否有新消息
|
|
|
});
|
|
|
-onMounted(() => {
|
|
|
- try {
|
|
|
- getMsgList();
|
|
|
- websoctStore.connect();
|
|
|
- } catch (e) {}
|
|
|
-});
|
|
|
</script>
|
|
|
|
|
|
<template>
|
|
@@ -259,7 +324,11 @@ onMounted(() => {
|
|
|
headerName
|
|
|
}}</el-header>
|
|
|
<!-- 聊天 -->
|
|
|
- <el-main class="right-container">
|
|
|
+ <el-main
|
|
|
+ class="right-container"
|
|
|
+ @mousewheel="handleScroll"
|
|
|
+ ref="mainContainer"
|
|
|
+ >
|
|
|
<div
|
|
|
class="message-container"
|
|
|
v-for="(record, index) in chatRecords.data"
|
|
@@ -269,13 +338,18 @@ onMounted(() => {
|
|
|
}"
|
|
|
:key="index"
|
|
|
>
|
|
|
- <span v-if="useUserStore().uid !== record.toId">{{
|
|
|
- record.content
|
|
|
- }}</span>
|
|
|
+ <div
|
|
|
+ v-if="useUserStore().uid !== record.toId"
|
|
|
+ class="time-text right-back"
|
|
|
+ >
|
|
|
+ <div>{{ record.createTime }}</div>
|
|
|
+ <span>{{ record.content }}</span>
|
|
|
+ </div>
|
|
|
<img :src="chat" class="head-sculpture" />
|
|
|
- <span v-if="useUserStore().uid == record.toId">{{
|
|
|
- record.content
|
|
|
- }}</span>
|
|
|
+ <div v-if="useUserStore().uid == record.toId" class="left-back">
|
|
|
+ <div>{{ record.createTime }}</div>
|
|
|
+ <span>{{ record.content }}</span>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
</el-main>
|
|
|
<!-- 底部 -->
|
|
@@ -286,6 +360,12 @@ onMounted(() => {
|
|
|
class="send-info-file"
|
|
|
@click="sendFileClick"
|
|
|
/>
|
|
|
+ <FileTreeChoice
|
|
|
+ :openFile="openFile"
|
|
|
+ @close="openFile = false"
|
|
|
+ :fileUserTreeData="fileUserTreeData.data"
|
|
|
+ @fileChangeMsg="fileChangeMsg"
|
|
|
+ ></FileTreeChoice>
|
|
|
<el-input
|
|
|
v-model="messageText"
|
|
|
class="w-50 m-2"
|