xyc
1 天以前 079d872fabfe488abf485d8898c40ff1fd746472
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
<template>
  <el-header class="app-header">
    <span class="header-title">{{ title }}</span>
    <div class="header-right">
      <span class="header-user">
        <i class="el-icon-user"></i> {{ username }}
      </span>
      <el-button type="text" class="header-logout" @click="logout">
        <i class="el-icon-switch-button"></i> 退出登录
      </el-button>
    </div>
  </el-header>
</template>
 
<script>
export default {
  name: 'AppHeader',
  props: {
    title: { type: String, required: true }
  },
  computed: {
    username() {
      return sessionStorage.getItem('username') || 'admin'
    }
  },
  methods: {
    logout() {
      this.$confirm('确定退出登录吗?', '提示', {
        confirmButtonText: '退出',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        sessionStorage.removeItem('token')
        sessionStorage.removeItem('username')
        sessionStorage.removeItem('realName')
        sessionStorage.removeItem('modules')
        this.$message.success('已退出登录')
        this.$router.push('/login')
      }).catch(() => {})
    }
  }
}
</script>
 
<style scoped>
.app-header {
  background: #409EFF;
  color: #fff;
  line-height: 60px;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  flex-shrink: 0;
}
.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  line-height: normal;
}
.header-user { opacity: 0.92; }
.header-logout { color: #fff; font-size: 14px; padding: 0; }
.header-logout:hover { color: #ffd04b; }
</style>