|
1 | 1 |
|
2 | 2 | <script> |
3 | | - import { mapActions, mapGetters } from 'vuex' |
4 | | - import { version } from '../../config' |
| 3 | + import { mapActions, mapState } from 'vuex' |
5 | 4 | import CcSpinner from '../general/spinner' |
| 5 | + import { version } from '../../config' |
6 | 6 |
|
7 | 7 | export default { |
8 | 8 | components: { |
9 | 9 | CcSpinner, |
10 | 10 | }, |
11 | 11 | computed: { |
12 | | - ...mapGetters(['currentUser', 'isLogged']), |
| 12 | + ...mapState({ |
| 13 | + user: state => state.Auth.user, |
| 14 | + }), |
13 | 15 | version() { |
14 | 16 | return version |
15 | 17 | }, |
16 | 18 | }, |
17 | | - watch: { |
18 | | - isLogged(value) { |
19 | | - if (value === false) { |
20 | | - this.$router.push({ name: 'auth.singin' }) |
| 19 | + methods: { |
| 20 | + ...mapActions(['setToken', 'setUser']), |
| 21 | + logout() { |
| 22 | + this.setToken('') |
| 23 | + this.setUser({}) |
| 24 | + this.$router.push({ name: 'login.index' }) |
| 25 | + }, |
| 26 | + /* eslint-disable no-undef */ |
| 27 | + navigate(name) { |
| 28 | + switch (name) { |
| 29 | + case 'codecasts': |
| 30 | + window.location = 'https://codecasts.com.br/' |
| 31 | + break; |
| 32 | + case 'logout': |
| 33 | + this.logout() |
| 34 | + break; |
| 35 | + default: |
| 36 | + this.$router.push({ name }) |
| 37 | + break; |
21 | 38 | } |
22 | 39 | }, |
23 | 40 | }, |
24 | | - methods: { |
25 | | - ...mapActions(['logout']), |
26 | | - }, |
27 | 41 | } |
28 | 42 | </script> |
29 | 43 |
|
30 | 44 | <template> |
31 | 45 | <div> |
32 | | - <nav class="navbar navbar-default"> |
33 | | - <div class="container-fluid"> |
34 | | - <div class="navbar-header spacer"> |
35 | | - <a class="navbar-brand" href="http://www.codecasts.com.br/"> |
36 | | - Codecasts.com.br |
37 | | - </a><br> |
38 | | - <small class="version">version {{ version }}</small> |
39 | | - </div> |
40 | | - <div class="collapse navbar-collapse"> |
41 | | - <ul class="nav navbar-nav"> |
42 | | - <router-link tag="li" :to="{ name: 'dashboard.index' }" exact> |
43 | | - <a>Dashboard</a> |
44 | | - </router-link> |
45 | | - <router-link tag="li" :to="{ name: 'categories.index', query: { page: 1 } }"> |
46 | | - <a>Categories</a> |
47 | | - </router-link> |
48 | | - <router-link tag="li" :to="{ name: 'products.index', query: { page: 1 } }"> |
49 | | - <a>Products</a> |
50 | | - </router-link> |
51 | | - </ul> |
52 | | - <div class="nav navbar-form navbar-right"> |
53 | | - <cc-spinner></cc-spinner> |
54 | | - <span class="username">{{ currentUser.name }}</span> |
55 | | - <button class="btn btn-default btn-sm" @click="logout">Logout</button> |
56 | | - </div> |
57 | | - </div> |
58 | | - </div> |
59 | | - </nav> |
| 46 | + <el-menu theme="dark" default-active="1" class="cc-navigation" |
| 47 | + mode="horizontal" @select="navigate"> |
| 48 | + <el-menu-item index="codecasts" class="brand">Codecasts.com.br</el-menu-item> |
| 49 | + <el-menu-item index="dashboard.index">Dashboard</el-menu-item> |
| 50 | + <el-submenu index="menu-modules"> |
| 51 | + <template slot="title">Modules</template> |
| 52 | + <el-menu-item index="categories.index">Categories</el-menu-item> |
| 53 | + <el-menu-item index="products.index">Products</el-menu-item> |
| 54 | + </el-submenu> |
| 55 | + <el-submenu index="menu-user" class="logout-button"> |
| 56 | + <template slot="title">{{ user.name }}</template> |
| 57 | + <el-menu-item index="logout">Logout</el-menu-item> |
| 58 | + </el-submenu> |
| 59 | + </el-menu> |
| 60 | + <small class="version">version {{ version }}</small> |
60 | 61 | </div> |
61 | 62 | </template> |
62 | 63 |
|
63 | 64 | <style scoped> |
64 | | - .spacer { |
65 | | - margin-left: 120px; |
| 65 | + .cc-navigation { |
| 66 | + padding-left: 115px; |
| 67 | + } |
| 68 | + .brand { |
| 69 | + font-size: 1.2em; |
66 | 70 | } |
67 | | - .username { |
68 | | - padding: 6px 20px; |
69 | | - border-radius: 20px; |
70 | | - background-color: #ddd; |
71 | | - display: inline-block; |
| 71 | + .logout-button { |
| 72 | + float: right; |
72 | 73 | } |
73 | 74 | .version { |
74 | 75 | position: absolute; |
75 | 76 | right: 15px; |
76 | | - top: 58px; |
| 77 | + top: 65px; |
77 | 78 | } |
78 | 79 | </style> |
0 commit comments