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

88 lines
2.2 KiB
Vue
Raw Normal View History

2018-03-08 11:53:14 +01:00
<template>
<div id="global_header">
<el-menu
:default-active="defaultActive"
class="el-menu-vertical account-menu"
2018-03-21 04:22:45 +01:00
:collapse="true"
2018-03-09 08:14:47 +01:00
:route="true"
background-color="#4a5664"
2018-03-08 11:53:14 +01:00
text-color="#909399"
active-text-color="#ffffff">
<el-menu-item :index="index.toString()" v-for="(account, index) in accounts" v-bind:key="account._id" :route="{path: `/${account._id}/home`}" @click="select(account)">
2018-03-08 11:53:14 +01:00
<i class="el-icon-menu"></i>
<span slot="title">{{ account.domain }}</span>
2018-03-08 11:53:14 +01:00
</el-menu-item>
<el-menu-item index="/login" @click="login">
<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="space">
<router-view :key="$route.params.id"></router-view>
2018-03-08 11:53:14 +01:00
</div>
</div>
</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({
2018-03-21 04:22:45 +01:00
defaultActive: state => state.GlobalHeader.defaultActive,
accounts: state => state.GlobalHeader.accounts
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: {
2018-03-21 04:22:45 +01:00
async initialize () {
await this.$store.dispatch('GlobalHeader/removeShortcutEvents')
this.$store.dispatch('GlobalHeader/watchShortcutEvents')
try {
const accounts = await this.$store.dispatch('GlobalHeader/listAccounts')
if (this.$route.params.id === undefined) {
this.$store.dispatch('GlobalHeader/schmearMenu', accounts[0]._id)
return this.$router.push({ path: `/${accounts[0]._id}/home` })
} else {
return this.$store.dispatch('GlobalHeader/schmearMenu', this.$route.params.id)
}
2018-03-21 04:22:45 +01:00
} catch (err) {
return this.$router.push({ path: '/login' })
}
},
login () {
return this.$router.push({ path: '/login' })
},
select (account) {
console.log(account._id)
return this.$router.push({ path: `/${account._id}/home` })
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;
.el-tooltip {
outline: 0;
}
2018-03-08 11:53:14 +01:00
}
.space {
2018-03-08 11:53:14 +01:00
margin-left: 65px;
2018-03-29 15:41:28 +02:00
height: 100%;
2018-03-08 11:53:14 +01:00
}
}
</style>