Navbar.vue 4.7 KB
Newer Older
花裤衩's avatar
花裤衩 committed
1 2
<template>
  <div class="navbar">
yanzhongrong's avatar
yanzhongrong committed
3
    <!-- <hamburger :is-active="sidebar.opened" class="hamburger-container" @toggleClick="toggleSideBar" /> -->
花裤衩's avatar
花裤衩 committed
4

yanzhongrong's avatar
yanzhongrong committed
5 6
    <!-- <breadcrumb class="breadcrumb-container" /> -->
    <Sidebar />
花裤衩's avatar
花裤衩 committed
7 8
    <div class="right-menu">
      <el-dropdown class="avatar-container" trigger="click">
yanzhongrong's avatar
yanzhongrong committed
9 10 11
        <span class="el-dropdown-link">
          admin<i class="el-icon-arrow-down el-icon--right"></i>
        </span>
yanzhongrong's avatar
yanzhongrong committed
12
        <el-dropdown-menu slot="dropdown">
13
          <el-dropdown-item divided @click.native="logout">
neogcg's avatar
neogcg committed
14
            <span style="display:block;">退出登录</span>
花裤衩's avatar
花裤衩 committed
15
          </el-dropdown-item>
neogcg's avatar
neogcg committed
16
         
花裤衩's avatar
花裤衩 committed
17 18
        </el-dropdown-menu>
      </el-dropdown>
yanzhongrong's avatar
yanzhongrong committed
19
      <span style="color: white; padding-right: 10px"> {{ dateTime }}</span>
花裤衩's avatar
花裤衩 committed
20 21 22 23 24 25 26 27
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import Breadcrumb from '@/components/Breadcrumb'
import Hamburger from '@/components/Hamburger'
yanzhongrong's avatar
yanzhongrong committed
28
import Sidebar from './Sidebar/index.vue'
yanzhongrong's avatar
yanzhongrong committed
29 30
import { logout } from '@/api/user'

花裤衩's avatar
花裤衩 committed
31
export default {
yanzhongrong's avatar
yanzhongrong committed
32 33 34 35 36 37
  data() {
    let timer
    return {
      dateTime: '',
    }
  },
花裤衩's avatar
花裤衩 committed
38 39
  components: {
    Breadcrumb,
yanzhongrong's avatar
yanzhongrong committed
40 41
    Hamburger,
    Sidebar
花裤衩's avatar
花裤衩 committed
42 43 44 45 46 47 48
  },
  computed: {
    ...mapGetters([
      'sidebar',
      'avatar'
    ])
  },
yanzhongrong's avatar
yanzhongrong committed
49 50 51
  mounted() {
    this.nowTimes()
  },
花裤衩's avatar
花裤衩 committed
52 53 54 55
  methods: {
    toggleSideBar() {
      this.$store.dispatch('app/toggleSideBar')
    },
yanzhongrong's avatar
yanzhongrong committed
56 57 58 59 60
    logout() {
      logout().then(() => {
        this.$store.dispatch('user/logout')
        this.$router.push(`/login`)
      })
yanzhongrong's avatar
yanzhongrong committed
61 62 63 64 65 66 67 68 69 70
    },
    // 获取当前时间函数
    timeFormate (timeStamp) {
      let year = new Date(timeStamp).getFullYear()
      let month = new Date(timeStamp).getMonth() + 1 < 10 ? '0' + (new Date(timeStamp).getMonth() + 1) : new Date(timeStamp).getMonth() + 1
      let date = new Date(timeStamp).getDate() < 10 ? '0' + new Date(timeStamp).getDate() : new Date(timeStamp).getDate()
      let hh = new Date(timeStamp).getHours() < 10 ? '0' + new Date(timeStamp).getHours() : new Date(timeStamp).getHours()
      let mm = new Date(timeStamp).getMinutes() < 10 ? '0' + new Date(timeStamp).getMinutes() : new Date(timeStamp).getMinutes()
      let ss = new Date(timeStamp).getSeconds() < 10? "0" + new Date(timeStamp).getSeconds(): new Date(timeStamp).getSeconds();
      // return year + "年" + month + "月" + date +"日"+" "+hh+":"+mm ;
yanzhongrong's avatar
yanzhongrong committed
71
      this.dateTime = year + '/' + month + '/' + date + ' ' + hh + ':' + mm + ':' + ss
yanzhongrong's avatar
yanzhongrong committed
72 73 74 75 76 77 78 79 80 81 82 83
    },
    // 定时器函数
    nowTimes() {
      this.timeFormate(new Date())
      clearInterval(this.timer)
      this.timer = setInterval(this.nowTimes, 1000)
    },
     // 清除定时器,不然会导致页面崩溃
    beforeDestroy () {
      if (this.timer) {
        clearInterval(this.timer)
      }
花裤衩's avatar
花裤衩 committed
84 85 86 87 88 89 90 91 92 93 94
    }
  }
}
</script>

<style lang="scss" scoped>
.navbar {
  overflow: hidden;
  position: relative;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0,21,41,.08);
yanzhongrong's avatar
yanzhongrong committed
95
  .log {
yanzhongrong's avatar
yanzhongrong committed
96
    font-size: 24px;
yanzhongrong's avatar
yanzhongrong committed
97 98 99
    color: #fff;
    float: left;
  }
花裤衩's avatar
花裤衩 committed
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
  .hamburger-container {
    line-height: 46px;
    height: 100%;
    float: left;
    cursor: pointer;
    transition: background .3s;
    -webkit-tap-highlight-color:transparent;

    &:hover {
      background: rgba(0, 0, 0, .025)
    }
  }

  .breadcrumb-container {
    float: left;
  }

  .right-menu {
neogcg's avatar
neogcg committed
118
    // float: right;
花裤衩's avatar
花裤衩 committed
119 120
    height: 100%;
    line-height: 50px;
yanzhongrong's avatar
yanzhongrong committed
121 122
    position: absolute;
    top: 5px;
neogcg's avatar
neogcg committed
123
    right: 30px;
花裤衩's avatar
花裤衩 committed
124 125 126 127 128 129 130 131 132 133

    &:focus {
      outline: none;
    }

    .right-menu-item {
      display: inline-block;
      padding: 0 8px;
      height: 100%;
      font-size: 18px;
yanzhongrong's avatar
yanzhongrong committed
134
      color: #fff;
花裤衩's avatar
花裤衩 committed
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 169 170
      vertical-align: text-bottom;

      &.hover-effect {
        cursor: pointer;
        transition: background .3s;

        &:hover {
          background: rgba(0, 0, 0, .025)
        }
      }
    }

    .avatar-container {
      margin-right: 30px;

      .avatar-wrapper {
        position: relative;

        .user-avatar {
          cursor: pointer;
          width: 40px;
          height: 40px;
          border-radius: 10px;
        }

        .el-icon-caret-bottom {
          cursor: pointer;
          position: absolute;
          right: -20px;
          top: 25px;
          font-size: 12px;
        }
      }
    }
  }
}
neogcg's avatar
neogcg committed
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
.el-dropdown-menu__item{
  color:#B2DDFF;
}
.el-popper[x-placement^=bottom] {
    margin-top: 5px;
}
.el-dropdown-menu__item--divided{
  border:none;
  margin-top: 0;
}
.el-dropdown-menu__item--divided:before{
  content: '';
    height: 6px;
    display: none;
    margin: 0;
    background-color: transparent;
}
</style>
<style>
  .el-popper .popper__arrow{
    display: none !important;
  }
  .el-dropdown-menu{
    padding:5px 0;
    background: #2066f9;
neogcg's avatar
neogcg committed
196
    border:none;
neogcg's avatar
neogcg committed
197 198 199 200 201
  }
  .el-dropdown-menu__item:not(.is-disabled):hover{
    background-color: #1a52c7;
    color: #fff;
  }
花裤衩's avatar
花裤衩 committed
202
</style>