|
|
@ -25,7 +25,7 @@ |
|
|
<li v-for="item in messages" :key="item.id" |
|
|
<li v-for="item in messages" :key="item.id" |
|
|
:class="{ 'im-chat-mine': item.sendUserId == $store.state.userStore.userInfo.id }"> |
|
|
:class="{ 'im-chat-mine': item.sendUserId == $store.state.userStore.userInfo.id }"> |
|
|
<div class="head-image"> |
|
|
<div class="head-image"> |
|
|
<head-image :url="headImage" ></head-image> |
|
|
<head-image :url="headImage(item)" ></head-image> |
|
|
</div> |
|
|
</div> |
|
|
<div class="im-msg-content"> |
|
|
<div class="im-msg-content"> |
|
|
<div class="im-msg-top"> |
|
|
<div class="im-msg-top"> |
|
|
@ -41,7 +41,8 @@ |
|
|
|
|
|
|
|
|
</div> |
|
|
</div> |
|
|
</el-main> |
|
|
</el-main> |
|
|
<el-footer height="150px" class="im-chat-footer"> |
|
|
<el-footer height="25%" class="im-chat-footer"> |
|
|
|
|
|
<div class="chat-tool-bar"></div> |
|
|
<textarea v-model="messageContent" ref="sendBox" class="textarea" @keyup.enter="onSendMessage()"></textarea> |
|
|
<textarea v-model="messageContent" ref="sendBox" class="textarea" @keyup.enter="onSendMessage()"></textarea> |
|
|
<div class="im-chat-send"> |
|
|
<div class="im-chat-send"> |
|
|
<el-button type="primary" @click="onSendMessage()">发送</el-button> |
|
|
<el-button type="primary" @click="onSendMessage()">发送</el-button> |
|
|
@ -72,6 +73,19 @@ |
|
|
methods: { |
|
|
methods: { |
|
|
onClickItem(index) { |
|
|
onClickItem(index) { |
|
|
this.$store.commit("activeChat", index); |
|
|
this.$store.commit("activeChat", index); |
|
|
|
|
|
// 获取对方 |
|
|
|
|
|
let userId = this.chatStore.chats[index].targetId; |
|
|
|
|
|
this.$http({ |
|
|
|
|
|
url: `/api/user/find/${userId}`, |
|
|
|
|
|
method: 'get' |
|
|
|
|
|
}).then((userInfo) => { |
|
|
|
|
|
// 如果发现好友的头像和昵称改了,进行更新 |
|
|
|
|
|
let chat = this.chatStore.chats[index]; |
|
|
|
|
|
if (userInfo.headImageThumb != chat.headImage || |
|
|
|
|
|
userInfo.nickName != chat.showName) { |
|
|
|
|
|
this.updateFriendInfo(userInfo,index) |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
}, |
|
|
}, |
|
|
onSendMessage() { |
|
|
onSendMessage() { |
|
|
let msgInfo = { |
|
|
let msgInfo = { |
|
|
@ -89,8 +103,9 @@ |
|
|
msgInfo.sendTime = new Date().getTime(); |
|
|
msgInfo.sendTime = new Date().getTime(); |
|
|
msgInfo.sendUserId = this.$store.state.userStore.userInfo.id; |
|
|
msgInfo.sendUserId = this.$store.state.userStore.userInfo.id; |
|
|
msgInfo.selfSend = true; |
|
|
msgInfo.selfSend = true; |
|
|
|
|
|
console.log(msgInfo); |
|
|
this.$store.commit("insertMessage", msgInfo); |
|
|
this.$store.commit("insertMessage", msgInfo); |
|
|
console.log(this.$refs.sendBox) |
|
|
|
|
|
// 保持输入框焦点 |
|
|
// 保持输入框焦点 |
|
|
this.$refs.sendBox.focus(); |
|
|
this.$refs.sendBox.focus(); |
|
|
// 滚动到底部 |
|
|
// 滚动到底部 |
|
|
@ -105,43 +120,67 @@ |
|
|
onDelItem(chat,index){ |
|
|
onDelItem(chat,index){ |
|
|
this.$store.commit("removeChat",index); |
|
|
this.$store.commit("removeChat",index); |
|
|
}, |
|
|
}, |
|
|
showName(item) { |
|
|
updateFriendInfo(userInfo,index){ |
|
|
if (item.sendUserId == this.$store.state.userStore.userInfo.id) { |
|
|
let friendsInfo={ |
|
|
|
|
|
friendId: userInfo.id, |
|
|
|
|
|
friendNickName: userInfo.nickName, |
|
|
|
|
|
friendHeadImage: userInfo.headImageThumb |
|
|
|
|
|
}; |
|
|
|
|
|
this.$http({ |
|
|
|
|
|
url: "/api/friends/update", |
|
|
|
|
|
method: "put", |
|
|
|
|
|
data: friendsInfo |
|
|
|
|
|
}).then(() => { |
|
|
|
|
|
this.$store.commit("updateFriends",friendsInfo); |
|
|
|
|
|
this.$store.commit("setChatUserInfo",userInfo); |
|
|
|
|
|
}) |
|
|
|
|
|
}, |
|
|
|
|
|
showName(msg) { |
|
|
|
|
|
if (msg.sendUserId == this.$store.state.userStore.userInfo.id) { |
|
|
return this.$store.state.userStore.userInfo.nickName; |
|
|
return this.$store.state.userStore.userInfo.nickName; |
|
|
} else { |
|
|
} else { |
|
|
let index = this.$store.state.chatStore.activeIndex; |
|
|
let index = this.$store.state.chatStore.activeIndex; |
|
|
let chats = this.$store.state.chatStore.chats |
|
|
let chats = this.$store.state.chatStore.chats |
|
|
return chats[index].showName; |
|
|
return chats[index].showName; |
|
|
} |
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
headImage(msg){ |
|
|
|
|
|
if(msg.sendUserId == this.$store.state.userStore.userInfo.id){ |
|
|
|
|
|
return this.$store.state.userStore.userInfo.headImageThumb; |
|
|
|
|
|
}else{ |
|
|
|
|
|
let index = this.$store.state.chatStore.activeIndex; |
|
|
|
|
|
let chats = this.$store.state.chatStore.chats |
|
|
|
|
|
if(index>=0 && chats.length > 0){ |
|
|
|
|
|
let chats = this.$store.state.chatStore.chats; |
|
|
|
|
|
return chats[index].headImage; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return ""; |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
computed: { |
|
|
computed: { |
|
|
|
|
|
chatStore(){ |
|
|
|
|
|
return this.$store.state.chatStore; |
|
|
|
|
|
}, |
|
|
messages() { |
|
|
messages() { |
|
|
let index = this.$store.state.chatStore.activeIndex; |
|
|
let index = this.$store.state.chatStore.activeIndex; |
|
|
let chats = this.$store.state.chatStore.chats |
|
|
let chats = this.$store.state.chatStore.chats |
|
|
if (index >= 0 && chats.length > 0) { |
|
|
if (index >= 0 && chats.length > 0) { |
|
|
|
|
|
console.log(chats[index].messages) |
|
|
return chats[index].messages; |
|
|
return chats[index].messages; |
|
|
} |
|
|
} |
|
|
return []; |
|
|
return []; |
|
|
}, |
|
|
}, |
|
|
titleName(){ |
|
|
titleName(){ |
|
|
let index = this.$store.state.chatStore.activeIndex; |
|
|
let index = this.$store.state.chatStore.activeIndex; |
|
|
let chats = this.$store.state.chatStore.chats |
|
|
|
|
|
if(index>=0 && chats.length > 0){ |
|
|
|
|
|
let chats = this.$store.state.chatStore.chats; |
|
|
let chats = this.$store.state.chatStore.chats; |
|
|
return chats[index].showName; |
|
|
|
|
|
} |
|
|
|
|
|
return ""; |
|
|
|
|
|
}, |
|
|
|
|
|
headImage(){ |
|
|
|
|
|
let index = this.$store.state.chatStore.activeIndex; |
|
|
|
|
|
let chats = this.$store.state.chatStore.chats |
|
|
|
|
|
if(index>=0 && chats.length > 0){ |
|
|
if(index>=0 && chats.length > 0){ |
|
|
let chats = this.$store.state.chatStore.chats; |
|
|
let chats = this.$store.state.chatStore.chats; |
|
|
return chats[index].headImage; |
|
|
return chats[index].showName; |
|
|
} |
|
|
} |
|
|
return ""; |
|
|
return ""; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
</script> |
|
|
</script> |
|
|
@ -300,6 +339,11 @@ |
|
|
flex-direction: column; |
|
|
flex-direction: column; |
|
|
padding: 0; |
|
|
padding: 0; |
|
|
|
|
|
|
|
|
|
|
|
.chat-tool-bar { |
|
|
|
|
|
width: 100%; |
|
|
|
|
|
height: 40px; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
textarea { |
|
|
textarea { |
|
|
box-sizing: border-box; |
|
|
box-sizing: border-box; |
|
|
padding: 5px; |
|
|
padding: 5px; |
|
|
|