-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathheaderAccount.vue
191 lines (187 loc) · 4.98 KB
/
headerAccount.vue
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
<template>
<div id="headerAccount">
<div class="is-login pointer" v-if="loginState">
<v-menu transition="slide-y-transition" bottom offset-y right>
<template v-slot:activator="{ on, attrs }">
<v-avatar class="avatar" v-bind="attrs" v-on="on" :size="dense?30:40" :color="loginInfo.avatar?'':'primary'">
<v-img v-if="loginInfo.avatar" :src="qiNiuImgLink+loginInfo.avatar"></v-img>
<span class="white--text text-h7" :class="{'text-xs':dense}"
v-else>{{loginInfo.nickname|preNickname}}</span>
</v-avatar>
</template>
<v-list class="user-menu">
<v-list-item class="user-menu-list" link v-for="item in menuList" :key="item.value"
@click="handleMenu(item.value)">
<v-icon class="icon">{{item.icon}}</v-icon>
{{item.name}}
</v-list-item>
</v-list>
</v-menu>
</div>
<div class="not-login" v-else>
<router-link to="/login">
<v-btn class="login-btn" depressed color="primary" :small="dense" :class="dense?'radius-2':''">登录
</v-btn>
</router-link>
<router-link to="/signup">
<v-btn class="sign-up-btn" depressed color="info" :small="dense" :class="dense?'radius-2':''">注册
</v-btn>
</router-link>
</div>
</div>
</template>
<script>
import { mapState, mapMutations } from 'vuex'
import localStore from '@utils/localStorage'
import { qiNiuImgLink } from '@utils/publicData'
import cookie from '@utils/cookie'
export default {
props: {
dense: {
type: Boolean,
default: false,
},
},
inject: ['changeRouterKey'],
data() {
return {
qiNiuImgLink,
menuList: Object.freeze([
{
name: '我的',
value: 'user',
icon: 'mdi-account-outline',
},
{
name: '新建实例',
value: 'newWork',
icon: 'mdi-plus-circle-outline',
},
{
name: '设置',
value: 'settings',
icon: 'mdi-cog-outline',
},
{
name: '退出登录',
value: 'logout',
icon: 'mdi-logout-variant',
},
]),
}
},
computed: {
...mapState(['loginState', 'loginInfo']),
},
methods: {
...mapMutations(['setLoginInfo', 'setLoginState', 'resetInstanceState']),
handleMenu(val) {
switch (val) {
case 'user': {
this.$router
.push(`/user/${this.loginInfo.username}`)
.catch((err) => {})
break
}
case 'newWork': {
/**
* 在新建实例或实例详情页面点击新建实例
* 需要触发App的changeRouterKey方法改变key强制刷新路由
* 并且需要清除iframe的绑定和实例部分配置
*/
switch (this.$route.name) {
case 'NewWork': {
this.$router.push({ name: 'NewWork' }).catch((err) => {
this.changeRouterKey()
})
break
}
case 'Work': {
this.$router.push({ name: 'NewWork' }).then(() => {
this.changeRouterKey()
})
break
}
default: {
this.$router.push({ name: 'NewWork' }).catch((err) => {})
}
}
break
}
case 'settings': {
this.$router.push({ name: 'Settings' }).catch((err) => {})
break
}
case 'logout': {
this.$alert({
content: '登出之后,下次来只能手动登录哦!',
okColor: 'error',
okText: '登出',
}).then((isLogout) => {
if (!isLogout) return void 0
// 删除登录身份凭证
cookie.del('AUTH_TOKEN')
// 取消自动登录
localStore.set('REMEMBER_ME', false)
// 临时的第三方登录TMP_REMEMBER_ME
sessionStorage.removeItem('TMP_REMEMBER_ME')
this.setLoginState(false)
this.setLoginInfo({
username: '',
nickname: '',
avatar: '',
})
this.$http.logout().then((res) => {
this.$router.replace({ name: 'Home' }).catch((err) => {})
})
})
}
}
},
},
}
</script>
<style lang="scss">
.user-menu {
.user-menu-list {
color: $light-5 !important;
@include setTransition(color, 0.3s, ease);
&:hover {
color: $light-1 !important;
}
.icon {
color: inherit;
margin-right: 15px;
}
}
}
</style>
<style lang="scss" scoped>
#headerAccount {
.is-login {
.avatar {
&:hover {
border: 2px solid $primary-1;
}
}
}
.not-login {
.login-btn {
margin-right: 15px;
}
}
}
@include screenXS {
#headerAccount {
.not-login {
.login-btn {
margin-right: 5px;
}
.login-btn,
.sign-up-btn {
height: 35px;
}
}
}
}
</style>