|
|
@@ -1,6 +1,6 @@
|
|
|
<script>
|
|
|
export default {
|
|
|
- name: "index2",
|
|
|
+ name: "index",
|
|
|
};
|
|
|
</script>
|
|
|
<script setup>
|
|
|
@@ -11,13 +11,15 @@ import send from "@/assets/images/send.png";
|
|
|
import sendFile from "@/assets/images/send-file.png";
|
|
|
import store from "@/store";
|
|
|
import { msgFriend } from "@/api/chat/msg";
|
|
|
+import Addperson from "@/components/AddPerson/index.vue"; //添加人员的弹框
|
|
|
//websocket连接====
|
|
|
-import useWebsoctStore from '@/store/modules/websocket'
|
|
|
-const websoctStore = useWebsoctStore()
|
|
|
-
|
|
|
+import useWebsoctStore from "@/store/modules/websocket";
|
|
|
+const websoctStore = useWebsoctStore();
|
|
|
//====
|
|
|
+
|
|
|
const height = ref(document.documentElement.clientHeight - 74 + "px;");
|
|
|
const searchText = ref(""); //搜
|
|
|
+const messageText = ref(""); //发送的内容
|
|
|
const SearchChat = () => {}; //搜索的点击事件
|
|
|
//聊天列表数据模拟
|
|
|
const personList = reactive({
|
|
|
@@ -39,27 +41,37 @@ const personList = reactive({
|
|
|
function getMsgList() {
|
|
|
msgFriend().then((res) => {
|
|
|
// personList.data=res.rows
|
|
|
- })
|
|
|
+ });
|
|
|
}
|
|
|
-const chatRecords= reactive( [
|
|
|
- { sender: 'friend', content: 'Hello' },
|
|
|
- { sender: 'me', content: 'Hi' },
|
|
|
- { sender: 'me', content: 'How are you?' },
|
|
|
- { sender: 'friend', content: 'I am fine, thanks!' },
|
|
|
- ])
|
|
|
+const chatRecords = reactive([
|
|
|
+ { sender: "friend", content: "Hello" },
|
|
|
+ { sender: "me", content: "Hi" },
|
|
|
+ { sender: "me", content: "How are you?" },
|
|
|
+ { sender: "friend", content: "I am fine, thanks!" },
|
|
|
+]);
|
|
|
+//点击左侧新建聊天
|
|
|
+const open = ref(false);
|
|
|
+const clickNewPerson = () => {
|
|
|
+ open.value = true;
|
|
|
+ console.log("1111", 1111);
|
|
|
+};
|
|
|
//点击左侧聊天列表
|
|
|
const clickPersonIndex = ref("");
|
|
|
const clickPerson = (index) => {
|
|
|
clickPersonIndex.value = index;
|
|
|
};
|
|
|
+//发送聊天点击事件
|
|
|
+const messageChat = () => {
|
|
|
+ const message = { text: messageText.value };
|
|
|
+ websoctStore.send(message);
|
|
|
+ messageText.value = "";
|
|
|
+};
|
|
|
onMounted(() => {
|
|
|
- try {
|
|
|
+ try {
|
|
|
getMsgList();
|
|
|
- websoctStore.connect()
|
|
|
- } catch (e) {
|
|
|
- }
|
|
|
-})
|
|
|
-
|
|
|
+ websoctStore.connect();
|
|
|
+ } catch (e) {}
|
|
|
+});
|
|
|
</script>
|
|
|
|
|
|
<template>
|
|
|
@@ -75,7 +87,22 @@ onMounted(() => {
|
|
|
suffix-icon="Search"
|
|
|
@change="SearchChat"
|
|
|
/>
|
|
|
- <el-icon size="24" color="#505870"><Plus /></el-icon>
|
|
|
+ <!-- 添加聊天人员 -->
|
|
|
+ <el-icon size="24" color="#505870" @click="clickNewPerson"
|
|
|
+ ><Plus
|
|
|
+ /></el-icon>
|
|
|
+ <Addperson :open="open" @close="open = false"></Addperson>
|
|
|
+ <!-- <el-dialog
|
|
|
+ title="新建聊天"
|
|
|
+ append-to-body
|
|
|
+ v-model="open"
|
|
|
+ style="
|
|
|
+ width: 512px;
|
|
|
+ height: 428px;
|
|
|
+ "
|
|
|
+ >
|
|
|
+ <Addperson></Addperson>
|
|
|
+ </el-dialog> -->
|
|
|
</div>
|
|
|
<div
|
|
|
:class="
|
|
|
@@ -109,16 +136,16 @@ onMounted(() => {
|
|
|
<el-main class="right-container">
|
|
|
<div
|
|
|
class="message-container"
|
|
|
- v-for="(record,index) in chatRecords"
|
|
|
+ v-for="(record, index) in chatRecords"
|
|
|
:class="{
|
|
|
'message-left': record.sender !== 'me',
|
|
|
'message-right': record.sender === 'me',
|
|
|
}"
|
|
|
:key="index"
|
|
|
>
|
|
|
- <span v-if="record.sender == 'me'">{{ record.content }}</span>
|
|
|
- <img :src="chat" class="head-sculpture"/>
|
|
|
- <span v-if="record.sender !== 'me'">{{ record.content }}</span>
|
|
|
+ <span v-if="record.sender == 'me'">{{ record.content }}</span>
|
|
|
+ <img :src="chat" class="head-sculpture" />
|
|
|
+ <span v-if="record.sender !== 'me'">{{ record.content }}</span>
|
|
|
</div>
|
|
|
<!-- <div class="chat-message">
|
|
|
<div class="chat-item" :class="{'chat-item-out':item.sender=='out'}" v-for="(item,index) in chatRecords" :key="index">
|
|
|
@@ -135,11 +162,11 @@ onMounted(() => {
|
|
|
<el-footer height="72px" class="right-footer">
|
|
|
<img :src="sendFile" class="send-info-file" />
|
|
|
<el-input
|
|
|
- v-model="searchText"
|
|
|
+ v-model="messageText"
|
|
|
class="w-50 m-2"
|
|
|
size="small"
|
|
|
placeholder="请输入聊天内容"
|
|
|
- @change="SearchChat"
|
|
|
+ @change="messageChat"
|
|
|
/>
|
|
|
<img :src="send" class="send-info" />
|
|
|
</el-footer>
|