front-end/src/views/layout/components/Navbar.vue (175 lines of code) (raw):

<!-- Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <template> <div class="navbar"> <hamburger :toggle-click="toggleSideBar" :is-active="sidebar.opened" class="hamburger-container"/> <breadcrumb class="breadcrumb-container"/> <div class="right-menu"> <el-dropdown @command="handleCommand"> <span class="el-dropdown-link"> {{ currentEnv }}<i class="el-icon-arrow-down el-icon--right"/> </span> <el-dropdown-menu slot="dropdown"> <el-dropdown-item v-for="(item,index) in environmentsListOptions" :command="item" :key="index" :label="item.label" :value="item.value"> {{ item.value }} </el-dropdown-item> <el-dropdown-item command="newEnvironment" divided>{{ $t('env.manageEnvs') }}</el-dropdown-item> </el-dropdown-menu> </el-dropdown> <template v-if="device!=='mobile'"> <error-log class="errLog-container right-menu-item"/> <el-tooltip :content="$t('navbar.size')" effect="dark" placement="bottom"> <size-select class="international right-menu-item"/> </el-tooltip> <lang-select class="international right-menu-item"/> </template> <el-dropdown class="avatar-container right-menu-item" trigger="click"> <span class="avatar-wrapper"> Admin<i class="el-icon-arrow-down el-icon--right"/> </span> <el-dropdown-menu slot="dropdown"> <a target="_blank" href="https://github.com/apache/pulsar"> <el-dropdown-item> {{ $t('navbar.github') }} </el-dropdown-item> </a> <el-dropdown-item divided> <span style="display:block;" @click="logout">{{ $t('navbar.logOut') }}</span> </el-dropdown-item> </el-dropdown-menu> </el-dropdown> </div> </div> </template> <script> import { mapGetters } from 'vuex' import Breadcrumb from '@/components/Breadcrumb' import Hamburger from '@/components/Hamburger' import ErrorLog from '@/components/ErrorLog' import SizeSelect from '@/components/SizeSelect' import LangSelect from '@/components/LangSelect' import { fetchEnvironments } from '@/api/environments' import { setEnvironment, getEnvironment } from '@/utils/environment' export default { components: { Breadcrumb, Hamburger, ErrorLog, SizeSelect, LangSelect }, data() { return { currentEnv: 'Environments', environmentsListOptions: [{ 'label': 'localhost:8080', 'value': 'localhost:8080' }] } }, computed: { ...mapGetters([ 'sidebar', 'name', 'avatar', 'device' ]) }, created() { this.getEnvironmentsList() this.currentEnv = getEnvironment() }, methods: { toggleSideBar() { this.$store.dispatch('toggleSideBar') }, logout() { this.$store.dispatch('LogOut').then(() => { location.reload()// In order to re-instantiate the vue-router object to avoid bugs }) }, handleCommand(command) { if (command === 'newEnvironment') { this.$router.push({ path: '/environments' }) return } setEnvironment(command.value) window.location.reload() }, getEnvironmentsList() { fetchEnvironments().then(response => { if (!response.data) return this.environmentsListOptions = [] for (var i = 0; i < response.data.data.length; i++) { this.environmentsListOptions.push({ 'value': response.data.data[i].name, 'label': response.data.data[i].broker, 'status': response.data.data[i].status }) } }) } } } </script> <style rel="stylesheet/scss" lang="scss" scoped> .el-icon-arrow-down { font-size: 12px; } .navbar { height: 50px; line-height: 50px; border-radius: 0px !important; .hamburger-container { line-height: 58px; height: 50px; float: left; padding: 0 10px; } .breadcrumb-container{ float: left; } .errLog-container { display: inline-block; vertical-align: top; } .right-menu { float: right; height: 100%; &:focus{ outline: none; } .right-menu-item { display: inline-block; margin: 0 8px; } .screenfull { height: 20px; } .international{ vertical-align: top; } .theme-switch { vertical-align: 15px; } .avatar-container { height: 50px; margin-right: 30px; .avatar-wrapper { cursor: pointer; margin-top: 5px; position: relative; .user-avatar { width: 40px; height: 40px; border-radius: 10px; } .el-icon-caret-bottom { position: absolute; right: -20px; top: 25px; font-size: 12px; } } } } } </style>