<template>
  <section class="app-main">
    <transition name="fade-transform" mode="out-in">
      <keep-alive :max="maxCacheCount">
        <router-view :key="key"/>
      </keep-alive>
    </transition>
  </section>
</template>

<script>
export default {
  name: 'AppMain',
  data() {
    return {
      maxCacheCount: 5 // 最多缓存尺寸 // 5.11 hht 加个尺寸控制，防止key值缓存过多
    }
  },
  computed: {
    cachedViews() {
      return this.$store.state.tagsView.cachedViews
    },
    key() {
      // TODO: 5.11 hht keep-alive的include/exclude结合router-view好像不能正常工作, 目前没有弄清原因
      // NOTE: 先通过key的途径解决缓存刷新的问题
      const meta = this.$route.meta
      const useCache = meta && meta.hasOwnProperty('noCache') && meta.noCache === false
      const fullPath = this.$route.fullPath
      const cacheControlArgs = useCache ? '' : ('_' + new Date().getTime())
      return fullPath + cacheControlArgs
    }
  }
}
</script>

<style lang="scss" scoped>
.app-main {
  /* 50= navbar  50  */
  min-height: calc(100vh - 150px);
  width: 100%;
  position: relative;
  overflow: hidden;
}

.fixed-header + .app-main {
  padding-top: 50px;
}

.hasTagsView {
  .app-main {
    /* 84 = navbar + tags-view = 50 + 34 */
    min-height: calc(100vh - 124px);
  }

  .fixed-header + .app-main {
    padding-top: 84px;
  }
}
</style>

<style lang="scss">
// fix css style bug in open el-dialog
.el-popup-parent--hidden {
  .fixed-header {
    padding-right: 15px;
  }
}
</style>
