Toolbar.vue 5.1 KB
Newer Older
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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 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 160 161 162 163 164 165 166 167 168
<!--
  - Licensed to the Apache Software Foundation (ASF) under one or more
  - contributor license agreements.  See the NOTICE file distributed with
  - this work for additional information regarding copyright ownership.
  - The ASF licenses this file to You 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>
  <v-toolbar
    color="primary"
    fixed
    dark
    app
  >
    <v-toolbar-side-icon @click.stop="handleDrawerToggle"></v-toolbar-side-icon>
    <v-text-field
      flat
      hide-details
      solo-inverted
      prepend-inner-icon="search"
      :label="$t('serviceSearch')"
      class="hidden-sm-and-down"
      v-model="global"
      @keyup.enter="submit"
    >
    </v-text-field>

    <v-spacer></v-spacer>

    <!--settings button-->
    <v-btn icon v-if="false">
      <v-icon>settings</v-icon>
    </v-btn>

    <!--full screen button-->
    <v-btn icon @click="handleFullScreen()">
      <v-icon>fullscreen</v-icon>
    </v-btn>

    <!--language select button-->
    <v-menu  attach bottom left offset-y max-height="500">
      <v-btn flat slot="activator" style="mini-width: 48px">
        {{selectedLang}}
      </v-btn>
      <v-list class="pa-0">
        <v-list-tile v-for="(item, index) in lang" @click="change(index)" :key="index">
          <v-list-tile-content>
            <v-list-tile-title>{{item}}</v-list-tile-title>
          </v-list-tile-content>
        </v-list-tile>
      </v-list>
    </v-menu>

    <!--notifictation button-->
    <v-menu offset-y origin="center center" class="elelvation-1" :nudge-bottom="14" transition="scale-transition" v-if="false">
      <v-btn icon flat slot="activator">
        <v-badge color="red" overlap>
          <span slot="badge">3</span>
          <v-icon medium>notifications</v-icon>
        </v-badge>
      </v-btn>
      <!--<notification-list></notification-list>-->
    </v-menu>

    <!--login user info-->
    <v-menu offset-y origin="center center" :nudge-bottom="10" transition="scale-transition">
      <v-btn icon large flat slot="activator">
        <v-avatar size="30px">
          <img src="@/assets/avatar.png" alt="Logined User" />
        </v-avatar>
      </v-btn>
      <v-list class="pa-0">
        <v-list-tile v-for="(item,index) in items" :to="!item.href ? { name: item.name } : null" :href="item.href" @click="item.click" ripple="ripple" :disabled="item.disabled" :target="item.target" rel="noopener" :key="index">
          <v-list-tile-action v-if="item.icon">
            <v-icon>{{ item.icon }}</v-icon>
          </v-list-tile-action>
          <v-list-tile-content>
            <v-list-tile-title>{{ item.title }}</v-list-tile-title>
          </v-list-tile-content>
        </v-list-tile>
      </v-list>
    </v-menu>
  </v-toolbar>
</template>
<script>
  import Util from '@/util'
  export default {
    name: 'toolbar',
    data: () => ({
      selectedLang: '',
      global: '',
      lang: [
        '简体中文',
        'English'
      ],
      items: [
        {
          icon: 'account_circle',
          href: '#',
          title: 'Profile',
          click: (e) => {
            console.log(e)
          }
        },
        {
          icon: 'fullscreen_exit',
          href: '#',
          title: 'Logout',
          click: (e) => {
            window.getApp.$emit('APP_LOGOUT')
          }
        }
      ]
    }),
    methods: {
      submit () {
        if (window.location.href.includes('#/service')) {
          window.location.href = '#/service?filter=' + this.global + '&pattern=service'
          window.location.reload()
        } else {
          window.location.href = '#/service?filter=' + this.global + '&pattern=service'
        }
        this.global = ''
      },
      handleDrawerToggle () {
        window.getApp.$emit('DRAWER_TOGGLED')
      },
      change (index) {
        this.selectedLang = this.lang[index]
        if (index === 0) {
          this.$i18n.locale = 'zh'
        } else {
          this.$i18n.locale = 'en'
        }
        this.$store.dispatch('changeArea', {area: this.$i18n.locale})
        window.localStorage.setItem('locale', this.$i18n.locale)
        window.localStorage.setItem('selectedLang', this.selectedLang)
      },
      handleTheme () {
        window.getApp.$emit('CHANGE_THEME')
      },
      handleFullScreen () {
        Util.toggleFullScreen()
      }
    },
    mounted: function () {
      if (this.$i18n.locale === 'zh') {
        this.selectedLang = '简体中文'
      } else {
        this.selectedLang = 'English'
      }
      let username = localStorage.getItem('username')
      if (username) {
        this.items[0].title = this.$t('userName') + ':' + username
      }
    }
  }
</script>