|
|
@ -1,29 +1,30 @@ |
|
|
<template> |
|
|
<template> |
|
|
<el-container> |
|
|
<el-container > |
|
|
<el-aside width="80px" class="navi-bar"> |
|
|
<el-aside width="80px" class="navi-bar"> |
|
|
<div class="user-head-image" @click="onClickHeadImage"> |
|
|
<div class="user-head-image"> |
|
|
<head-image :url="$store.state.userStore.userInfo.headImageThumb" > </head-image> |
|
|
<head-image :url="$store.state.userStore.userInfo.headImageThumb" :size="60" |
|
|
|
|
|
@click.native="showSettingDialog=true"> </head-image> |
|
|
</div> |
|
|
</div> |
|
|
|
|
|
|
|
|
<el-menu background-color="#333333" text-color="#ddd" style="margin-top: 30px;" > |
|
|
<el-menu background-color="#333333" text-color="#ddd" style="margin-top: 30px;"> |
|
|
<el-menu-item title="聊天"> |
|
|
<el-menu-item title="聊天"> |
|
|
<router-link v-bind:to="'/home/chat'"> |
|
|
<router-link v-bind:to="'/home/chat'"> |
|
|
<span class="el-icon-chat-dot-round"></span> |
|
|
<span class="el-icon-chat-dot-round"></span> |
|
|
</router-link> |
|
|
</router-link> |
|
|
</el-menu-item > |
|
|
</el-menu-item> |
|
|
<el-menu-item title="好友" > |
|
|
<el-menu-item title="好友"> |
|
|
<router-link v-bind:to="'/home/friend'"> |
|
|
<router-link v-bind:to="'/home/friend'"> |
|
|
<span class="el-icon-user"></span> |
|
|
<span class="el-icon-user"></span> |
|
|
</router-link> |
|
|
</router-link> |
|
|
</el-menu-item> |
|
|
</el-menu-item> |
|
|
<el-menu-item title="群聊" > |
|
|
<el-menu-item title="群聊"> |
|
|
<router-link v-bind:to="'/home/group'"> |
|
|
<router-link v-bind:to="'/home/group'"> |
|
|
<span class="el-icon-s-check"></span> |
|
|
<span class="el-icon-s-check"></span> |
|
|
</router-link> |
|
|
</router-link> |
|
|
</el-menu-item> |
|
|
</el-menu-item> |
|
|
|
|
|
|
|
|
<el-menu-item title="设置" @click="onClickSetting()" > |
|
|
<el-menu-item title="设置" @click="onClickSetting()"> |
|
|
<span class="el-icon-setting"></span> |
|
|
<span class="el-icon-setting"></span> |
|
|
</el-menu-item> |
|
|
</el-menu-item> |
|
|
</el-menu> |
|
|
</el-menu> |
|
|
<div class="exit-box" @click="handleExit()" title="退出"> |
|
|
<div class="exit-box" @click="handleExit()" title="退出"> |
|
|
@ -34,50 +35,61 @@ |
|
|
<router-view></router-view> |
|
|
<router-view></router-view> |
|
|
</el-main> |
|
|
</el-main> |
|
|
<setting :visible="showSettingDialog" @close="onCloseSetting()"></setting> |
|
|
<setting :visible="showSettingDialog" @close="onCloseSetting()"></setting> |
|
|
|
|
|
<user-info v-show="uiStore.userInfo.show" |
|
|
|
|
|
:pos="uiStore.userInfo.pos" |
|
|
|
|
|
:user="uiStore.userInfo.user" |
|
|
|
|
|
@close="$store.commit('closeUserInfoBox')"></user-info> |
|
|
|
|
|
<full-image :visible="uiStore.fullImage.show" |
|
|
|
|
|
:url="uiStore.fullImage.url" |
|
|
|
|
|
@close="$store.commit('closeFullImageBox')" |
|
|
|
|
|
></full-image> |
|
|
</el-container> |
|
|
</el-container> |
|
|
</template> |
|
|
</template> |
|
|
|
|
|
|
|
|
<script> |
|
|
<script> |
|
|
import HeadImage from '../components/common/HeadImage.vue'; |
|
|
import HeadImage from '../components/common/HeadImage.vue'; |
|
|
import Setting from '../components/setting/Setting.vue'; |
|
|
import Setting from '../components/setting/Setting.vue'; |
|
|
|
|
|
import UserInfo from '../components/common/UserInfo.vue'; |
|
|
|
|
|
import FullImage from '../components/common/FullImage.vue'; |
|
|
|
|
|
|
|
|
export default { |
|
|
export default { |
|
|
components:{HeadImage,Setting}, |
|
|
components: { |
|
|
data(){ |
|
|
HeadImage, |
|
|
|
|
|
Setting, |
|
|
|
|
|
UserInfo, |
|
|
|
|
|
FullImage |
|
|
|
|
|
}, |
|
|
|
|
|
data() { |
|
|
return { |
|
|
return { |
|
|
showSettingDialog: false |
|
|
showSettingDialog: false |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
methods: { |
|
|
methods: { |
|
|
init(userInfo){ |
|
|
init(userInfo) { |
|
|
this.$store.commit("setUserInfo", userInfo); |
|
|
this.$store.commit("setUserInfo", userInfo); |
|
|
this.$store.commit("initStore"); |
|
|
this.$store.commit("initStore"); |
|
|
console.log("socket"); |
|
|
this.$wsApi.createWebSocket("ws://localhost:8878/im", this.$store); |
|
|
this.$wsApi.createWebSocket("ws://localhost:8878/im",this.$store); |
|
|
this.$wsApi.onopen(() => { |
|
|
this.$wsApi.onopen(()=>{ |
|
|
|
|
|
console.log("pullUnreadMessage") |
|
|
|
|
|
this.pullUnreadMessage(); |
|
|
this.pullUnreadMessage(); |
|
|
}); |
|
|
}); |
|
|
this.$wsApi.onmessage((e)=>{ |
|
|
this.$wsApi.onmessage((e) => { |
|
|
console.log(e); |
|
|
if (e.cmd == 2) { |
|
|
if(e.cmd == 2){ |
|
|
|
|
|
// 异地登录,强制下线 |
|
|
// 异地登录,强制下线 |
|
|
this.$message.error("您已在其他地方登陆,将被强制下线"); |
|
|
this.$message.error("您已在其他地方登陆,将被强制下线"); |
|
|
setTimeout(()=>{ |
|
|
setTimeout(() => { |
|
|
location.href="/"; |
|
|
location.href = "/"; |
|
|
},1000) |
|
|
}, 1000) |
|
|
|
|
|
|
|
|
} |
|
|
} else if (e.cmd == 3) { |
|
|
else if(e.cmd==3){ |
|
|
|
|
|
// 插入私聊消息 |
|
|
// 插入私聊消息 |
|
|
this.handlePrivateMessage(e.data); |
|
|
this.handlePrivateMessage(e.data); |
|
|
}else if(e.cmd == 4){ |
|
|
} else if (e.cmd == 4) { |
|
|
// 插入群聊消息 |
|
|
// 插入群聊消息 |
|
|
this.handleGroupMessage(e.data); |
|
|
this.handleGroupMessage(e.data); |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
}, |
|
|
}, |
|
|
pullUnreadMessage(){ |
|
|
pullUnreadMessage() { |
|
|
// 拉取未读私聊消息 |
|
|
// 拉取未读私聊消息 |
|
|
this.$http({ |
|
|
this.$http({ |
|
|
url: "/api/message/private/pullUnreadMessage", |
|
|
url: "/api/message/private/pullUnreadMessage", |
|
|
@ -89,25 +101,23 @@ |
|
|
method: 'post' |
|
|
method: 'post' |
|
|
}); |
|
|
}); |
|
|
}, |
|
|
}, |
|
|
handlePrivateMessage(msg){ |
|
|
handlePrivateMessage(msg) { |
|
|
// 好友列表存在好友信息,直接插入私聊消息 |
|
|
// 好友列表存在好友信息,直接插入私聊消息 |
|
|
let friend = this.$store.state.friendStore.friends.find((f)=>f.id==msg.sendId); |
|
|
let friend = this.$store.state.friendStore.friends.find((f) => f.id == msg.sendId); |
|
|
if(friend){ |
|
|
if (friend) { |
|
|
this.insertPrivateMessage(friend,msg); |
|
|
this.insertPrivateMessage(friend, msg); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
// 好友列表不存在好友信息,则发请求获取好友信息 |
|
|
// 好友列表不存在好友信息,则发请求获取好友信息 |
|
|
this.$http({ |
|
|
this.$http({ |
|
|
url: `/api/friend/find/${msg.sendId}`, |
|
|
url: `/api/friend/find/${msg.sendId}`, |
|
|
method: 'get' |
|
|
method: 'get' |
|
|
}).then((friend)=>{ |
|
|
}).then((friend) => { |
|
|
this.insertPrivateMessage(friend,msg); |
|
|
this.insertPrivateMessage(friend, msg); |
|
|
this.$store.commit("addFriend",friend); |
|
|
this.$store.commit("addFriend", friend); |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}, |
|
|
}, |
|
|
insertPrivateMessage(friend,msg){ |
|
|
insertPrivateMessage(friend, msg) { |
|
|
let chatInfo = { |
|
|
let chatInfo = { |
|
|
type: 'PRIVATE', |
|
|
type: 'PRIVATE', |
|
|
targetId: friend.id, |
|
|
targetId: friend.id, |
|
|
@ -115,27 +125,27 @@ |
|
|
headImage: friend.headImage |
|
|
headImage: friend.headImage |
|
|
}; |
|
|
}; |
|
|
// 打开会话 |
|
|
// 打开会话 |
|
|
this.$store.commit("openChat",chatInfo); |
|
|
this.$store.commit("openChat", chatInfo); |
|
|
// 插入消息 |
|
|
// 插入消息 |
|
|
this.$store.commit("insertMessage",msg); |
|
|
this.$store.commit("insertMessage", msg); |
|
|
}, |
|
|
}, |
|
|
handleGroupMessage(msg){ |
|
|
handleGroupMessage(msg) { |
|
|
// 群聊缓存存在,直接插入群聊消息 |
|
|
// 群聊缓存存在,直接插入群聊消息 |
|
|
let group = this.$store.state.groupStore.groups.find((g)=>g.id==msg.groupId); |
|
|
let group = this.$store.state.groupStore.groups.find((g) => g.id == msg.groupId); |
|
|
if(group){ |
|
|
if (group) { |
|
|
this.insertGroupMessage(group,msg); |
|
|
this.insertGroupMessage(group, msg); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
// 群聊缓存存在,直接插入群聊消息 |
|
|
// 群聊缓存存在,直接插入群聊消息 |
|
|
this.$http({ |
|
|
this.$http({ |
|
|
url: `/api/group/find/${msg.groupId}`, |
|
|
url: `/api/group/find/${msg.groupId}`, |
|
|
method: 'get' |
|
|
method: 'get' |
|
|
}).then((group)=>{ |
|
|
}).then((group) => { |
|
|
this.insertGroupMessage(group,msg); |
|
|
this.insertGroupMessage(group, msg); |
|
|
this.$store.commit("addGroup",group); |
|
|
this.$store.commit("addGroup", group); |
|
|
}) |
|
|
}) |
|
|
}, |
|
|
}, |
|
|
insertGroupMessage(group,msg){ |
|
|
insertGroupMessage(group, msg) { |
|
|
let chatInfo = { |
|
|
let chatInfo = { |
|
|
type: 'GROUP', |
|
|
type: 'GROUP', |
|
|
targetId: group.id, |
|
|
targetId: group.id, |
|
|
@ -143,29 +153,31 @@ |
|
|
headImage: group.headImageThumb |
|
|
headImage: group.headImageThumb |
|
|
}; |
|
|
}; |
|
|
// 打开会话 |
|
|
// 打开会话 |
|
|
this.$store.commit("openChat",chatInfo); |
|
|
this.$store.commit("openChat", chatInfo); |
|
|
// 插入消息 |
|
|
// 插入消息 |
|
|
this.$store.commit("insertMessage",msg); |
|
|
this.$store.commit("insertMessage", msg); |
|
|
}, |
|
|
}, |
|
|
handleExit(){ |
|
|
handleExit() { |
|
|
this.$http({ |
|
|
this.$http({ |
|
|
url: "/api/logout", |
|
|
url: "/api/logout", |
|
|
method: 'get' |
|
|
method: 'get' |
|
|
}).then(()=>{ |
|
|
}).then(() => { |
|
|
this.$wsApi.closeWebSocket(); |
|
|
this.$wsApi.closeWebSocket(); |
|
|
location.href="/"; |
|
|
location.href = "/"; |
|
|
}) |
|
|
}) |
|
|
}, |
|
|
}, |
|
|
onClickHeadImage(){ |
|
|
onClickSetting() { |
|
|
this.$message.success(JSON.stringify(this.$store.state.userStore.userInfo)); |
|
|
|
|
|
}, |
|
|
|
|
|
onClickSetting(){ |
|
|
|
|
|
this.showSettingDialog = true; |
|
|
this.showSettingDialog = true; |
|
|
}, |
|
|
}, |
|
|
onCloseSetting(){ |
|
|
onCloseSetting() { |
|
|
this.showSettingDialog = false; |
|
|
this.showSettingDialog = false; |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
|
|
|
computed:{ |
|
|
|
|
|
uiStore(){ |
|
|
|
|
|
return this.$store.state.uiStore; |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
mounted() { |
|
|
mounted() { |
|
|
this.$http({ |
|
|
this.$http({ |
|
|
url: "/api/user/self", |
|
|
url: "/api/user/self", |
|
|
@ -174,7 +186,7 @@ |
|
|
this.init(userInfo); |
|
|
this.init(userInfo); |
|
|
}) |
|
|
}) |
|
|
}, |
|
|
}, |
|
|
unmounted(){ |
|
|
unmounted() { |
|
|
this.$wsApi.closeWebSocket(); |
|
|
this.$wsApi.closeWebSocket(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -185,42 +197,45 @@ |
|
|
background: #333333; |
|
|
background: #333333; |
|
|
padding: 10px; |
|
|
padding: 10px; |
|
|
padding-top: 50px; |
|
|
padding-top: 50px; |
|
|
|
|
|
|
|
|
.user-head-image{ |
|
|
.user-head-image { |
|
|
position: relative; |
|
|
position: relative; |
|
|
width: 50px; |
|
|
width: 50px; |
|
|
height: 50px; |
|
|
height: 50px; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
.el-menu { |
|
|
.el-menu { |
|
|
border: none; |
|
|
border: none; |
|
|
flex: 1; |
|
|
flex: 1; |
|
|
|
|
|
|
|
|
.el-menu-item { |
|
|
.el-menu-item { |
|
|
margin-top: 20px; |
|
|
margin-top: 20px; |
|
|
.router-link-exact-active span{ |
|
|
|
|
|
|
|
|
.router-link-exact-active span { |
|
|
color: white !important; |
|
|
color: white !important; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
span { |
|
|
span { |
|
|
font-size: 24px !important; |
|
|
font-size: 24px !important; |
|
|
color: #aaaaaa; |
|
|
color: #aaaaaa; |
|
|
|
|
|
|
|
|
&:hover{ |
|
|
&:hover { |
|
|
color: white !important; |
|
|
color: white !important; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
.exit-box { |
|
|
.exit-box { |
|
|
position: absolute; |
|
|
position: absolute; |
|
|
width: 60px; |
|
|
width: 60px; |
|
|
bottom: 40px; |
|
|
bottom: 40px; |
|
|
color: #aaaaaa; |
|
|
color: #aaaaaa; |
|
|
font-size: 24px; |
|
|
font-size: 24px; |
|
|
text-align: center; |
|
|
text-align: center; |
|
|
cursor: pointer; |
|
|
cursor: pointer; |
|
|
&:hover{ |
|
|
|
|
|
|
|
|
&:hover { |
|
|
color: white !important; |
|
|
color: white !important; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -231,7 +246,6 @@ |
|
|
background-color: #E9EEF3; |
|
|
background-color: #E9EEF3; |
|
|
color: #333; |
|
|
color: #333; |
|
|
text-align: center; |
|
|
text-align: center; |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
</style> |
|
|
} |
|
|
|
|
|
</style> |
|
|
|