Whalebird-desktop-client-ma.../src/renderer/components/GlobalHeader.vue

112 lines
2.7 KiB
Vue
Raw Normal View History

2018-03-08 11:53:14 +01:00
<template>
<div id="global_header">
<el-menu
v-if="!hide"
:default-active="activeRoute()"
class="el-menu-vertical account-menu"
2018-03-21 04:22:45 +01:00
:collapse="true"
:router="true"
:background-color="themeColor"
2018-03-08 11:53:14 +01:00
text-color="#909399"
2018-10-21 04:17:59 +02:00
active-text-color="#ffffff"
role="menubar">
<el-menu-item :index="`/${account._id}/home`" v-for="(account, index) in accounts" v-bind:key="account._id" role="menuitem">
<i v-if="account.avatar === undefined || account.avatar === null || account.avatar === ''" class="el-icon-menu"></i>
<img v-else :src="account.avatar" class="avatar" :title="account.username + '@' + account.domain" />
<span slot="title">{{ account.domain }}</span>
2018-03-08 11:53:14 +01:00
</el-menu-item>
2018-10-21 04:17:59 +02:00
<el-menu-item index="/login" :title="$t('global_header.add_new_account')" role="menuitem">
<i class="el-icon-plus"></i>
<span slot="new">New</span>
</el-menu-item>
2018-03-08 11:53:14 +01:00
</el-menu>
<div :class="hide ? 'space no-global-header':'space with-global-header' ">
<router-view :key="$route.params.id"></router-view>
2018-03-08 11:53:14 +01:00
</div>
</div>
</div>
2018-03-08 11:53:14 +01:00
</template>
<script>
2018-03-08 15:08:33 +01:00
import { mapState } from 'vuex'
2018-03-08 11:53:14 +01:00
export default {
name: 'global-header',
2018-03-08 15:08:33 +01:00
computed: {
...mapState('GlobalHeader', {
accounts: state => state.accounts,
hide: state => state.hide
}),
2018-03-08 15:08:33 +01:00
...mapState({
themeColor: state => state.App.theme.global_header_color
2018-03-08 15:08:33 +01:00
})
},
2018-03-08 11:53:14 +01:00
created () {
2018-03-21 04:22:45 +01:00
this.initialize()
2018-03-08 11:53:14 +01:00
},
methods: {
activeRoute () {
return this.$route.path
},
2018-03-21 04:22:45 +01:00
async initialize () {
await this.$store.dispatch('GlobalHeader/removeShortcutEvents')
this.$store.dispatch('GlobalHeader/loadHide')
2018-03-21 04:22:45 +01:00
this.$store.dispatch('GlobalHeader/watchShortcutEvents')
try {
const accounts = await this.$store.dispatch('GlobalHeader/listAccounts')
if (this.$route.params.id === undefined) {
return this.$router.push({ path: `/${accounts[0]._id}/home` })
}
2018-03-21 04:22:45 +01:00
} catch (err) {
return this.$router.push({ path: '/login' })
}
2018-03-08 11:53:14 +01:00
}
}
}
</script>
<style lang="scss" scoped>
#global_header /deep/ {
.account-menu {
2018-03-08 11:53:14 +01:00
height: 100%;
position: fixed;
top: 0;
left: 0;
width: 65px;
padding-top: 24px;
2018-10-26 17:23:12 +02:00
border: 0;
.el-tooltip {
outline: 0;
text-align: center;
padding: 0 !important;
}
.avatar {
width: 42px;
height: 42px;
border-radius: 50%;
mix-blend-mode: overlay;
}
.is-active {
.avatar {
mix-blend-mode: normal;
}
}
2018-03-08 11:53:14 +01:00
}
.space {
2018-03-29 15:41:28 +02:00
height: 100%;
2018-03-08 11:53:14 +01:00
}
.no-global-header {
margin-left: 0;
}
.with-global-header {
margin-left: 65px;
}
2018-03-08 11:53:14 +01:00
}
</style>