You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.1 KiB

3 years ago
<template>
<el-container>
<el-aside width="250px" class="l-chat-box">
<div class="l-chat-header">
<el-input width="200px" placeholder="搜索" v-model="searchText">
<el-button slot="append" icon="el-icon-search"></el-button>
</el-input>
</div>
<el-scrollbar class="l-chat-list" >
<div v-for="(chat,index) in chatStore.chats" :key="index">
<chat-item :chat="chat" :index="index" @click.native="handleActiveItem(index)" @del="handleDelItem(chat,index)"
:active="index === chatStore.activeIndex"></chat-item>
</div>
</el-scrollbar>
3 years ago
</el-aside>
<el-container class="r-chat-box">
<chat-box v-show="activeChat.targetId>0" :chat="activeChat"></chat-box>
3 years ago
</el-container>
</el-container>
</template>
<script>
import ChatItem from "../components/chat/ChatItem.vue";
import ChatBox from "../components/chat/ChatBox.vue";
3 years ago
export default {
name: "chat",
components: {
ChatItem,
ChatBox
3 years ago
},
data() {
return {
searchText: "",
messageContent: "",
group: {},
groupMembers: []
3 years ago
}
},
methods: {
handleActiveItem(index) {
3 years ago
this.$store.commit("activeChat", index);
},
handleDelItem(chat, index) {
this.$store.commit("removeChat", index);
}
3 years ago
},
computed: {
chatStore() {
return this.$store.state.chatStore;
},
activeChat() {
let index = this.chatStore.activeIndex;
let chats = this.chatStore.chats
3 years ago
if (index >= 0 && chats.length > 0) {
return chats[index];
3 years ago
}
// 当没有激活任何会话时,创建一个空会话,不然控制台会有很多报错
let emptyChat = {
targetId: -1,
showName: "",
headImage: "",
messages: []
3 years ago
}
return emptyChat;
3 years ago
}
}
}
</script>
<style lang="scss">
3 years ago
.el-container {
.l-chat-box {
display: flex;
flex-direction: column;
3 years ago
border: #dddddd solid 1px;
background: white;
3 years ago
width: 3rem;
.l-chat-header {
3 years ago
padding: 5px;
background-color: white;
line-height: 50px;
}
.l-friend-ist{
flex: 1;
}
3 years ago
}
}
</style>