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.
 
 
 
 

181 lines
5.0 KiB

<template>
<div class="header-wrap ">
<div class="header-logo" @click="toHome">
<img src="../assets/header-logo.png" alt="">
</div>
<div class="header-right flex" v-if="headerShow">
<div
:class="['right-item', currentPath == item.path ? 'right-item-active' :'']"
v-for="(item,index) in routerNavList"
:key="index"
@click="goToPage(item.path)"
>
{{ item.name }}
</div>
<el-dropdown trigger="click">
<div class="right-item flex el-dropdown-link">
<img class="right-item-icon" src="../assets/header-icon.png" alt="">
<span>{{user}}</span>
<div class="img"></div>
</div>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item><div @click="loginOut">退出</div></el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</div>
</div>
</template>
<script>
export default {
data(){
return{
user: '',
headerShow:false,
doctor_id:'',
authtoken:false,
currentPath:'',
routerNavList:[
// {
// name:'个人信息',
// path:'/doctorInformation'
// },
// {
// name:'医院管理',
// path:'/hospitalManage'
// },
// {
// name:'收款管理',
// path:'/paymentMethod'
// },
]
}
},
mounted(){
this.user = localStorage.getItem('user_name')
var user_type = localStorage.getItem('user_type')
if(!user_type || user_type == 'undefined') {
this.user = '超级管理员'
}else{
if(user_type && user_type != 'undefined') this.user = (user_type == 1?'医生':'助手') + this.user
}
this.doctor_id = localStorage.getItem('doctor_id')
this.authtoken = localStorage.getItem('authtoken')
if(this.authtoken){
this.headerShow = true
// 初始化时设置当前路由高亮
this.updateCurrentPath()
// 监听路由变化
this.watchRouteChange()
}else{
this.headerShow = false
}
},
methods: {
toHome() {
this.$router.push({
path: '/'
})
},
goToPage(path) {
this.currentPath = path;
this.$router.push({
path: path + '?doctor_id=' + this.doctor_id
})
},
loginOut(){
localStorage.removeItem('token');
localStorage.removeItem('user_name');
localStorage.removeItem('authtoken');
localStorage.removeItem('user_type');
localStorage.removeItem('doctor_id');
this.$router.push('/login');
},
// 更新当前路径高亮状态
updateCurrentPath() {
const currentRoute = this.$route.path;
const matchedItem = this.routerNavList.find(item =>
currentRoute.startsWith(item.path)
);
if (matchedItem) {
this.currentPath = matchedItem.path;
} else {
this.currentPath = '';
}
},
// 监听路由变化
watchRouteChange() {
this.$watch('$route', (to, from) => {
console.log(to,from,'====');
this.updateCurrentPath();
});
}
},
beforeDestroy() {
}
}
</script>
<style lang="scss" scoped>
.flex {
display: flex;
}
.header-wrap {
color: #1E2226;
display: flex;
justify-content: space-between;
width: calc(100% - 64px);
height: 100%;
align-items: center;
position: absolute;
z-index: 9;
.header-logo {
cursor: pointer;
img {
height: 46px;
}
}
.header-right {
justify-content: flex-end;
gap:20px;
.el-dropdown-link {
cursor: pointer;
}
.right-item{
padding: 10px;
transition: all .3s;
cursor: pointer;
&:hover{
border-radius: 6px;
background: rgba(255, 255, 255, 0.4);
color: #006AFF;
transition: all .3s;
}
}
.right-item-active{
border-radius: 6px;
background: rgba(255, 255, 255, 0.4);
color: #006AFF;
transition: all .3s;
}
.el-dropdown .right-item{
padding: 0 10px;
cursor: pointer;
}
.right-item-icon {
width: 36px;
height: 36px;
}
.right-item-icon+span {
display: inline-block;
margin: 0 6px 0 12px;
}
}
}
</style>