gaoluyang
5 天以前 c7566bba45e6f90594d36ec4b80ac4ff89f577ee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<template>
  <div class="navbar">
    <hamburger id="hamburger-container" :is-active="appStore.sidebar.opened" class="hamburger-container" @toggleClick="toggleSideBar" />
    <div class="center-menu">
      <span class="label">LIMS实验室管理系统</span>
    </div>
    <div class="right-menu">
      <div class="avatar-wrapper">
        <el-avatar shape="square" :size="30">{{ avatarText }}</el-avatar>
        <span class="userName">{{ userStore.nickName }}</span>
        <el-dropdown class="avatar-container right-menu-item hover-effect" trigger="click">
          <div class="avatar-wrapper">
            <lims-icon name="el-icon-caret-bottom" />
          </div>
          <template #dropdown>
            <el-dropdown-menu>
              <router-link to="/user/profile">
                <el-dropdown-item>个人中心</el-dropdown-item>
              </router-link>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
        <img class="logoout" src="@/assets/images/logoout.png" @click="logout" title="退出账号" />
      </div>
    </div>
  </div>
</template>
 
<script setup>
import { ElMessageBox } from 'element-plus'
import Hamburger from '@/components/Hamburger'
import useAppStore from '@/store/modules/app'
import useUserStore from '@/store/modules/user'
 
const appStore = useAppStore()
const userStore = useUserStore()
 
const avatarText = computed(() => (userStore.nickName || '').substring(0, 1))
 
function toggleSideBar() {
  appStore.toggleSideBar()
}
 
function logout() {
  ElMessageBox.confirm('确定注销并退出系统吗?', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(() => {
    userStore.logOut().then(() => {
      location.href = '/index'
    })
  }).catch(() => { })
}
</script>
 
<style lang="scss" scoped>
.navbar {
  height: 50px;
  overflow: hidden;
  background: var(--lims-surface);
  border-bottom: 1px solid var(--lims-divider);
  box-shadow: none;
  position: fixed; /* 将头部固定 */
  top: 0; /* 在顶部固定 */
  width: 100%; /* 宽度100%,覆盖整个视口 */
  z-index: 1000; /* 确保头部在其他内容之上 */
  display: flex;
  align-items: center;
  justify-content: space-between;
 
  .hamburger-container {
    line-height: 46px;
    height: 100%;
    cursor: pointer;
    transition: background 0.2s;
    -webkit-tap-highlight-color: transparent;
    display: flex;
    align-items: center;
    flex-shrink: 0;
    margin-left: 8px;
    border-radius: var(--lims-radius-sm);
 
    &:hover {
      background: var(--lims-surface-hover);
    }
  }
 
  .center-menu {
    height: 100%;
    line-height: 50px;
    margin-right: auto;
    margin-left: 8px;
    display: flex;
    align-items: center;
 
    /* 标题左侧的主色细条,呼应弹窗标题的视觉语言 */
    &::before {
      content: '';
      display: inline-block;
      width: 3px;
      height: 15px;
      border-radius: 2px;
      background: var(--el-color-primary);
      margin-right: 10px;
    }
 
    .label {
      font-size: 15px;
      font-weight: 600;
      color: var(--lims-text);
      letter-spacing: 0.2px;
    }
  }
 
  .right-menu {
    height: 100%;
    line-height: 50px;
    display: flex;
    align-items: center;
 
    &:focus {
      outline: none;
    }
 
    .avatar-wrapper {
      display: flex;
      align-items: center;
 
      :deep(.el-avatar) {
        background: var(--el-color-primary);
        border-radius: var(--lims-radius-sm);
        font-size: 14px;
        font-weight: 600;
      }
 
      .userName {
        font-size: 14px;
        color: var(--lims-text-2);
        margin-left: 10px;
      }
      .logoout {
        margin: 0 40px;
        cursor: pointer;
        width: 14px;
        opacity: 0.6;
        transition: opacity 0.2s;
 
        &:hover {
          opacity: 1;
        }
      }
    }
 
    .right-menu-item {
      display: inline-block;
      padding: 0 8px;
      height: 100%;
      font-size: 18px;
      color: var(--lims-text-2);
      vertical-align: text-bottom;
 
      &.hover-effect {
        cursor: pointer;
        transition: background 0.2s;
 
        &:hover {
          background: var(--lims-surface-hover);
        }
      }
    }
 
    .avatar-container {
      display: flex;
      align-items: center;
    }
  }
}
</style>