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.

111 lines
2.7 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>
<div class="l-chat-loadding" v-if="loading" v-loading="true" element-loading-text="消息接收中..."
element-loading-spinner="el-icon-loading" element-loading-background="#eee">
<div class="chat-loading-box"></div>
</div>
<el-scrollbar class="l-chat-list">
<div v-for="(chat,index) in chatStore.chats" :key="index">
<chat-item v-show="chat.showName.startsWith(searchText)" :chat="chat" :index="index"
@click.native="handleActiveItem(index)" @delete="handleDelItem(index)" @top="handleTop(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);
},
2 years ago
handleDelItem(index) {
this.$store.commit("removeChat", index);
2 years ago
},
handleTop(chatIdx) {
this.$store.commit("moveTop", chatIdx);
},
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;
},
loading(){
return this.chatStore.loadingGroupMsg || this.chatStore.loadingPrivateMsg
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-chat-loadding{
height: 50px;
background-color: #eee;
.chat-loading-box{
height: 100%;
}
}
.l-friend-ist {
flex: 1;
}
3 years ago
}
}
</style>