AppHeader.vue 7.57 KB
Newer Older
Esteban Choque's avatar
Esteban Choque committed
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
<template>
  <div class="app-header">
    <nav
      class="app-menu"
      :class="{ stick: stick }">
      <div class="app-menu__container">
        <el-row
          type="flex"
          class="row-bg relative"
          justify="space-between">
          <div class="app-logo-container">
            <app-logo></app-logo>
          </div>
          <div class="app-b-servicio">
            <b-servicio></b-servicio>
          </div>
          <div class="app-header-lang-2">
            <app-lang></app-lang>
          </div>
          <transition name="el-fade-in">
            <div
              class="app-menu__main"
              :class="{ 'open-menu': $store.state.open }">
              <div class="app-logo-container-2">
                <app-logo></app-logo>
              </div>
              <span
                class="app-search__close"
                @click="$store.commit('CLOSE_MENU')">
                <i class="el-icon-close"></i>
              </span>
              <ul class="app-menu__list">
                <li
                  v-for="item in menu"
                  :key="item.path"
                  :class="{ active: '/' + item.path === $route.fullPath }"
                  class="app-menu__item">
                  <nuxt-link :to="$i18n.path(item.path)">
                    {{ $t(`menu.${item.path}`) }}
                  </nuxt-link>
                  <el-button
                    type="text"
                    v-if="item.submenu"
                    class="app-menu__btn-open app-btn__link"
                    icon="el-icon-arrow-down"
                    @click="item.open = !item.open">
                  </el-button>
                  <ul
                    v-if="item.submenu"
                    class="app-menu__sublist fadeInUp"
                    :class="{ 'open-menu': item.open }">
                    <li
                      v-for="subitem in item.submenu"
                      :key="subitem.path"
                      class="app-menu__subitem">
                      <nuxt-link :to="$i18n.path(subitem.path)">
                        {{ $t(`menu.${subitem.path}`) }}
                      </nuxt-link>
                    </li>
                  </ul>
                </li>
                <div class="divider"></div>
                <li
                  class="app-menu__item">
                  <a href="/participa">Participa</a>
                  <el-button
                    type="text"
                    class="app-menu__btn-open app-btn__link"
                    icon="el-icon-arrow-down"
70
                    @click="pestaña_participa = !pestaña_participa">
Esteban Choque's avatar
Esteban Choque committed
71
72
                  </el-button>
                  <ul
73
74
75
                    class="app-menu__sublist fadeInUp foros"
                    :class="{ 'open-menu': pestaña_participa }">

Esteban Choque's avatar
Esteban Choque committed
76
                    <li
77
78
79
80
81
82
83
84
85
                      v-for="forum in forums"
                      :key="forum.id_forum"
                      class="app-menu__subitem">
                      <nuxt-link :to="$i18n.path('participa/'+forum.id_forum+'/'+forum.slug)">
                        {{ forum.name }}
                      </nuxt-link>
                    </li>

                    <!--<li
Esteban Choque's avatar
Esteban Choque committed
86
87
88
89
90
91
                      class="app-menu__subitem">
                      <a href="/participa/1/agenda-digital">Agenda Digital</a>
                    </li>
                    <li
                      class="app-menu__subitem">
                      <a href="/participa/2/inclusion-digital">Inclusión Digital</a>
92
93
                    </li>-->

Esteban Choque's avatar
Esteban Choque committed
94
95
96
97
98
                  </ul>
                </li>
              </ul>

              <!-- lang options -->
99
100
              <!--<div class="divider app-lang-divider"></div>
              <app-lang></app-lang>-->
Esteban Choque's avatar
Esteban Choque committed
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

              <!-- login/logout user -->
              <!--<div class="divider"></div>
              <div class="app-header__options">
                <el-dropdown
                  v-if="$store.state.authUser">
                  <el-button
                    class="app-btn__link"
                    type="text">
                    {{ $store.state.authUser.username || $store.state.authUser.usuario }} <i class="el-icon-setting el-icon--right"></i>
                  </el-button>
                  <el-dropdown-menu
                    class="app-header__submenu"
                    slot="dropdown">
                    <el-dropdown-item class="app-header__user__item">
                      <a
                        href="#"
                        @click.prevent="logout">{{ $t('header.logout') }}</a>
                    </el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
                <el-button
                  type="text"
                  class="app-btn__link"
                  @click="login"
                  v-else
                >{{ $t('header.login') }}</el-button>
              </div>-->

              <!-- button search -->
              <!--<div class="divider"></div>
              <div class="app-header__search">
                <el-button
                  type="text"
                  icon="el-icon-search"
                  class="app-btn__link"
                  @click="openSearch">
                  <span class="app-header__search-text">Buscar</span>
                </el-button>

              </div>-->
            </div>
          </transition>
          <el-button
            type="text"
            class="app-menu__btn-open-menu app-btn__link"
            @click="$store.commit('OPEN_MENU')">
            Menú
          </el-button>
        </el-row>
      </div>
    </nav>
  </div>
</template>

<script>
import AppLang from './AppLang';
import AppLogo from './AppLogo';
import BServicio from '~/components/bservicio/BServicio';
160
import axios from 'axios';
Esteban Choque's avatar
Esteban Choque committed
161
162
163
164
165
166
167
168
169
170
171
172
173
174

const Cookie = process.client ? require('js-cookie') : undefined;
let nuxtContainer = null;

export default {
  components: {
    AppLang,
    AppLogo,
    BServicio
  },
  data () {
    return {
      menu: [],
      stick: false,
175
176
177
      maxStick: 180,
      pestaña_participa: false,
      forums: []
Esteban Choque's avatar
Esteban Choque committed
178
179
180
181
182
183
184
185
186
187
188
189
190
    };
  },
  asyncData() {
    return {};
  },
  created () {
    if (process.browser) {
      window.addEventListener('scroll', this.handleScroll);
    }
    this.getMenu();
  },
  mounted () {
    nuxtContainer = document.getElementById('__nuxt');
191
    this.getListadoForos();
Esteban Choque's avatar
Esteban Choque committed
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
  },
  destroyed () {
    if (process.browser) {
      window.removeEventListener('scroll', this.handleScroll);
    }
  },
  methods: {
    handleScroll () {
      this.stick = window.scrollY > this.maxStick;
      nuxtContainer.className = window.scrollY > this.maxStick ? 'container-stick' : '';
    },
    openSearch () {
      this.$store.commit('OPEN_SEARCH');
    },
    login () {
      this.$store.commit('OPEN_LOGIN');
    },
    logout () {
      this.$service.post('/api/logout')
      .then(response => {
        if (response) {
          Cookie.remove('auth');
          this.$store.commit('SET_USER', null);
          this.$store.commit('SET_AUTH', null);
          window.location = '';
        }
      });
    },
    getMenu () {
      this.$service.get('/api/menu')
      .then(response => {
        if (response) {
          this.menu = response.menu;
          this.$store.commit('SET_PAGES', response.pages);
          this.$store.commit('SET_CATEGORIES', response.categories);
          this.$nextTick(() => {
            this.$store.commit('SET_ACTION', 'loadPage');
          });
        }
      });
232
233
234
235
236
237
238
    },
    getListadoForos() {
     axios.get(this.$foro.url+'/fm/v1/')
      .then(response => {
        this.forums = response.data;
        console.log(response.data);
     });
Esteban Choque's avatar
Esteban Choque committed
239
240
241
242
243
244
    }
  }
};
</script>

<style lang="scss" src="./app-header.scss"></style>