header.vue
5.89 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<style lang="scss" scoped>
.qg-header {
width: 100%;
height: $headerHeight;
/*
background-color: darken($primary, 5);
*/
background-color: $primary;
display: flex;
flex-direction: row;
align-items: center;
position: fixed;
z-index: 1000;
}
.qg-header-nav {
white-space: nowrap;
overflow: hidden;
flex: 1;
height: 100%;
display: flex;
align-items: center;
> a {
display: flex;
align-items: center;
font-size: 16px;
color: rgba(255, 255, 255, 0.7);
position: relative;
padding: 0 20px;
height: 100%;
&:hover {
color: rgba(255, 255, 255, 1);
font-weight: bold;
}
&.active {
color: rgba(255, 255, 255, 1);
font-weight: bold;
background-color: rgba(255, 255, 255, 0.2);
/*&:after{*/
/* content: '';*/
/* position: absolute;*/
/*}*/
}
}
}
</style>
<style lang="scss">
#app .theme-navtl {
.sidebar-container {
top: $headerHeight;
border-right: 1px solid #efefef;
height: auto;
background-color: #fff;
flex: 1;
.el-menu {
background-color: #fff;
}
}
.sidebar-logo-container {
width: auto;
background-color: transparent;
border: none;
padding: 0 32px;
color: #fff;
}
}
.theme-navtl {
.qg-header .el-dropdown {
color: #fff;
}
.right-menu-icon {
color: rgba(255, 255, 255, .8);
&:hover {
color: #fff;
}
}
}
</style>
<template>
<header class="qg-header">
<logo style="width: auto;padding: 0 32px;"/>
<nav class="qg-header-nav">
<template v-for="item in menus">
<app-link
v-if="item.routeUrl || item.redirect"
:key="item.name"
:class="{'active':activeMenu && activeMenu.id === item.id}"
:to="item.routeUrl|| item.redirect || '/404'"
:target="item.openWay?'':''"
@click.native="setSubMenus(item)"
>
<span>{{ item.name }}</span>
</app-link>
<a
v-else
:key="item.name"
:class="{'active':activeMenu && activeMenu.id === item.id}"
href=""
@click="setSubMenus(item)"
>{{ item.name }}</a>
</template>
</nav>
<right-menu/>
</header>
</template>
<script>
import {mapGetters} from 'vuex';
import {changePassword} from '@/api/moudles/uc/user';
import AppLink from '@/layout/components/Sidebar/Link';
import Logo from '@/layout/components/Logo';
import {RightMenu} from '../../../components';
import {getFirstNav} from '@/utils';
export default {
name: 'ThemeHeader',
components: {Logo, AppLink, RightMenu},
data() {
return {
visible: false,
activeMenu: {}
};
},
computed: {
...mapGetters(['menus', 'subMenus', 'crumbList'])
},
watch: {
crumbList(val) {
console.log('crumbList', val);
},
activeMenu(val) {
this.$store.dispatch('permission/setSubMenus', (val && val.childList) || []);
}
},
created() {
console.log('this.menus', this.menus);
this.menus.forEach(item => {
if (item.childList && item.childList.length > 0) {
item.redirect = getFirstNav(item.childList);
}
});
this.activeMenu = (this.crumbList && this.crumbList[0]) || {};
// TODO iframe 嵌入的页面 刷新后,nav没定位,如果iframe嵌入的是内部也需要测试
},
methods: {
toggleSideBar() {
this.$store.dispatch('app/toggleSideBar');
},
async logout() {
await this.$store.dispatch('user/logout');
this.$router.push(`/login?redirect=${this.$route.fullPath}`);
},
changePassword() {
this.visible = true;
this.editForm.oldPassword = '';
this.editForm.newPassword = '';
this.editForm.againPassword = '';
},
handleOk() {
const that = this;
that.$refs.editForm.validate((valid) => {
if (!valid) {
return;
}
that.editForm.oldPassword = btoa(that.editForm.oldPassword);
that.editForm.newPassword = btoa(that.editForm.newPassword);
that.editForm.againPassword = btoa(that.editForm.againPassword);
changePassword(that.editForm).then((res) => {
if (res.success) {
that.$message.success(res.msg || '修改成功');
setTimeout(() => {
that.logout();
}, 500);
} else {
that.$message.error(res.msg || '修改失败');
}
});
});
},
handleClose() {
this.visible = false;
},
setSubMenus(item) {
this.activeMenu = item;
}
}
};
</script>