<template>
  <div class="header-content">
    <div class="logo-box">
      <img
        class="logo"
        :src="sysLogo ? sysLogo : require('@/assets/img/logo.png')"
        alt="LOGO"
        @click="handleGoHome"
      />
      <h1 class="title" @click="handleGoHome">
        {{ sysName ? sysName : systemName }}
      </h1>
      <HeaderSite></HeaderSite>
    </div>
    <!-- 导航 -->
    <MenuBar v-if="layout === 'head'" mode="horizontal"></MenuBar>
    <!-- 返回门户 -->
    <div class="back-btn">
      <el-tooltip effect="dark" content="返回门户" placement="bottom">
        <a class="pointer" :href="portal + (path ? path : '/')">
          <i class="el-icon-s-home"></i> 返回门户
        </a>
      </el-tooltip>
    </div>
  </div>
</template>

<script>
import HeaderSite from "./HeaderSite.vue";
import MenuBar from "./MenuBar.vue";

import { systemName } from "@/config";
import { mapState, mapMutations } from "vuex";
export default {
  components: {
    HeaderSite,
    MenuBar,
  },
  data() {
    return {
      systemName,
      portal: process.env.VUE_APP_API_portal_URL + "/#",
    };
  },
  computed: {
    activeMenu() {
      const route = this.$route;
      const { meta, matched } = route;
      if (meta.activeMenu) {
        return meta.activeMenu;
      } else {
        let curMatched = matched.filter((v) => v.path);
        return curMatched[0].path;
      }
    },
    ...mapState(["menus", "sysName", "sysLogo", "path", "layout"]),
  },
  created() {},
  methods: {
    ...mapMutations(["SET_secondaryRoutes"]),
    selectMenu(index) {
      this.SET_secondaryRoutes(index);
    },
    handleGoHome() {
      let path = this.menus[0].path;
      if (path) {
        this.$router.push(path);
      }
    },
  },
};
</script>

<style lang="less" scoped>
.header-content {
  height: 100%;
  width: 100%;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  .logo-box {
    display: flex;
    align-items: center;
  }
  .logo {
    height: 32px;
    object-fit: contain;
    margin-right: 8px;
  }

  .title {
    margin-right: 34px;
    font-weight: bold;
    font-size: 18px;
    line-height: normal;
    color: #fff;
    cursor: pointer;
  }
  .back-btn {
    a {
      color: #fff;
      font-size: 14px;
    }
  }
}
</style>
