<template>
  <div class="header">
    <div class="con">
      <a href="https://www.4dkankan.com/" class="logo">
        <img :src="require('@/assets/images/icons/img_logo_20220119.svg')" alt="" />
      </a>
      <ul class="tab">
        <li @click="handleItem(item)" :class="{active:active.id==item.id}" v-for="(item, i) in tab" :key="i">
          {{ item.name }}
        </li>
      </ul>
      <user-info class="user-info"></user-info>
    </div>
  </div>
</template>

<script>
import UserInfo from "@/components/userInfo.vue";
export default {
  components: {
    UserInfo,
  },
  data() {
    return {
      active:{},
      tab: [
        {
          name: "我的作品",
          id: "works",
          path:{
            path:'/works'
          }
        },
        {
          name: "我的素材",
          id: "material",
          path:{
            path:'/'
          }
        }
      ],
    };
  },
  watch:{
    '$route.meta':{
      deep:true,
      handler:function (newVal) {
        this.active  = this.tab.find(item=>{
          return item.id == newVal.belong 
        })
      }
    }
  },
  methods:{
    handleItem(item){
      this.$router.push(item.path)
    }
  }
};
</script>

<style lang="less" scoped>
.header {
  width: 100%;
  background: #fff;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 999;
  .con {
    color: #000;
    max-width: 1280px;
    height: 70px;
    display: flex;
    align-items: center;
    margin: 0 auto;
    position: relative;
    padding: 0;
    .logo {
      font-size: 24px;
      font-weight: bold;
      width: 188px;
      >img{
        width: 100%;
        vertical-align: middle;
      }
    }
    .tab {
      display: flex;
      align-items: center;
      margin-left: 116px;
      > li {
        cursor: pointer;
        margin-right: 50px;
        text-align: left;
        font-size: 16px;
        color: #909090;
        &.active{
          font-size: 16px;
          font-weight: bold;
          color: #0076F6;
          position: relative;
          &::before{
            content: '';
            width: 20px;
            height: 2px;
            background: #0076F6;
            display: inline-block;
            position: absolute;
            left: 50%;
            transform: translateX(-50%);
            bottom: -10px;
          }
        }
      }
    }
    .user-info {
      margin-left: auto;
      margin-right: 0;
    }
  }
}
</style>
