<template>
  <div class="navbar">
    <div style="display: flex; justify-content: center; color: white; line-height: 47px">
      <div class="cursor index" @click="handlerIndex">
        <span class="icon">&#xe712;</span>
        <div class="mtt">首页</div>
      </div>
      <div class="cursor index">
        <top-nav></top-nav>
      </div>
      <search />
      <hamburger id="hamburger-container" :is-active="sidebar.opened" v-show="isShowHamBurger" class="hamburger-container" @toggleClick="toggleSideBar" />
    </div>
    <breadcrumb id="breadcrumb-container" class="breadcrumb-container" v-if="!topNav" />
    <div class="right-menu">
      <div class="cursor index right-menu-item">
        <header-notice-vue />
      </div>
      <el-dropdown class="avatar-container right-menu-item hover-effect" trigger="click">
        
        <div class="avatar-wrapper">
          <img :src="avatar" class="user-avatar" />
          <div class="cons">
            <div class="nickName">{{ user.name }}</div>
          </div>
          <i class="el-icon-caret-bottom" />
        </div>
        <el-dropdown-menu slot="dropdown">
          <router-link to="/user/profile">
            <el-dropdown-item>个人中心</el-dropdown-item>
          </router-link>
          <el-dropdown-item @click.native="setting = true">
            <span>布局设置</span>
          </el-dropdown-item>
          <el-dropdown-item divided @click.native="logout">
            <span>退出登录</span>
          </el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex';
import Breadcrumb from '@/components/Breadcrumb';
import TopNav from '@/components/TopNav';
import Hamburger from '@/components/Hamburger';
import Screenfull from '@/components/Screenfull';
import SizeSelect from '@/components/SizeSelect';
import Search from '@/components/HeaderSearch';
import RuoYiGit from '@/components/RuoYi/Git';
import RuoYiDoc from '@/components/RuoYi/Doc';
import HeaderNoticeVue from './HeaderNotice.vue';

export default {
  data() {
    return {
      // 菜单列表显示、隐藏
      isShowMenu: false,
      user: this.$store.state.user,
      // 伸缩按钮显示、隐藏
      isShowHamBurger: false,
      routeImgs: [
        require('@/assets/route_images/u211.svg'),
        require('@/assets/route_images/u217.svg'),
        require('@/assets/route_images/u226.svg'),
        require('@/assets/route_images/u214.svg'),
        require('@/assets/route_images/u223.svg'),
        require('@/assets/route_images/u229.svg'),
        require('@/assets/route_images/u220.svg'),
        require('@/assets/route_images/u232.svg')
      ]
    };
  },
  components: {
    HeaderNoticeVue,
    Breadcrumb,
    TopNav,
    Hamburger,
    Screenfull,
    SizeSelect,
    Search,
    RuoYiGit,
    RuoYiDoc
  },
  computed: {
    ...mapGetters(['sidebar', 'avatar', 'device', 'sidebarRouters']),
    setting: {
      get() {
        return this.$store.state.settings.showSettings;
      },
      set(val) {
        this.$store.dispatch('settings/changeSetting', {
          key: 'showSettings',
          value: val
        });
      }
    },
    topNav: {
      get() {
        return this.$store.state.settings.topNav;
      }
    }
  },
  methods: {
    toggleSideBar() {
      this.$store.dispatch('app/toggleSideBar');
    },
    async logout() {
      this.$confirm('确定注销并退出系统吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.$store.dispatch('LogOut').then(() => {
            location.href = '/ruoyi-vue-web/index';
          });
        })
        .catch(() => {});
    },
    handlerShowMenu() {
      this.isShowMenu = !this.isShowMenu;
    },

    handlerIndex() {
      this.isShowHamBurger = false;
      this.$router.push('/');
    }
  },

  watch: {
    '$route.fullPath': {
      handler: function (newV, oldV) {
        if (newV == '/index') {
          this.isShowHamBurger = false;
        } else {
          this.isShowHamBurger = true;
        }
      }
      // deep:true,
    }
  }
};
</script>

<style lang="scss" scoped>
.navbar {
  height: 60px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #2561ef;

  .index {
    width: 100px;
    text-align: center;
    .mtt {
      margin-top: -25px;
      font-size: 14px;
    }
  }

  .cursor {
    cursor: pointer;
  }

  .menu-hover {
    padding: 10px;

    &:hover {
      background-color: rgb(221, 235, 248);
    }
  }

  .hamburger-container {
    line-height: 46px;
    height: 100%;
    float: left;
    cursor: pointer;
    transition: background 0.3s;
    -webkit-tap-highlight-color: transparent;

    &:hover {
      background: rgba(0, 0, 0, 0.025);
    }
  }
  .breadcrumb-container {
    float: left;
  }
  .topmenu-container {
    position: absolute;
    left: 50px;
  }
  .errLog-container {
    display: inline-block;
    vertical-align: top;
  }
  .right-menu {
    float: right;
    height: 100%;
    line-height: 50px;
    &:focus {
      outline: none;
    }
    .right-menu-item {
      display: inline-block;
      padding: 0 8px;
      height: 100%;
      font-size: 18px;
      color: #5a5e66;
      vertical-align: text-bottom;
      &.hover-effect {
        cursor: pointer;
        transition: background 0.3s;

        &:hover {
          background: rgba(0, 0, 0, 0.025);
        }
      }
    }
    .avatar-container {
      margin-right: 30px;
      .avatar-wrapper {
        margin-top: 5px;
        position: relative;
        .user-avatar {
          cursor: pointer;
          width: 40px;
          height: 40px;
          border-radius: 10px;
        }
        .cons {
          float: right;
          font-size: 13px;
          margin-top: -4px;
          margin-left: 10px;
          max-width: 100px;
          color: white;
          .nickName {
            height: 10px;
          }
          .desc {
            margin-top: 7px;
          }
        }
        .el-icon-caret-bottom {
          cursor: pointer;
          position: absolute;
          right: -20px;
          top: 16px;
          font-size: 12px;
          color: white;
        }
      }
    }
  }
}
</style>
