<!-- 新闻管理 by wangshxc -->
<template>
  <div class="frame">
    <div class="frameTitle">
      <el-menu
        :default-active="defaultIndex()"
        class="el-menu-demo"
        mode="horizontal"
        @select="handleSelect"
      >
        <el-menu-item v-for="(item,id) in elMenu" :key="id"  :index="item.key">{{ item.value }}</el-menu-item>
      </el-menu>
    </div>
    <div>
      <router-view />
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      elMenu: [
        {
          value: '帮助题库',
          key: '1',
        },
      ]
    }
  },
  watch: {
    '$route'(to, from) {
      this.defaultIndex()
      this.handleSelect(this.defaultIndex());
    }
  },
  created() {
    this.handleSelect(this.defaultIndex());
  },
  methods: {
    defaultIndex() {
      const allMenu = this.elMenu.filter(i => i.key);
      if (allMenu.length > 0) {
        if (localStorage.getItem('ws-pf_help')) {
          // debugger
          for (let i = 0; i < allMenu.length; i++) {
            if (allMenu[i].key === localStorage.getItem('ws-pf_help')) {
              return localStorage.getItem('ws-pf_help')
            }
          }
          return allMenu[0].key
        } else {
          for (let i = 0; i < allMenu.length; i++) {
            if (allMenu[i].key) {
              return allMenu[i].key
            }
          }
        }
      }
      return '';
    },
    // 点击标签跳转
    handleSelect(key) {
      if (key === '1') {
        this.$router.push({ name: "helpList" })
        localStorage.setItem('ws-pf_help', key)
      }
    },
  }
}
</script>

<style lang="scss" scoped>
  .frameTitle {
    background-color: #fff;
  }

  .el-menu--horizontal > .el-menu-item {
    height: 50px;
    line-height: 50px;
  }

  .frameCenter {
    background-color: #fff;
    margin: 10px 10px 10px 10px;
    padding: 0px 15px 15px 15px;
    height: calc(100vh - 100px);
    overflow-y: auto;
  }
</style>
