index.vue 2.52 KB
<template>
  <div class="layout-header">
    <el-header class="platform-head fixed-header">
      <div class="header-middle">
        <!-- menu -->
        <el-menu
          :default-active="activeIndex"
          class="header-menu-wrapper"
          background-color="#1d66f3"
          text-color="#fff"
          mode="horizontal"
          @select="handleSelect"
        >
          <menus-item v-for="route in routes" :key="route.key" :item="route" />
        </el-menu>
      </div>
      <div class="header-left">logo</div>
      <div class="header-right">right</div>
    </el-header>
  </div>
</template>

<script>
import MenusItem from '../MenuItem'

export default {
  name: 'GlobalHeader',
  components: { MenusItem },
  data() {
    return {
      activeIndex: '',
      routes: [
        {
          key: 'home',
          path: '/',
          name: '首页'
        },
        {
          key: 'analysis',
          path: 'analysis',
          name: '客流统计'
        },
        {
          key: 'behavior',
          path: 'behavior',
          name: '人脸分析'
        },
        {
          key: 'dataasis',
          path: 'dataasis',
          name: '数据分析'
        },
        {
          key: 'manage',
          path: 'manage',
          name: '后台管理'
        }
      ]
    }
  },
  computed: {
    activeMenu() {
      const route = this.$route
      const currRoute = this.routes.find(
        item => route.path.indexOf(item.key) > -1
      )
      return (currRoute && '/' + currRoute.path) || '/'
    }
  },
  mounted() {
    // console.log('activeMenu', this.activeMenu)
  },
  methods: {
    handleSelect(key) {
      this.$router.push(key)
    }
  }
}
</script>

<style lang="scss" scoped>
.layout-header {
  box-sizing: border-box;
  flex: 0 0 auto;
}
.platform-head {
  width: 100%;
  background-color: #1d66f3;
  color: #fff;
  height: 60px;
  line-height: 60px;
  padding: 0 500px 0 364px;
  overflow: hidden;
  &.fixed-header {
    position: fixed;
    top: 0;
    right: 0;
    z-index: 9;
  }
}
.header-middle {
  position: relative;
  float: left;
  width: 100%;
  height: 60px;
}
.header-menu-wrapper {
  font-size: 16px;
  color: #fff;
}
.header-left {
  position: relative;
  float: left;
  width: 364px;
  height: inherit;
  left: -364px;
  padding-left: 165px;
  margin-left: -100%;
  background: #1d66f3;
  text-align: center;
}
.header-right {
  position: relative;
  float: left;
  width: 500px;
  height: inherit;
  right: -500px;
  margin-left: -500px;
  background: #1d66f3;
  text-align: center;
}
</style>