Navbar.vue
3.8 KB
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
<template>
<el-menu class="navbar-header-fixed" mode="horizontal">
<div class="top-right">
<div class="hb-bd">
<hamburger
class="hamburger-container"
:toggleClick="toggleSideBar"
:isActive="sidebar.opened"
></hamburger>
<breadcrumb></breadcrumb>
</div>
<div class="top-select">
<div class="go-index">{{time}}</div>
<div class="select-right">
<el-dropdown trigger="click">
<div>
<el-image :src="userImage" class="avatar">
<div slot="error" class="image-slot">
<i class="el-icon-picture-outline"></i>
</div>
</el-image>
<div class="el-dropdown-link">
尊敬的: {{name}}
<i class="el-icon-arrow-down el-icon--right"></i>
</div>
</div>
<el-dropdown-menu slot="dropdown">
<router-link to="/">
<el-dropdown-item>返回首页</el-dropdown-item>
</router-link>
<el-dropdown-item @click.native="logout">
<span>切换账号</span>
</el-dropdown-item>
<el-dropdown-item @click.native="logout">
<span>退出登录</span>
</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</div>
</div>
</div>
</el-menu>
</template>
<script>
import { format } from "date-fns";
import { mapGetters } from "vuex";
import Breadcrumb from "@/components/Breadcrumb";
import Hamburger from "@/components/Hamburger";
export default {
components: {
Breadcrumb,
Hamburger
},
data: () => ({
time: "",
userImage: require("@/assets/user.png")
}),
mounted() {
this.set_time();
this.timer = setInterval(() => {
this.set_time();
}, 60000);
console.log(this.userImage)
},
methods: {
toggleSideBar() {
this.$store.dispatch("ToggleSideBar");
},
logout() {
this.$store.dispatch("LogOut").then(() => {
this.$message({
message: "退出成功",
type: "success"
});
this.$router.push('/login')
});
},
set_time() {
this.time = format(new Date(), "yyyy/MM/dd HH:mm");
}
},
computed: {
...mapGetters(["name", "role", "sidebar"])
},
beforeDestroy() {
console.log("销毁计时器------------");
clearInterval(this.timer);
this.timer = null;
}
};
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.navbar-header-fixed {
transition: width 0.28s;
width: calc(100% - 256px);
display: flex;
align-items: center;
position: fixed;
right: 0;
z-index: 1002;
height: 62px;
.hamburger-container {
line-height: 58px;
height: 50px;
float: left;
padding: 0 10px;
}
.logo {
width: 199px;
height: 62px;
}
.top-right {
display: flex;
width: 100%;
height: 100%;
background-color: #ffffff;
justify-content: space-between;
padding: 0 19px;
.hb-bd {
display: flex;
justify-content: center;
align-items: center;
}
.avatar {
width: 30px;
height: 30px;
margin-right: 10px;
/deep/ img {
width: 100%;
height: 100%;
border-radius: 50%;
}
}
.top-select {
display: flex;
align-items: center;
.go-index {
color: #333333;
font-weight: 400;
margin-right: 20px;
padding-right: 20px;
border-right: 1px solid #cccccc;
}
.select-right /deep/ .el-dropdown > span {
font-size: 6px;
}
.select-right {
.el-dropdown-link {
color: #333333;
font-weight: 400;
}
/deep/ .el-dropdown-selfdefine {
display: flex;
align-items: center;
}
}
}
}
}
</style>