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.

163 lines
3.8 KiB

4 years ago
<template>
<div class="header flex-between">
<div class="logo">
<img class="cursor"
@click="goHome"
src="../assets/img/logo.png">
</div>
<div class="header-right">
<div class="header-user-con">
<div class="user"
@click="toPerson">
<el-avatar :size="40"
:src="$store.state.avatar"></el-avatar>
<span class="user-avator">{{userName}}</span>
4 years ago
</div>
<el-divider class="ml20"
direction="vertical"></el-divider>
<el-button type="text"
class="ml20"
@click="loginout">退出</el-button>
</div>
4 years ago
</div>
</div>
4 years ago
</template>
<script>
import Bus from '@/libs/bus'
4 years ago
export default {
data () {
return {
userName: ''
};
},
mounted () {
this.getUserInfo()
},
methods: {
toPerson () {
if (this.$route.path.split('/').pop() !== 'person') {
this.$router.push('/person')
}
},
loginout () {
localStorage.removeItem('ms_username');
localStorage.removeItem('token');
sessionStorage.clear()
location.reload()
},
goHome () {
this.$router.push('/customer')
},
// socket连接成功
open () {
console.log("socket连接成功");
},
// socket连接失败
error () {
console.log("连接错误");
},
// 接收消息
getMessage (msg) {
console.log("==websocket接收数据==");
console.log(JSON.parse(msg.data));
const { content } = JSON.parse(msg.data)
// 1赛事、2创业、3考核、4模型。-号拼接携带id
content == 1 && Bus.$emit('matchSocket')
content == 4 && Bus.$emit('modelSocket')
},
// 关闭socket
close () {
console.log("socket已经关闭");
4 years ago
},
initSocket ({ id, account }) {
// 实例化socket
2 years ago
this.socket = new WebSocket(`wss://${Setting.isDev ? '192.168.31.51' : location.host}/nakadai/websocket/${id}/${account}`)
// this.socket = new WebSocket(`ws://121.37.12.51:9100/nakadai/websocket/${id}/${account}`)
// 监听socket连接
this.socket.onopen = this.open;
// 监听socket错误信息
this.socket.onerror = this.error;
// 监听socket消息
this.socket.onmessage = this.getMessage;
4 years ago
},
getUserInfo () {
this.$get(this.api.queryUserInfoDetails).then(({ result }) => {
let userInfo = result.hrUserInfo
if (userInfo.userAvatars) this.$store.commit('userAvatar', { avatar: userInfo.userAvatars })
this.userName = userInfo.userName
const { id } = result.userAccount
id && this.$store.commit('SET_ACCOUNTID', id)
this.$store.commit('SET_USERNAME', this.userName)
2 years ago
this.initSocket(result.userAccount)
}).catch(err => { })
4 years ago
},
},
4 years ago
};
</script>
3 years ago
<style lang="scss" scoped>
4 years ago
.header {
position: relative;
box-sizing: border-box;
width: 100%;
height: 60px;
font-size: 16px;
color: #333;
}
.header .logo {
float: left;
width: 170px;
height: 40px;
margin-left: 20px;
}
.header .logo img {
4 years ago
width: 100%;
height: 100%;
}
.header-right {
float: right;
padding-right: 50px;
}
.header-user-con {
display: flex;
height: 70px;
align-items: center;
}
.header-user-con .user {
4 years ago
display: inline-flex;
align-items: center;
cursor: pointer;
}
4 years ago
.user-avator {
cursor: pointer;
margin-left: 10px;
3 years ago
font-size: 12px;
4 years ago
}
.ml20 {
4 years ago
margin-left: 20px;
}
.user-avator img {
display: block;
width: 40px;
height: 40px;
border-radius: 50%;
}
/deep/.header-right .el-button--text {
4 years ago
color: #333;
3 years ago
span {
font-size: 12px;
}
4 years ago
}
.header-right .el-divider--vertical {
4 years ago
width: 2px;
height: 15px;
}
.header-right .el-divider {
4 years ago
background-color: #333;
}
</style>